1

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?

GraduateOfAcmeU
  • 342
  • 3
  • 9
  • probably because IRIX /bin/sh is the bourne shell. (I'm only guessing, I'm not sure ;-)). Can you change that to `/bin/bash` or `/bin/ksh`. Good luck. – shellter Nov 09 '12 at 20:38
  • you shouldn't have to escape the `$` because it's already in the single quote. – sampson-chen Nov 09 '12 at 20:44

2 Answers2

1

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

jilles
  • 10,509
  • 2
  • 26
  • 39
0

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'"
GraduateOfAcmeU
  • 342
  • 3
  • 9