Opinion on best practice...

Grant Edwards invalid at invalid.invalid
Wed Feb 6 16:18:09 CET 2013

On 2013-02-06, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> Chris Angelico wrote:
>> Python is not an "excellent option". It's a bad fit for shell
>> scripting, it just happens to be way better than a weak shell. Having
>> grown up on command.com, I found OS/2's cmd.exe to be a massive
>> improvement, and Windows's cmd.exe to be rather less impressive... but
>> both of them pale into insignificance compared to bash.
> I have to disagree with much of this. bash is a poorly designed
> language which, in my opinion, is only good enough for short (under
> 20 lines) throw-away scripts.

And the OP wanted to write someting that was what, about 3 lines?

> This is how you test whether something is not the name of a directory:
> [[ -d $dir ]] || {
>   echo "$FUNCNAME: $dir is not a directory" >&2
>   return 2
> }

It can be written more clearly.

> http://www.bashcookbook.com/bashinfo/source/bash-4.2/examples/functions/emptydir
> Arithmetic requires either calling an external program, or special magic
> syntax:
> z=`expr $z + 3`
> i=$(( i + 1 ))

Agreed: Bash is not good at math.  It should not be used for numerical

> Spaces are magic -- these two lines do radically different things:

So?  Leading spaces are magic in Python.

> bash is even more weakly typed than Perl. As far as I can tell, bash
> is completely untyped -- everything is text, all the time, even
> arrays.

Correct.  In bash, everything is a string.

If you're doing something other than manipulating files (and therefore
filenames and paths), then bash is probably the wrong language to use.

Grant Edwards               grant.b.edwards        Yow! Are we wet yet?

More information about the Python-list mailing list