Re: : bash script issue
"Dave Bour" <[email protected]> Sun, 17 Aug 2014 17:57:48 +0000
| Newsgroups | gmane.org.user-groups.linux.tolug |
|---|---|
| Message-ID | <[email protected]> |
Preface script with IFS=$'\n' Seen this a ton of times - spaces and white space create breaks in variable handling in a loop Sent from my iPad Dave Bour Senior Consultant Desktop Solution Center [email protected] 905.381.0077 > On 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 -- 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