3 ms·
Why would anyone need a library when we could just do this? arg=default while [ -n "${1}" ] do case "${1}" in --arg)
by djha-skin 4y ago
Why would anyone need a library when we could just do this?
arg=default
while [ -n "${1}" ]
do
case "${1}" in
--arg)
shift
arg="${1}"
shift
;;
*)
print_help_page
shift
;;
esac
done
The above is terse, readable, and doesn't rely on any dependencies other than POSIX compatibility.
Often the whole point of shell scripts is that they're dependency free; nothing is needed other than the shell. After all, why code rustup in sh if not for this reason?
People who make libraries like this for shell are, I think, missing the point of shell.
- qbasic_forever 4y agoLooks like gibberish to me, and you're conveniently skipping all the documentation and argument parsing that docopt is providing.
- sacnoradhq 4y agoDon't do this: you have a bug when "$1" is ''. arg= while [[ "$#" -gt 0 ]]; do case "$1" in --arg) shift; arg="$1" ;; *) help; exit 1 ;; esac shift done
- BiteCode_dev 4y agoAnd that's why.
- tpmoney 4y agoUnless I'm reading the page wrong, this isn't a dependency per-se. That is the scripts you ship around won't depend on this, rather you write your bash script with the help doc information inside and then run this think to generate a new script that has the arg parsing stuff added in. You pass around the new script. The biggest issue I see with this is the generated code is a minified chunk of noise that can't be easily edited by hand by downstream users
- djha-skin 4y agoQuite right. Friends don't let friends generate shell script.
- k_roy 4y agomfw you didn't make it into the first paragraph...