[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: something strange with rsh/ssh + bash/tcsh is happening. Please advise

On Sun, Jan 01, 2006 at 05:58:21AM -0600, Peter Samuelson wrote:
> So you want rsh/ssh to do the job of word splitting?  The question is

No! The easiest way to do word spliting is not to join the words again
after the shell has already split them. No, I am not sure if the
protocol support this. I think it should. So, for example:

myssh remotehost echo a 'b c' *

executes myssh with:
ARGV[0] = "myssh"
ARGV[1] = "remotehost"
ARGV[2] = "echo"
ARGV[3] = "a"
ARGV[4] = "b c"
ARGV[5] = "file1.txt"

(obviously I am assuming one file exists in the current directory on
the local machine)

Which will pass the parameters, still split, to the remote end end

exec*("echo","a","b c","file1.txt",NULL);

(note: I don't have the man page available to double check the
various exec variants)

> how elaborate its shell-emulation parser should be.  Handle \ and " and
> ' quoting?  Expand environment variables?  Expand globs?  Execute $()
> nested commands?  Handle | or || or && or >> or ! or <& or ; or & or ~?
> Implement builtins such as chdir and while?

If you really want this sort of expansion at the remote end (most of the
time I don't), that is easy:

myssh remotehost sh -c 'echo a "b c" *'

which will become three parameters:
echo a "b c" *

This also makes it more obvious (IMHO) why you need two levels of

WHat I propose is much the same as recommended elsewhere, e.g. I have
seen the recommendation you shouldn't use:

system('echo a "b c"');

In perl, as this requires invoking the shell - if instead you pass the
parameter as an array, the shell isn't required, no splitting of the
parameters is required, and this makes the script more secure.

Unfortunately, it seems the same methods have yet to come to
rsh/ssh, etc. Hmmm. I think sudo supports it though:

bam@snoopy:~$ sudo 'id; echo hi'
sudo: id; echo hi: command not found
bam@snoopy:~$ sudo sh -c 'id; echo hi'
uid=0(root) gid=0(root) groups=0(root)
Brian May <bam@debian.org>

Reply to: