Difference between single quotes and double quotes when passing command through ssh
Solution 1:
Probably no difference for that example but there certainly would be for this one:
ssh [email protected] "echo $PATH"
The reason is that bash will evaluate and substitute variables inside double-quotes on the local machine but will do it on the target machine inside single quotes.
The same is true for subshells:
ssh [email protected] "echo `hostname`"
ssh [email protected] "echo $(hostname)"
However, it appears to not be true for functions:
$ foo () { echo "Foo"; }
$ foo
Foo
$ ssh [email protected] "foo"
bash: foo: command not found
Globbing also does not happen within double quotes:
$ ssh [email protected] "ls -l *"
$ ssh [email protected] "ls -l numbered_files.?.gz"