I start all my bash scripts from the following template, then modify it as needed. It is not fancy, but I think it supports the lowest common denominator that is compatible with other flag processing systems in all other languages that I am aware of. (In particular, it does not support '--option=opt' but uses '--option opt', which is cross-compatible). I like that it is small, easy to maintain, and avoids external de…
Bash code generator for command-line arguments
21–30 of 54 posts
Re: Bash code generator for command-line arguments
#22Re: Bash code generator for command-line arguments
#23I start all my bash scripts from the following template, then modify it as needed. It is not fancy, but I think it supports the lowest common denominator that is compatible with other flag processing systems in all other languages that I am aware of. (In particular, it does not support '--option=opt' but uses '--option opt', which is cross-compatible). I like that it is small, easy to maintain, and avoids external de…
Re: Bash code generator for command-line arguments
#24command -ffilename -f filename --file=filename -- -f is not an option
My template is at https://gist.github.com/webb/ff380b0eee96dafe1c20c2a136d85ef....
Re: Bash code generator for command-line arguments
#25Like @bxparks, I have a template for my bash scripts command-line parsing, but I like to stick to GNU-style options and I find that Bash's getopts command handles all these cases without trouble: command -ffilename -f filename --file=filename -- -f is not an option My template is at https://gist.github.com/webb/ff380b0eee96dafe1c20c2a136d85ef... .
Re: Bash code generator for command-line arguments
#26Like @bxparks, I have a template for my bash scripts command-line parsing, but I like to stick to GNU-style options and I find that Bash's getopts command handles all these cases without trouble: command -ffilename -f filename --file=filename -- -f is not an option My template is at https://gist.github.com/webb/ff380b0eee96dafe1c20c2a136d85ef... .
Using `-:` to build long-options on top of the short-option-only `getopts` builtin is a great hack.
Re: Bash code generator for command-line arguments
#27I'm probably going to get downvoted for this, but: writing bash scripts in general just isn't a fun experience. years ago, i started just writing ruby scripts for execution in the terminal instead of bash, and haven't had any problems with it so far.
For a scripting language, better look elsewhere.
If we had to standardize on one language, perhaps Python would be a good choice.
Re: Bash code generator for command-line arguments
#28I start all my bash scripts from the following template, then modify it as needed. It is not fancy, but I think it supports the lowest common denominator that is compatible with other flag processing systems in all other languages that I am aware of. (In particular, it does not support '--option=opt' but uses '--option opt', which is cross-compatible). I like that it is small, easy to maintain, and avoids external de…
This is nice! I suggest writing messages to standard error instead of standard output.
echo "message" 1>&2
Yes, that's probably a good idea, though I cannot recall this causing a problem for any script that I've written so far.Re: Bash code generator for command-line arguments
#29I start all my bash scripts from the following template, then modify it as needed. It is not fancy, but I think it supports the lowest common denominator that is compatible with other flag processing systems in all other languages that I am aware of. (In particular, it does not support '--option=opt' but uses '--option opt', which is cross-compatible). I like that it is small, easy to maintain, and avoids external de…
In my experience this is the simplest way. The only mod I’d suggest is to put positional arguments into an array so you can put flags anywhere but this will work fine for 99% of scripts.
Re: Bash code generator for command-line arguments
#30I'm probably going to get downvoted for this, but: writing bash scripts in general just isn't a fun experience. years ago, i started just writing ruby scripts for execution in the terminal instead of bash, and haven't had any problems with it so far.