bet at rahul.net
Tue Jul 13 10:33:05 PDT 2004
One basic issue to consider, is choice of tools.
If you care to, you can simplify scripts by using platform-specific
aids like seq.
I, for one, tend to reach for perl when [relatively]
platform-independent tools don't suit, as I and the folks I work
with consistently provide that on all platforms we work on.
When the performance cost of doing so isn't too painful, I'll
generally reach for expr(1), since it's always there. If I want a
counted loop, and prefer to code it out rather than enumerating the
results, I'll use
while test $i -le 4;do
i=`expr $i + 1`
which brings up another choice-of-tools issue; some folk like to
try, as a habit, to write scripts in the subset dialect that is
pretty portable across platforms and across sh/bash/ksh/ash/....
Another thing I find myself doing a lot is replacing shell loops
with invocations of xargs, sometimes xargs -l. I also use perl a lot
from the cmdline. So if I wanted to do
mv "file 1" file.1
mv "file 2" file.2
mv "file 20" file.20
I'd probably go
perl -e 'rename "file $_","file.$_" for 1..20'
ls file*|perl -e 'rename $_,"file.$1" if / (\d+)$/'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
More information about the lfs-chat