I found a strange error when I try to get SSH Remote command exit code. I don't understand why it will get different result and how to explain it. Can someone point out what I'm doing wrong or a better way to capture the exit status of the remote ssh command. Appreciate any help.
local command:
ssh_test/test.sh; echo $?;
+ exit 1
1
ssh command:(Ubuntu 18.04)
ssh 127.0.0.1 "ssh_test/test.sh; echo $?"
+ exit 1
0
test.sh
#!/bin/bash
set -x
exit 1
I should use single quotation marks to double quotation marks. echo $? will become "0", if I use double quotation marks to execution ssh command.
ssh 127.0.0.1 'ssh_test/test.sh; echo $?'