shellvariablesshsgiirix

Shell script for loop: variable strangeness


My shell-fu is weak, and these SGI (IRIX 6.5) boxes aren't helping. It works as I would expect on Linux.

The ultimate goal is to run one or more shell scripts on a remote system. There is one shell script in an appropriate location, so this should be simple:

$ ssh remote.host '/bin/sh -c "for s in *.sh; do echo \$s; done"'
s - Undefined variable

...huh, ok. Out of random curiosity, just changing the variable name:

$ ssh remote.host '/bin/sh -c "for i in *.sh; do echo \$i; done"'
12

It's similarly fail-inducing with this:

$ ssh remote.host '/bin/sh/ -c "for s in `ls *.sh`; do echo \$s; done"'\
s - Undefined variable

Can someone teach me the magic spell for IRIX?


Solution

  • The problem is that the login shell on the remote host is csh. One of the strange properties of csh is that a dollar sign within double-quotes is always special (cannot be escaped). Single-quotes do work as expected as long as you do not use newlines within them (csh requires these to be escaped with a backslash).