I’m attempting the following:
❯ ssh user1@10.8.1.1 zsh --version
zsh 5.8.1 (x86_64-apple-darwin22.0)
❯ ssh user1@10.8.1.1 zsh -lc "for ((index=1; index <= 1; index++)); do echo \$index; done"
zsh:1: parse error near `)'
Yet locally and also without zsh -lc through ssh, it works:
❯ zsh -lc "for ((index=1; index <= 1; index++)); do echo $index; done"
1
❯ ssh user1@10.8.1.1 "for ((index=1; index <= 1; index++)); do echo \$index; done"
1
I can also get it to work when I do anything before the for loop:
❯ ssh user1@10.8.1.1 zsh -lc "echo 1; for ((index=1; index <= 1; index++)); do echo \$index; done"
1
Any recommendations on where I should look?
>Solution :
There’s also word splitting by the destination shell which you want to avoid. So quoting once more should work:
ssh user1@10.8.1.1 zsh -lc "'for ((index=1; index <= 1; index++)); do echo \$index; done'"