> As posted on Linux Format User Forums:
> 
> Basically I was experimenting in shell script and was trying to create a
> useful script that took each file in the current directory (*.sh) and for
> each file, create a MD5 hash and save that hash in a file of the same name
> as the file (appended with a .md5 extension), so the basic script looked
> something like this:
> 
>  *Code:*
> FILES="*.sh"
> for f in $FILES
> do
>    md5sum $f > $f.md5
> done
> 
> 
> Now, what is annoying is I have just run this at home on ubuntu (debian)
> and
> it has done the job as expected, however when I ran this on a test box at
> work today running CentOS (RedHat) it kept putting ALL the MD5 hashes in
> one
> file called "*.sh.md5", whereas what I was expecting, and what I got on
> Ubuntu, was say I had some files like so:
> 
>  *Code:*
> shellscript1.sh
> shellscript2.sh
> 
> 
> after I run my script above in the current directory, and then run an "ls"
> I
> should get:
> 
>  *Code:*
> shellscript1.sh
> shellscript1.sh.md5
> shellscript2.sh
> shellscript2.sh.md5
> 
> 
> Can anyone explain this deviant behaviour on Red Hat and give any tips
> that
> would allow the shellscript to work on either platform?
> 
> Oh yes and if the code above is of any use you are welcome to it, and
> modify/redistribute as you see fit. It was a test really as I am learning
> "loops" at the moment and wondered if I could write a script that works
> with
> each file in a given folder.

Using "*" gives unpredictable results depending on the context. Better to use 
the output of a command:

LIST=`ls *.sh`

Cheers,
Malc

-- 
Technical copy-editor & proofreader

KDE Proofreading Team
KDE British English Translation Team

http://l10n.kde.org/team-infos.php?teamcode=en_GB

Facebook: http://www.facebook.com/FriendlyAtheist

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

_______________________________________________
Peterboro mailing list
Peterboro@mailman.lug.org.uk
https://mailman.lug.org.uk/mailman/listinfo/peterboro

Reply via email to