[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash vs. python scripts - which one is better?




On Aug 18, 2007, at 12:20 PM, Douglas A. Tutty wrote:
Also, I
find that some of the bash constructs are cryptic by their nature with
no clean work-arounds. They are likely perfectly clear to a proficient
bash coder but the finer points are lost on me.

It certainly has its warts. In particular, Bash's "test" (aka "[") operator has pitfalls. Testing for an empty variable, for example, is awkward. If you do:

if [ $foo == "" ]

Bash will complain about missing arguments. Instead, you have to do something like this:

if [ "x$foo" == "x" ]

which works, but makes no sense the first time you see it. The file- testing features of "test" are quite powerful and extensive, though -- there are few languages where it's quite so easy to test conditions like, 'is this a directory?'.

Bash is great if you need to glue together a bunch of existing utilities to do something. You can pipe output directly from one utility to another with an ease that doesn't exist in most other languages, which tend to make it complicated to launch other processes. Doing complex tasks with a series of simple utilities is sort of what Unix is all about.

Besides, until operating systems start having init scripts written in Perl or Python, being able to write shell scripts is going to be an essential system administration skill. ;)





Reply to: