Mailinglist Archive: opensuse (3572 mails)

< Previous Next >
Re: [opensuse] bash - why doesn't the tldp bash beginners guide for loop example work?
  • From: Anders Johansson <ajh@xxxxxxxxxx>
  • Date: Thu, 14 Feb 2008 21:49:18 +0100
  • Message-id: <200802142149.18579.ajh@xxxxxxxxxx>
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
--
Madness takes its toll
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References