Re: shel script problem regarding arrays
Stephane Chazelas wrote:
> On 23 Aug 2006 04:01:43 -0700, Danish wrote:
> [...]
> > After your suggestions, I modified the code a bit..Im pasting the code
> > below.
> >
> > #!/bin/sh
> >
> > array=(`ls -l /home/danish/scp | tr -s " " | cut -d " " -f9`)
> >
> > len=${#array[*]}
> >
> > i=$(($i + 1))
> >
> > printf "%s\n" "${array[@]}"
> >
> > echo "ssh to 192.168.10.98 starts here"
> >
> > array1=(`ssh 192.168.10.98 " cd /home/danish/scp; vdir * | tr -s \"
> > \"|cut -d \" \" -f9 "`)
> >
> > length=${#array1[*]}
> >
> > j=$(($j + 1))
> >
> > printf "%s\n" "${array1[@]}"
> >
> > This portion is working perfectly well. Now I would like to equate the
> > names of both the files ( on localhost as well as on the remote server.
> > For eg..If after running the script I get as output, the names of files
> > "a", "b" on both the machines. After comparing the names of the files
> > the script should delete the files "a", "b" on the local machine, if
> > they are present on both the machines..
> [...]
>
> Ok, you want to compare the content of two directories one local
> and one remote, and you want to delete the local files, if a
> file by the same name can be found on the remote machine?
>
> Then:
>
> #! /bin/sh -
>
> cd /home/danish/scp || exit
>
> {
> ls # list local files
> ssh -n 192.168.10.98 '
> cd /home/danish/scp && ls' # list remote files
> } | sort | uniq -d | sed 's/./\\&/g' | xargs rm -f --
> # uniq -d reports the dupplicates, sed makes that output
> # compatible with xargs expected input format and xargs gives
> # as argument to rm the names of the files it read from its
> # standard input
>
> There's no need for arrays. That's not how you do shell
> scripting.
>
> --
> Stephane
I copied you script and named it "remove_files.sh". But when I ran it
,the following error was reported.
../remove_files.sh
sed: -e expression #1, char 8: unterminated `s' command
#
Thanks
Danish
|