Re:Bash functions are better than I thought
by 1vuio0pswjnm7 on Sunday October 31, 2021 @07:56PM
(#29061668)
"Shell" as used here means the Bourne POSIX-like shell, such as NetBSD's Almquist shell, not userland utilities that the shell may or may not call in a script. Scripts can of course test for differences in utilities where there is uncertainty.
If scripts written for a POSIX-like "lowest common denominator" shell were not portable, methinks projects written for such a shell, such as autoconf, would not work on so many diffferent systems. The amount of free software found in open source OS repositories that is built using "configure" shell scripts is not small.
Debian and other Linux distributions use a shell derived from NetBSD's Almquist shell. People who design and maintain these operating systems suggest that, for non-interactive use, this Bourne shell is faster than Bash.
One of the principal things that "got done" using Bash (at least until 2017 -- after that, I couldn't say) off the top of my head was the GFS at NCEP. Yes, it was predominantly Fortran for number crunching; but what tied all the individual programs together was a super massive, maintained, and constantly modified and improved Bash script. And yes, there were plans in the works to switch out for something else (which is why I cannot say, four years later, what the status quo is). I should also mention, it was this Bash script that ran parallelized on the supercomputer -- and it was ultimately this script which, every three hours, produced the next set of forecasts, 24/7.
Re:Bash functions are better than I thought
by oweiler on Sunday October 31, 2021 @06:36PM
(#29061147)
Bash scripts and shell scripts are not portable.
They have to shell out to other commands in order to do something meaningful.
Depending on your OS, these commands may not exist, or have a different set of commandline flags.
djb has always used them, even in the shortest of scripts.
Otherwise I agree with everything in this comment.
There is a reasonable argument to avoid using bash for non-interactive scripts. The benefits of any additional bash features, so-called "bashisms", arguably do not outweigh the costs of making these scripts non-portable. One of the many advantages of shell scripts is that they are portable and have tremendous longevity; shell scripts can last a long, long time. There are no version changes and aggressive feature creep to worry about as is routinely the case with programming languages. The scripts just keep working, every day, and we can forget we are even using them, e.g., they are being used in the various ways by UNIX-like OS distributions.
One of the today's programmer memes was "Get Stuff Done". Maybe the shell was not meant for today's programmers. But for "sysadmins", or "DevOps", or whatever term anyone comes up with in the future, people who can "administer/operate" computers running a UNIX-like OS for themselves or for someone else like a client or an employer, the Bourne shell works for its intended purpose, better than anything anyone has come up with in the last 50+ years. There's a lot of stuff that "gets done" with the shell, whether it is on someone's own computer, their client's or their employer's.
Attempts at "shell replacements", cf. alternative shells, usually look like interpreters for programming languages, not shells. Perhaps this is not a coincidence.
Bourne shell is relatively small and fast. Computers with small form factors often use UNIX-like OS and when they do they usually include shells. Many programmers seem to dislike the notion that such a layer exists. They often try to blame the shell instead of their own lack of interest in learning to use it.
The shell is boring, and "boring" is sometimes the wisest choice. Most software has expanded to consume available resources (often the developer's choice not the user's). This makes computer performance gains difficult for the end user to discern, e.g., decade after decade, routine tasks seem to take the same amount of time. However the shell and many "standard" UNIX utilities have not changed as much in the same period. Subshells may have been "slow" many years ago. IMHO, they do not feel slow today. Routine tasks performed with the shell seem to run faster, as one would expect after hardware upgrade.
I posit: Life is too short to learn every programming language du jour but it is long enough to learn the Bourne shell, reasonably well.