News for hackers. Stuff that matters.
Re:No script is too simple by ajuc on Tuesday September 22, 2020 @03:34PM (#24558830)
Ever tried to parse XML or json in linux shell?

It's not a matter of familiarity with linux shell. It's a matter of wasting time debugging/implementing stuff in shell that is trivial to implement in any modern scripting language.

Re:No script is too simple by freedomben on Tuesday September 22, 2020 @03:45PM (#24558952)
Haven't parsed XML in quite a number of years but I parse JSON to extract values from a curl command all the time with jq and it's really not that bad. If there's anything more than simple extraction required then I agree it's not good for the shell. For that I turn to the primary language of the project preferably (which these days is Elixir and sometimes Ruby for me).

But even JSON and (X|HT)ML you'd be amazed how often a simple grep can snag what you want, and regular expressions are also mostly universal so nearly everybody can read them.

Re:No script is too simple by ajuc on Tuesday September 22, 2020 @04:00PM (#24559120)
We (2-person team doing embedded QT app on linux) did it the exact way you're arguing for - starting with shell, struggling with it for several months every time something went wrong or we had to change it, and finally giving up and rewriting it in python.

Python wasn't our main language (the app was in C++ and QML which is basically java script). But we both knew Python and it's the easiest language for these sort of things that we both knew and that comes with the system.

My main conclussion is - I'm starting with python the next time.

Life's too short to check for the number of arguments in each function.

Re:No script is too simple by verall on Tuesday September 22, 2020 @05:43PM (#24560297)
I think there is a big difference between this and the parent. If you are working on projects where the "primary language" is Ruby or Python or Elixr than sure, use that, but if your project's primary language is C++, like most embedded applications, you do NOT want to use that.

Any complex or cross-platform C++ projects will need a scripting language in addition to shell and a build system.

Re:No script is too simple by chubot on Wednesday September 23, 2020 @01:25AM (#24563290)
Life's too short to check for the number of arguments in each function.

Ha! The Oil shell does that for you :)

https://www.oilshell.org/release/0.8.0/doc/idioms.html#use-p...

(It's our upgrade path from bash)

Re:No script is too simple by reificator on Tuesday September 22, 2020 @03:56PM (#24559077)
I do JSON pretty frequently with jq and idiomatic python[0] can't even approach its ease of use.

[0]: I'm sure there's a jq style library for python somewhere but it's definitely not the norm.

Re:No script is too simple by jdc on Tuesday September 22, 2020 @10:55PM (#24562467)
JMESPath works pretty well: https://github.com/jmespath/jmespath.py
Re:No script is too simple by tingletech on Tuesday September 22, 2020 @08:21PM (#24561565)
there are a couple of bindings from python to jq, I can't remember which I've used, but it makes it super simple to do jq queries from python
Re:No script is too simple by ak217 on Tuesday September 22, 2020 @07:24PM (#24561208)
Shameless plug: my project yq (https://github.com/kislyuk/yq) (pip install yq) includes a utility, xq, which transcodes XML to JSON using the Goessner JsonPath transformation (https://www.xml.com/pub/a/2006/05/31/converting-between-xml-...) so you can use jq to query XML.
Re:No script is too simple by kasabali on Tuesday September 22, 2020 @07:46PM (#24561376)
If you're trying to implement stuff in shell you're doing it wrong. It's a glue language.

and yes, parsing XML or JSON in "linux shell" is very easy. For JSON use jq, for XML use xml2 or xmlstarlet.

Re:No script is too simple by anon73044 on Tuesday September 22, 2020 @08:43PM (#24561709)
>json in linux shell? Yes!

Fortunately for me a 10 whole lines of sed, awk and some trimming and a for loop turned my json into a CSV to pass back to a legacy system. No curl or json modules necessary. That being said, if I needed anything more complex Python would be my default.