Question

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?

Était-ce utile?

La 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).

Autres conseils

I kinda' randomly discovered that this particular shell implementation is happier when I swap the single- and double-quotes.

I had much better luck with:

ssh remote.host "/bin/sh -c 'for s in \`ls *.sh\`; do echo \$s; done'"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top