Bash – $(( )) vs. $[]

Paul Smith paul at mad-scientist.net
Wed Dec 5 22:09:07 UTC 2012


On Wed, 2012-12-05 at 16:19 -0500, Gene Heskett wrote:

> No, I was just relating how easy it was to do with a bash script, running 
> as a daemon on this machine.  The printer wasn't intended to be the star, 
> the bash script that made it possible is the star.  Nowadays, there is a 
> java .jar in series with the path the data travels and its about 15x 
> faster, but the end result is the same.  Beautiful assembly language 
> listing hardcopy.

The argument is not between using bash vs. typing commands by hand, or
writing a C program.  The argument is between using bash vs. using POSIX
standard shell.  There are very few things in bash, from a scripting
standpoint, that are significant enhancements over POSIX shell; most of
it is just syntactic sugar.  The biggest advantage to bash IMO is
PIPESTATUS, if you really need to be checking every single failure
situation.  Even that can be worked around but it's gross.

The problem with writing bash scripts is that IF you ever wanted to use
them on an embedded system of any kind (your router, for example, but
there are many others) that uses (for example) busybox sh, you will be
sad.  And even if you never do that, if you help others write scripts
and given them bash-isms then they start to need them in other places,
they will be sad.

These things have a way of creeping into places you wouldn't expect and,
once there, causing problems.  You have no idea the number of times I've
reported bugs against some open source project that I needed on a
smaller system, for using bash scripts.  Half the time they say
#!/bin/sh at the top which is completely wrong, and the other half they
say #!/bin/bash but I still can't use them because I don't have it. You
look in the script and there's NO REASON they couldn't have used POSIX
sh.  They just didn't know or weren't careful.  Or didn't care.


I always say bash is the VAX of our era [1].



[1] http://dictionary.die.net/vaxocentrism





More information about the ubuntu-users mailing list