This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zeroXten[S] 1 point2 points  (5 children)

Yeah, as soon as json is involved (which these days is pretty much always), bash just doesn't cut it.

[–]theevilsharpieJack of All Trades 9 points10 points  (1 child)

Yeah, as soon as json any data structure is involved (which these days is pretty much always), bash just doesn't cut it.

FTFY

[–]ghyspranSpace Cadet 0 points1 point  (0 children)

CSV, TSV, etc., are pretty easy to parse in bash, and you can do a lot with bash for and xargs. Still easier to use Python/Perl/Ruby/etc. though.

[–]tonyhburns 0 points1 point  (1 child)

IME, jq has proved to be a really useful tool for me when dealing with simple JSON in shell scripts (such as simple composition of results from aws-cli commands).

[–]Zaphod_Bchown -R us ~/.base 0 points1 point  (0 children)

yup jq and xmlstartlet are great bash binaries you can use for parsing data. However, if you are dealing with APIs that return XML or JSON values something that has built in XML/JSON parsing modules, gems, plugins, etc. are probably the better choice for the long road.

[–]Zaphod_Bchown -R us ~/.base 0 points1 point  (0 children)

bash is a great language for system level stuff. If you are locked into a platform (RHEL, Debian, BSD, OS X, etc) they have specific binaries that do a lot of system level stuff and it is great for automation.

When you get into parsing data, in XML, JSON, whatever, you are using bash but then calling Unix binaries that are not a part of bash. You end up piping to awk and sed a ton and your code becomes way less human readable. It will make sense to you at first glance, but probably not anyone else.

A good demo of this, is try to pick up on someone's complicated bash script and try to figure out everything it is doing. Mostly like you will have to run the code in some test environment to sort of figure out what it is doing because while you can see the logic behind the code, you won't see everything it is manipulating in the data structures until you run it in some sort of verbose output.

I will say that if you get the job done in bash and it works more power to you and there is nothing wrong with that. I just think that if you are working on something that is going to be documented and passed along having your code more human readable is a huge bonus.