A very good rant about Bash scripting

1 Like

I totally understand where he’s coming from. Most bash scripts that I’ve dealt with over the years are really nothing more than glorified batch files.

1 Like

Exactly, most scripts are just running external processes in Bash subshells and combining inputs and outputs with pipes. It’s a pity, because Bash is capable of so much more!

But the worst thing is tutorials and books on shell programming, they very rarely teach you true Bash scripting. Instead they teach you how to use sed and awk, which are fine tools, but not Bash.

Yep, exactly right. One of the recent “bash” PDFs I downloaded did the same thing; I didn’t even realize that awk could be used as its own “shell” for programming.

I switched to fish shell awhile ago, but haven’t put enough effort into really learning how to program with it. I’m getting better with python, although I still find too many reasons to use sub-shelled programs when I can’t find the proper module.

1 Like

xonsh shell goes to further and if i am not mistaken dubs Bash shell as legacy. Since the bash scripting is closely tied up with the shell, i dont know how to call it.

As far as I can tell, xon.sh is not POSIX compliant (a bit like fish), so I would not set it as my default shell.

1 Like

BLOAT Again Shell

1 Like

Scary video!!! I’ll need to download it and watch it several times at slow speed.

Even I know about the useless use of cat and I just found Useless Use of Cat Award with other non-cat uselessness.

A couple of times in the video there was if [[ ... followed by then. I remember Luke Smith going on about how inelegant that was: Never say “If” writing a Bash script! (Exit codes & logical operators).

(Disclaimer: just because I post a link doesn’t mean I understand most of what’s in it.)

1 Like

And as a cherry on top they start with #!/bin/sh. :sweat_smile:

4 Likes

Who?

1 Like

Related to the original post:

  • Good Practice:
    You may be tempted to use external applications such as sed, awk, cut, perl or others to modify your strings. Be aware that all of these require an extra process to be started, which in some cases can cause slowdowns. Parameter Expansions are the perfect alternative.

From the BashGuide

1 Like

Here!!! especially in the comments to the answer.

I disagree with whomever wrote that post on Superuser. There is a place for advanced bash or even zsh features in scripts. The only condition is that the proper command interpreter is specified in the first line of the script. And the shell is not a terrible language, it’s quite powerful. It’s just that the syntax is very… peculiar :sweat_smile:

1 Like