bash script issue

William Muriithi william.muriithi-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Sun Aug 17 17:53:07 UTC 2014


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





More information about the Legacy mailing list