for example
ssh root@me -- cat /etc/hostname -- cat /etc/hostname
I expect it output:
me
me
but it output
me
me
cat: cat: No such file or directory
I know the double-dash means ending parsing option, why it raise cat: cat: No such file or directory
-- signals the end of option parsing. Nothing after -- will be treated as an option, even if it begins with a dash. As an example, ls -l will print a file listing in long format while ls -- -l looks for a file named -l.
ssh root@me -- cat /etc/hostname -- cat /etc/hostname
This sshes to a remote server and runs the command:
cat /etc/hostname -- cat /etc/hostname
That is a single cat command. Skipping over the --, it's equivalent to writing:
cat /etc/hostname cat /etc/hostname
It prints /etc/hostname, which is me. It then tries to print the file cat, which doesn't exist, giving the error cat: cat: No such file or directory. The program cat is complaining that the file cat doesn't exist. Then it prints /etc/hostname again.
If you want to execute multiple commands with ssh, do this:
ssh root@me 'cat /etc/hostname; cat /etc/hostname'
or this:
ssh root@me <<CMDS
cat /etc/hostname
cat /etc/hostname
CMDS
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With