In Bash, I can use the following code:
[ "$sshcmd" = "" ] && sshcmd="ssh -someopts myhost"
$sshcmd "echo hello world"
In ZSH, the same code does not work because it tries to find a “ssh -someopts myhost” executable. How can I do the same thing in ZSH?
Thanks, Albert
To split a string at whitespace (more generally, at
$IFS) like other shells:$=sshcmdBut you should instead make
sshcmdan array, so that your commands still works if one of the options contains whitespace:This applies to bash and ksh too, by the way; but there you must also protect the array variable substitution against further splitting and filename expansion: