Why bash does what I expect here with a compound command in a subshell:
$ bash -x -c 'set -e; (false && true; echo hi); echo here'
+ set -e
+ false
+ echo hi
hi
+ echo here
here
But DO NOT do what I expect here:
$ bash -x -c 'set -e; (eval "false && true"; echo hi); echo here'
+ set -e
+ eval 'false && true'
++ false
Basically, the difference between βeval'-uating a compound command and just executing a compound command. When a shell executes a compound command, non-terminal commands in a compound command that fail do not cause the entire connection command to fail, they just end the command. But when eval launches a compound command, and any nonterminal subcommand completes the command with an error, eval terminates the command with an error.
I think I need to format my eval statement as follows:
eval "false && true" || :
so that the eval command does not exit my subshell with an error, because it works the way I would expect this:
$ bash -x -c 'set -e; (eval "false && true" || :; echo hi); echo here'
+ set -e
+ false
+ echo hi
hi
+ echo here
here
, :
function execute() {
local command="$1"
local remote="$2"
if [ ! -z "$remote" ]; then
$SSH $remote "$command" || :
else
eval "$command" || :
fi
}
set -e script. ssh - ssh script , , . , , , , . , ssh eval 1, . || : eval ssh, , , eval'd ssh'd .
.