Why is the first sub-command of my remote command not executing or not affecting later sub-commands?
1
vote
0
answers
26
views
This command is a simplification of the problem I've come across:
ssh grinder1h.devqa sh -c "cd /etc/ssh && pwd"
This command gives an output of ***"/home/fetch"***, which is the remote user's home directory. I would expect the output to be ***"/etc/ssh"***, as the "cd" should run in the same shell as "pwd", and so should affect its output.
In fooling around, I tried this command:
ssh grinder1h.devqa sh -c "pwd && cd /etc/ssh && pwd"
This command produces ***"/home/fetch"*** followed by ***"/etc/ssh"***, which is the expected output. So for this command, the first sub-command produces a result, and somehow affects the remaining sub-commands.
It turns out that I can add any subcommand to the front of this command to cause the remaining parts of the command to work correctly. So this command produces ***"/etc/ssh"***, the desired result:
ssh grinder1h.devqa sh -c "X=1 && cd /etc/ssh && pwd"
So my question is, why does adding "X=1" to the front of this command affect its output?
I could add any number of examples that act strangely. They all suggest that the first part of my remote command is either not being executed at all, or its effects are ignored. What am I missing?
In case it matters, the client machine is a Mac, the remote host is running Alma Linux 9.5, and doing "sh --version" on the remote host produces this version info:
GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
Asked by CryptoFool
(121 rep)
Dec 1, 2024, 06:17 PM