Re:Bash functions are better than I thought
by ReactiveJelly on Sunday October 31, 2021 @02:35PM
(#29059181)
Just don't use Bash.
[ Parent
| on HN ]
Re:Bash functions are better than I thought
by gavinray on Sunday October 31, 2021 @02:53PM
(#29059332)
A lot of the time you don't even have the luxury of assuming "bash" is present, you've got only "sh".
Since all valid "sh" syntax is valid "bash", you've got to restrict yourself to only sh-valid code in the event the host doesn't have bash.
I have gotten used to doing this -- these scripts usually wind up being run in Docker containers that don't have "bash" installed for the sake of minimalism.
IE, you can't use [[ $predicate ]], but instead [ $predicate ], etc. Lot of subtle differences.
Re:Bash functions are better than I thought
by Spivak on Sunday October 31, 2021 @04:20PM
(#29060028)
Not all sh syntax is valid bash — in bash [[ is reserved but not in sh. And if you want syntax that is valid but doesn’t do the same thing in sh vs bash there’s plenty of examples.
Re:Bash functions are better than I thought
by kevin_thibedeau on Sunday October 31, 2021 @07:49PM
(#29061614)
You can't ever assume that /bin/sh is a POSIX shell so then you get limited to just an early Bourne subset.
Re:Bash functions are better than I thought
by mistrial9 on Sunday October 31, 2021 @03:34PM
(#29059674)
I would agree with this and use python instead, but for uuhh "python problems with strings". IF you are 'blue sky' open, making new things, yes, sure. no BASH. But for things I built 8 years ago that are non-trivial, and I don't prioritize an entire rewrite, BASH works very well. And guess what, every two years that 8-years-ago just comes along with it. BASH is here to stay.