From: Ron via Talk <talk@lists.gtalug.org>
Yesterday's meeting was a fun deep-dive into some `bash` quirks.
Mostly on how to determine if a script was sourced or run as an executable.
Hugh suggested that scripts should never be sourced unless specific conditions are desired. Not wrong, but the desire is to prevent users' terminal from closing on them, forcing the correct invocation.
I stand by that :-) You don't accidentally source a script: it takes explicitly using "source" or "." as a command. You don't do that with any program, why should shell scripts be different? The ONLY reason to use "source" is if you want the script to modify the current shell's environment. Dicey, but sometimes useful. I did learn that BASH is even weirder that I remembered. I learned to use the Bourne Shell almost 50 years ago. It was a big improvement over the earlier UNIX shell. But it is a bit odd. BASH is a LOT more complicated and most of the features don't pay for their additional complexity. I do admit that some features are great. - readline! (But I used that kind of command editing in the earlier Korn Shell (from Unix Systems Group)). - there are plenty of hacky features to improve programming, but, even so, I don't think that BASH is a good language for programming. In some sense, the successor the the Bourne Shell is Tom Duff's RC shell for Plan 9. I haven't used it, but I helped Byron Rakitzis with his UNIX/Linux implementation. I just installed it from the Fedora repos. This version seems to be configured to use GNU readline. <https://utcc.utoronto.ca/~cks/space/blog/unix/RcHistoryHowItWorks> BASH is really really fat: $ size /usr/bin/bash /usr/bin/dash /usr/bin/rc text data bss dec hex filename 1426035 49208 47072 1522315 173a8b /usr/bin/bash 109024 5016 11408 125448 1ea08 /usr/bin/dash 90580 3368 6344 100292 187c4 /usr/bin/rc Even more telling is the size of the man pages for each: $ man bash | wc 7430 58219 444766 $ man dash | wc 1601 10177 78627 $ man rc | wc 1139 6458 46263