Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Running command-line script via ssh remote

64 views
Skip to first unread message

James

unread,
Mar 28, 2013, 4:14:03 PM3/28/13
to
The remote login shell is csh. How do I get the desired output, which is
1
2
3

$ ssh remote 'bash -c "for f in 1 2 3; do echo $f; done"'
f: Undefined variable.

$ ssh remote 'bash -c "for f in 1 2 3; do echo \$f; done"'
f: Undefined variable.

$ ssh remote 'bash -c "for f in 1 2 3; do echo \\$f; done"'
f: Undefined variable.

$ ssh remote 'bash -c "for f in 1 2 3; do echo \\\$f; done"'
f: Undefined variable.

$ ssh remote "bash -c \"for f in 1 2 3; do echo \$f; done\""
f: Undefined variable.

$ ssh remote "bash -c \"for f in 1 2 3; do echo \\\$f; done\""
f: Undefined variable.


James

Lew Pitcher

unread,
Mar 28, 2013, 4:18:02 PM3/28/13
to
On Thursday 28 March 2013 16:14, in comp.unix.shell, hsle...@yahoo.com
wrote:

> The remote login shell is csh. How do I get the desired output, which is
> 1
> 2
> 3
>
> $ ssh remote 'bash -c "for f in 1 2 3; do echo $f; done"'
> f: Undefined variable.
>
> $ ssh remote 'bash -c "for f in 1 2 3; do echo \$f; done"'
> f: Undefined variable.

It worked for me...

~ $ ssh merlin 'bash -c "for f in 1 2 3 ; do echo \$f ; done "'
Enter passphrase for key '/home/lpitcher/.ssh/id_rsa':
1
2
3
~ $ ssh -V
OpenSSH_5.1p1, OpenSSL 0.9.8y 5 Feb 2013
~ $

[snip]

--
Lew Pitcher
"In Skills, We Trust"

James

unread,
Mar 28, 2013, 4:33:38 PM3/28/13
to lew.p...@digitalfreehold.ca
On Thursday, March 28, 2013 1:18:02 PM UTC-7, Lew Pitcher wrote:
>
> wrote:
>
>
>
> > The remote login shell is csh. How do I get the desired output, which is
>
> > 1
>
> > 2
>
> > 3
>
> >
>
> > $ ssh remote 'bash -c "for f in 1 2 3; do echo $f; done"'
>
> > f: Undefined variable.
>
> >
>
> > $ ssh remote 'bash -c "for f in 1 2 3; do echo \$f; done"'
>
> > f: Undefined variable.
>
>
>
> It worked for me...
>
>
>
> ~ $ ssh merlin 'bash -c "for f in 1 2 3 ; do echo \$f ; done "'
>
> Enter passphrase for key '/home/lpitcher/.ssh/id_rsa':
>
> 1
>
> 2
>
> 3
>
> ~ $ ssh -V
>
> OpenSSH_5.1p1, OpenSSL 0.9.8y 5 Feb 2013
>
> ~ $
>
>
>
> [snip]
>
>
>
> --
>
> Lew Pitcher
>
> "In Skills, We Trust"

I guess merlin's login shell is bash, not /bin/csh.

James

Alan Curry

unread,
Mar 29, 2013, 2:01:53 AM3/29/13
to
In article <4c752329-b208-4a7a...@googlegroups.com>,
James <hsle...@yahoo.com> wrote:
>The remote login shell is csh. How do I get the desired output, which is
>1
>2
>3
>
>$ ssh remote 'bash -c "for f in 1 2 3; do echo $f; done"'
>f: Undefined variable.
>
>$ ssh remote 'bash -c "for f in 1 2 3; do echo \$f; done"'
>f: Undefined variable.

Nothing you do will fix that problem with the $ inside the "". csh won't
allow it. But it will let you end the "", add your $ protected by a
different kind of quoting, and resume with another "", like this:

ssh remote 'sh -c "for i in 1 2 3;do echo "\$"i;done"'

Or, if you switch around your outer quotes...

ssh remote "sh -c 'for i in 1 2 3;do echo \$i;done'"

(The backslash is eaten locally since the local shell is processing "". I'm
presuming the local shell isn't also a csh)

--
Alan Curry
0 new messages