DEV Community

loading...

Discussion on: Advanced Argument Handling in Bash

Collapse
rpalo profile image
Ryan Palo Author

Hmm. I hadn't heard of getopt. Neat! From just a quick search/read-up, here's what I am seeing people say:

GNU getopt seems like a reasonable alternative that makes long options a little easier. It looks like the syntax may be a little more complicated, but not problematically so. The main complaint I'm seeing is that it is external to Bash, so it's not quite as likely to be as portable as getopts, which is a Bash built-in.

That being said, if it's present on the system you're working on or if you're fine installing it, then it seems like a pretty OK alternative: tidying up the things you miss when you roll your own argument parsing, while still being relatively readable.

It reminds me a little of the Python argparse functionality.

I have read that it has issues with whitespace in arguments, but I can't confirm that without trying it out.

Thanks for sharing! :)