Re: : bash script issue
Bill Thanis <[email protected]> Mon, 18 Aug 2014 10:16:58 -0400
| Newsgroups | gmane.org.user-groups.linux.tolug |
|---|---|
| Message-ID | <CAA3RLT71mKA0MuW06aj75GGBgFvm-XWqxUuboEd6k381ypN8fA@mail.gmail.com> |
Try this: ls | while read f ; do echo "$f"; done The for loop uses each individual space separated word as a parameter. The above will pass each name in the 'ls' as if it was on a separate line. You will still have to properly quote the varaiable. Bill On Sun, Aug 17, 2014 at 1:53 PM, William Muriithi < [email protected]> wrote: > Afternoon, > > I have a list of files that have horrible names and it is forcing me > to improve the intelligence of a script I have been using to clean up > the system after the images have been processed. Sample names are as > below > > '004378858 (152).jpg' > '004384040.jpg' > '004382728.jpg' > '004383192.jpg' > '004375871.jpg' > '004378858 (179).jpg' > '004378858 (155).jpg' > '004378858 (187).jpg' > > > If i run either of the below commands on the console, it list them > properly as above. > > #LIST=`find /home/wmuriithi/images/ -type f | cut -d"/" -f4| sed 's@ > @\\ @g' | sed 's@[(]@\\(@' | sed 's@[)]@\\)@'` > #LIST=`find /home/wmuriithi/images/ -type f | cut -d"/" -f4|sed -e > "s/.*/'&'/"` > > If I run it on a loop, it breaks the file name into two if the name has a > space > > for f in $LIST; > do > > mv /home/wmuriithi/images/"$f" /home/wmuriithi/archive/images/"$DATE"/ > # echo "rm $f" >> processed.list > echo "rm $f" >> processed.list2 > > done > > I get this error: > > mv: cannot stat `/home/wmuriithi/images/\'004378858': No such file or > directory > mv: cannot stat `/home/wmuriithi/images/(38).jpg\'': No such file or > directory > mv: cannot stat `/home/wmuriithi/images/\'004378858': No such file or > directory > mv: cannot stat `/home/wmuriithi/images/(53).jpg\'': No such file or > directory > > Now, I am curious, why do I get different behaviours above? What's a > better way of handling such a file name? > > Thanks in advance > > William > -- > The Toronto Linux Users Group. Meetings: http://gtalug.org/ > TLUG requests: Linux topics, No HTML, wrap text below 80 columns > How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists >