3 ms·
> Bash is the only shell scripting language permitted for > executables. > [...] > The only exception to this is where you're forced to by whateve
by nickysielicki 10y ago
> Bash is the only shell scripting language permitted for
> executables.
> [...]
> The only exception to this is where you're forced to by whatever
> you're coding for. One example of this is Solaris SVR4 packages
> which require plain Bourne shell for any scripts.
> [...]
> When to use Shell
>
> * If you're mostly calling other utilities and are doing
> relatively little data manipulation, shell is an acceptable choice
> for the task.
>
> * If performance matters, use something other than shell.
>
> * If you find you need to use arrays for anything more than
> assignment of ${PIPESTATUS}, you should use Python.
>
> * If you are writing a script that is more than 100 lines long,
> you should probably be writing it in Python instead. Bear in mind
> that scripts grow.
>
> * Rewrite your script in another language early to avoid a
> time-consuming rewrite at a later date.
Limiting the domain of shell scripts is the best advice in here. Shell scripts are terrible to maintain, and you should use perl or python if it's complicated.
But limiting the domain of shell scripts also probably means that you're not going to be using any advanced features of bash, so you should write it in sh instead. It's undoubtedly more portable, and it also serves to enforce the idea that you shouldn't write complicated shell scripts. I'll take a leap and say it outright, if you're using a feature of bash that isn't in bourne shell, you shouldn't be writing it in either of them.
The internet is littered with bash scripts that are compatible with bourne shell, but the shebang says '#!/bin/bash'. Well some systems don't have bash! But everyone has bourne shell.
I'm disappointed by their choice of bash and how this guide might reinforce that behaviour, but other than that, the actual style guidelines are great.
[Edit: rewording]
- Zardoz84 10y ago> * If you are writing a script that is more than 100 lines long, > you should probably be writing it in Python instead. Bear in mind > that scripts grow. > > * Rewrite your script in another language early to avoid a > time-consuming rewrite at a later date. Hehe. I did on DLang with a script that we have to update some instances of our application on develop machines. Our old bash scripts was becoming bigger and can't handle any more some few cases.
- nickysielicki 10y agoWhat made you choose D?
- ams6110 10y agoI've never learned perl in depth but I've never seen a perl script that didn't seem either a) overly complicated or b) terse to the point of being opaque. Shell scripts, for all their warts, tend to be fairly readable and easy to follow unless deliberately obfuscated. I would include Python here to a point as well, though Python is certainly friendly to architecture astronauts also.