Tech News
← Back to articles

More shell tricks: first class lists and jq

read original related products more articles

More shell tricks: first class lists, jq, and the es shell

Preamble

It’s not a secret that most common shells don’t have first class lists.

Sure, you can pass a list to a program by passing each element in argv (e.g. with "$@" or "${list_variable[@]}" ), but what if you want to return a list?

There are a couple of options.

The challenge

As a more practical example of this, let’s implement split-by-double-dash , a function (or a program) that would return two lists: args that come before -- and ones that come after. That’s a common format used by command line utilities.

So, for example, split-by-double-dash a b c -- d e f should return the lists [a, b, c] and [d, e, f] , somehow.

One possible use case for this would be a wrapper around a utility that accepts arguments in this form.

The quoting way with jq

... continue reading