> 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).
--
__Pascal_Bourguignon__ (o_ Software patents are endangering
() ASCII ribbon against html email //\ the computer industry all around
/\ and Microsoft attachments. V_/ the world http://lpf.ai.mit.edu/
1962:DO20I=1.100 2001:my($f)=`fortune`; http://petition.eurolinux.org/