LinuxSA Mailing list archives
Index:
[thread]
[date]
[subject]
[author]
[stats]
From: Andrew McDonnell <andymc73@yahoo.com.au>
To : <linuxsa@linuxsa.org.au>
Date: Tue, 26 Jun 2001 12:29:45 +1000 (EST)
Re: for loop (bash) with spaces in filenames
n Mon, 25 Jun 2001, Peter Freeman wrote:
> for f in `cat /pathtolist/mp3.txt` do cp "$f"
/newdirectory done
>
> Can anyone see the glaring holes in the syntax? Or
is there a better
> way to do it?
Spaces do cause a problem somewhat - the for statement
will split the cat
output by space not by carriage return.
Try this - you may need to use something other than
"_" (e.g. "@" should work I think) if any of the
filenames have an underscore:
for f in `cat /pathtolist/mp3.txt | tr ' ' '_'` ; do
cp "`echo ${f} | sed 's/_/ /g'`" /newdirectory; done
"tr" in this case replaces all " " with "_" and sed
changes the "_" back to " " to
do the copy. The reason the cp command works with ``
in the loop body is because
there is is called one at a time instead of all at
once (I am sure someone with a more
intimate knowledge of the inner workings of the shell
could explain this better)
Andrew
PS anyone know how to stop the ?ISO8859 thingy yahoo
puts next to my name in the list digest header?
=====
-----------------------
www.comptroubsa.com
www.andrewmcdonnell.net
_____________________________________________________________________________
http://messenger.yahoo.com.au - Yahoo! Messenger
- Voice chat, mail alerts, stock quotes and favourite news and lots more!
--
LinuxSA WWW: http://www.linuxsa.org.au/ IRC: #linuxsa on irc.linux.org.au
To unsubscribe from the LinuxSA list:
mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject
Index:
[thread]
[date]
[subject]
[author]
[stats]
Return to the LinuxSA Mailing List Information Page