Anders Johansson wrote:
On Thursday 14 February 2008 05:41:23 David C. Rankin wrote:
Listmates,
I have run into a bash problem with a simple for loop I don't understand and would like input from the gurus to determine if the tldp documentation is in error or if it is me. Safe money says it's me, but here is the situation.
I am using example 9.1.2.2. from the following link to construct a simple for loop to extract a directory full of zip files:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_01.html
The example give is:
[carol@octarine ~/html] cat html2php.sh #!/bin/bash # specific conversion script for my html files to php LIST="$(ls *.html)" for i in "$LIST"; do NEWNAME=$(ls "$i" | sed -e 's/html/php/') cat beginfile > "$NEWNAME" cat "$i" | sed -e '1,25d' | tac | sed -e '1,21d'| tac >> "$NEWNAME" cat endfile >> "$NEWNAME" done
This is actually in a tutorial? Wow
for i in *; do NEWNAME=${i%html}.php echo beginfile > "$NEWNAME" sed -e '1,25d.........
So I created the following:
#!/bin/bash LIST="$(ls *.zip)" for i in "$LIST"; do unzip $i -d /mnt/nemesis-cfg/home/samba/computer/software/fonts/extract echo "Unzipped: $i to ../extract" done exit 0
for i in *.zip; do unzip "$i" -d /mnt/nemesis-cfg/home/samba/computer/software/fonts/extract done
You want to have the quotes around $i to guard against spaces in file names
Anders
Anders, I found the quotes around "$i" do not work for managing filenames with spaces. The filenames, spaces and all, are pulled in by the LIST="$(ls *.zip)". Quoted or unquoted, it makes no difference, because $i is just the next element in the list. Example: goodfile 001.jpg exists in the list as: goodfile 001.jpg for i $list; do echo "i = $1" done gives: i = goodfile i = 001.jpg regardless. Stumbling around, it seems if you include AFS='\n' it will keep the loop from breaking on spaces by specifying that it only break on newlines and not spaces. So filenames with spaces (all my wife's digital pictures are) this is the only thing I have found to work without extensive character and replacing spaces with '_': AFS='\n' for i $list; do Telling the loop not to break on spaces with AFS seems to work like a charm. Are there any better ways? echo "i = $1" done -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org