Try quoting the argument list.

-- 
Austin Gonyou
Systems Architect
Coremetrics, Inc.
Phone: 512-796-9023
email: [EMAIL PROTECTED]

On Sun, 1 Apr 2001, Pascal J. Bourguignon wrote:

>
> > Date: Mon, 02 Apr 2001 02:53:35 +1000
> > From: Ivan Teliatnikov <[EMAIL PROTECTED]>
> >
> > Hi there,
> >
> > I am trying to use ssh to do some file mainpulation on a remote host.
> >
> > Consider bash script.
> >
> > if [ ! ` ssh $user@$host ls /host/home/user/tmp/bin/$dir_name ` ]; then
> >      echo -e " \\t Hm! $dir_name is not there, creat $dir_name"
> >       etc ...
> > fi
> >
> > this is working OK.
> >
> > but if I say
> >
> > if [ ! ` ssh $user@$host ls -ls /host/home/user/tmp/bin/$dir_name ` ];
> >
> > # NOTE ls -al option
> >
> >             etc...
> > fi
> >
> > it does not work error message: ./test: [: too many arguments
>
> [pascal@triton packages]$  [ ! "`ls`" ] && echo yes || echo no
> no
> [pascal@triton packages]$  [ ! `ls` ] && echo yes || echo no
> [: too many arguments
> no
>
>
> > Q1. Could you tell me why?
>
> Because ls  may return several  words and then  `` will write  them as
> several words,  while the  '!' operator of  test ([) expects  only one
> word as argument.
>
> > Q2  Any suggestion to make it working.
>
> Use "quotes".
>
>
>
> Note that ls may return a  lot of output. Testing for the existance of
> a remote directory would be done more economically with:
>
> ssh $user@$host [ ! -d $dirname ]` \
>     && echo $dirname is not a directory. \
>     || echo $dirname is a directory.
>
> or:
>
>     if ssh $user@$host [ ! -d $dirname ] ; then
>         $dirname is not a directory on $host for $user.
>     fi
>
> (ssh returns the status of the remotely executed program).
>
>

Reply via email to