Re: bash vs. python scripts - which one is better?
On 2007-08-07 12:39:37 -0700, David Brodbeck wrote:
> On Aug 7, 2007, at 11:42 AM, Manon Metten wrote:
>> I'm about to learn bash or python scripting.
Why not zsh (more powerful than bash) or perl?
>> Or should I learn bash scripting anyway?
> If you plan to do much system administration, learning bash scripting is
> worthwhile. There are three reasons I can think of right off the bat:
> - Every Unix-like system you encounter will have some version of the Bourne
> shell. Not every system will have Python.
Not every system has bash. If this is for compatibility, you can learn
POSIX sh, but e.g. Solaris /bin/sh is not a POSIX sh. For this reason
and because POSIX sh is limited (you can't execute a command and have
a timeout on it), I now write all my portable scripts in Perl since it
is on every system I've met.
> - You will often need to modify or maintain other people's bash scripts,
> since that's how most startup scripts and the like are written.
> - Simple bash scripts can be done right from the shell prompt, which is
> sometimes handy.
> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ;
> done' to encode a bunch of WAV files to MP3, to give a crude example.
This one is bad. Really.
for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done
This is another reason why sh sucks. It's too easy to write broken
Vincent Lefèvre <email@example.com> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)