Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Arithmetic expansion through ssh and zsh -lc throws parse error

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

❯ 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'"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading