[lug] Passing multiword parameters through rsh from ksh

Zan Lynx zlynx at acm.org
Fri Feb 23 12:07:33 MST 2007


On Fri, 2007-02-23 at 11:18 -0700, Elyse M. Grasso wrote:
> When I pass a parameter with blank spaces in it through rsh, it gets split 
> into separate parameters when it reaches the remote program. 
> 
> My ksh and rsh are pretty rusty. Is there a syntax for doing this?
> 
> Does not work:
> script.ksh 'multiword value' value2 
>  
> #!/bin/ksh
> # check for valid params
> rsh $HOST "progname"  "$@"
> 
> also does not work:
> #!/bin/ksh
> # check for valid params
> note=$1
> shift
> rsh $HOST "progname" "'$note'" "$@"
> 
> Google is not being helpful.

Just a reminder that rsh is really insecure.  It's OK if you're running
stuff inside a cluster environment or somewhere you can really trust all
the systems.

But anyway, both rsh and ssh invoke a shell on the _remote_ computer.
*That* shell receives the string that you sent, which was processed by
the local shell first.

That means, that you need *double* shell escaping and quoting, one for
the local shell, one for the remote shell.

So maybe:
rsh $HOST "'progname' '$note' '$@'"

Note the nesting of single quotes and double quotes.  That is untested
but might work.

A way to test your quoting is to write a script on the remote system
that writes out command arguments as it sees them, perhaps one per line
using a while shift loop or for i in "$@" or something similar.  Then
you can rsh to that script to see what you get.
-- 
Zan Lynx <zlynx at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20070223/a119142a/attachment.pgp>


More information about the LUG mailing list