2 votes by tummy 3 months ago — 2 votes, 8 comments

The first option looks incredibly silly as implementing the interface properly is not trivial

I have become so used to using getopts, I don't really find any problems setting it up.


It looks like argbash has put quite a bit of thought into this.

This looks interesting, but I don't see the benefit right away. Is there a side-by-side comparison between getopts and argbash or should I just wait until my next task to try it out?

I try to use only things that default installed with Ubuntu to keep dependencies low. But it seems to fix a problem I do not have in that urgency.

They seem to have a few practical reasons explained in their README.

I am still not convinced. There is no real problem to fix. and a Docker image?!? WTF?!

I use the following bash only approach to parse arguments for a while now and it works for me fine

#!/usr/bin/env bash
# Based on: https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
set -euo pipefail
IFS="$(printf '\n\t')"

# set default values

declare -a positional=()

while [[ $# -gt 0 ]]

case $key in
    shift # past argument
    shift # past value
    shift # past argument
    shift # past value
    shift # past argument
    shift # past value
    shift # past argument
    *)    # unknown option
    positional+=("$1") # save it in an array for later
    shift # past argument
set -- "${#positional[@]}" # restore positional parameters

echo "FILE EXTENSION  = ${extension}"
echo "SEARCH PATH     = ${searchpath}"
echo "LIBRARY PATH    = ${libpath}"
echo "DEFAULT         = ${default}"
fc 1 vote 3 months ago

This is more or less the standard way but it's also a lot of code. Plus, bash scripts are cryptic anyway...

Na, bash script can be written clear and concise but most people don't case. The code I posted is WAY shorter than Argsbash code

This just reminded me of docopt but I'm not sure they have a bash port.