views:

59

answers:

2

Is there a way to write a BASH script that will append a string to every file in a directory?

e.g., I want to append the string "test" to every .html file in the current working directory I'm in; something like:

echo "test" >> *.html

But of course this doesn't work.

+2  A: 

Nevermind, I figured it out.

#!/bin/sh

for f in *.html ; do
    echo "test" >> $f
done
James Nine
@James, +1 for figuring it out, but I can't abide sparse code so I compressed it a bit :-) Hope you don't mind (if you do, just change it back).
paxdiablo
Better to put "$f" surrounded by quotes, specially if you have weird filenames (eg: with spaces)
LatinSuD
+2  A: 
sed -i.bak '$a append' *.html
ghostdog74