DEV Community

Discussion on: Passing command-line options to bash scripts

Collapse
 
taikedz profile image
Tai Kedzierski • Edited

There is so much wrong here, you obviously have not checked your code at all.

  • You forgot to close the case block, which is a basic syntax error
  • Your usage of getopts is completely wrong - this is the correct usage
  • --longoptions does not exist. The getopts built-in command does not take such options. You may have used some external getopts command (which you might find with which getopts) but your example does not apply to normal systems
  • And my pet peeve, you're not quoting any of your variables, opening up to bugs galore.

Don't post code you haven't checkd, for pity's sake.

The bash scripting ecosystem is rife enough with bad examples and bad code, we really don't need any more atrocious and unchecked posts about it.

Collapse
 
zenulabidin profile image
Ali Sherief • Edited

I do admit I extracted the first example from a larger script of mine, and the second example came from the Stack Overflow link you linked.

I'll fix the problems you pointed out, thanks for letting me know about them. It's why I have the disclaimer at the end.

Regarding the --longoptions comment though, GNU getopt does have such an option. It's the version I used in the first example.