3 ms·
It's been my experience that for soe reason otherwise good developers who use functions liberally to modularize and DRY their code in <language X> seem to throw
by freedomben 6y ago
It's been my experience that for soe reason otherwise good developers who use functions liberally to modularize and DRY their code in <language X> seem to throw good software engineering priniples out the window when it comes to Shell.
You'd be amazed at how readable and un-gnarly most shell script become if you break them into functions. Control flow and loops become quite easy.
String manipulation on the other hand, if awk and jq can handle it reasonably well I'll use that, but I also forgive people for using a better scripting language. I prefer Ruby but I think using the language of the project is a better choice.
- krono 6y agoOh you hit the nail on the head! I have written some really basic shell scripts, and I try to use common shell modules/commands whenever it makes sense. It's just so confusing sometimes. The main challenges I faced in the beginning where caused by MacOS. MacOS comes with an older version of Bash, its default shell ZSH comes with its own slight variations on how it expects you to do things, and the utilities that come with MacOS aren't Gnu so the available options/arguments are not what you would find online. Then there is so much conflicting information online! A lot of it is also ancient, as in newsgroup archives from the 90s. String manipulation. When I look up how to do some specific replacement again, I come across all these massive inline awk scripts. But then I remember I could also just use sed and regex, or in some cases even just standard variable tricks, and achieve the desired result with 90% fewer code. The bigger scripts I've written are a mess.. I think. I still haven't been able to figure out how to error exit out of the entire script from a function that was called within it... :)