[SWLUG] Stupidity with shell scripts

Chris M. Jackson C.M.Jackson at cs.cardiff.ac.uk
Thu Mar 13 15:41:32 UTC 2003


Wrote myself a nice little shell script

#!/usr/bin/env bash
# ^ because /bin/bash caused problems and locate works not
for fname in `ls`
do
    sed -e "s%<br>%<br />%g" $fname
done;

Now this worked, and changed all the relevant tags, however it dumped all
to stdout.  I thought "Look, I forgot to write back to the file!"

Changed the important bit to

    sed -e "s%<br>%<br />%g" $fname > $fname

(the idea being that I thought it would write back)
What I ended up with was a mass of zero-length files, and having to pester
our sysadmin to recover the files from backup (d'oh).

Not entirely on-topic when these are on Suns, but if anyone's interested
we have bash-2.03, however sed looks distinctly non-GNU and unwilling to
reveal a version number.

MTIA

-- 
|/  Chris M. Jackson
C>  Be seeing you!
H





More information about the Swlug mailing list