bash and command-line argument parsing - research

in «tip» by Michael Beard
Tags: , , , , , , ,

This is something that I toy with at times and then usually drop to the floor, as I really need to get something done, rather than try a bunch of different options.

It is something that I'd like to figure out for me. I have it worked out for Python, but it would be nice to have something for bash as well.

different ways of parsing command-line options

Right now, I'm just listing a bunch of interesting articles for this. I haven't had a chance to use them yet (as they seem a little involved and I needed to do something more quickly - but, I want to come back to it).

After quickly reading some of these, I'm still not sure. I like the idea of getopts (note, not getopt - notice the lack of "s" -- getopts is apparently a built-in command to bash (if it's new enough, so ... something to check on MacOs) and is pretty good). Though, a simple switch case that I've seen in several articles is pretty nice as well.

Most of what I'm trying to find something like this for, is the use of the jrnl, the journaling script that I use all the time, scripts I have written to make life easier for me. Most of the time, I really don't need to parse anything (or at most, just a single argument). But, it would be nice to have more.

In the case that got me looking, the script export_jrnls_md really needs 2 parameters and it's not really set up for that. So ...

Here are some links I found. I wrote some notes for the ones I thought good or had something interesting. The others, are good support material and might provide some extra light on some things, but aren't outstanding overall.

Currently, I think these are the two options to try:

Both have really good qualities.

Resources