[Techtalk] command line
dominik.schramm at gmxpro.net
dominik.schramm at gmxpro.net
Sat Mar 20 15:53:12 EST 2004
Hi,
Finne Boonen <fboonen at vub.ac.be> writes:
> if somebody can help me out in getting it done for all files:
> (pseudocode)
>
> for i in *.php
>
> do
> cat newheader i.php > i2
> mv i2 i.php
> end
If "newheader" is a file containing the new header, then this
almost works:
* you have to reference the variable i with "$i"
* the values of $i are of the form blabla.php, file2.php, etc.php
i.e. they already contain the ending ".php"
* the for-loop syntax is for... do ... done (not "end")
You can do without this temporary file with something like:
for i in *.php
do
( echo -e 'newheader\n'; cat $i ) > i2
mv i2 $i
done
Note that "i2" is not a variable like i, but an ordinary file name.
If you want to make sure that temporary file name does not yet exist,
you can use tempfile, like this:
tempfile=`tempfile`
for i in *.php
do
( echo -n -e 'this is the new header\n'; cat $i ) > $tempfile
cp $tempfile $i
done
rm $tempfile
regards,
dominik
--
Dominik Schramm <dominik.schramm at gmxpro.net>
pgp key via http://www.cam.ac.uk.pgp.net/pgpnet/wwwkeys.html
More information about the Techtalk
mailing list