Are there some built-in tools that will recognize -x
and --xxxx
as switches, and not arguments, or do you have to go through all the input variables, test for dashes, and then parse the arguments thereafter?
|
||||
|
Use It is fairly portable as it is in the POSIX spec. Unfortunately it doesn't support long options. See also this If you only need short options, typical usage pattern for
|
|||||
|
I assume you're using bash or similar. An example:
|
|||||
|
I wrote a script recently for work that was versatile and allowed for multiple kinds of switches in any order. I can't disclose the full script for obvious legal reasons (not to mention I don't have it with me at the moment), but here's the meat of it.. you can put it in a subroutine and call it at the end of your script:
I do recommend limiting your bash script to less than 400 lines/15k characters; my aforementioned script grew past this size and became greatly difficult to work on. I started rewriting it in Perl, which is much better suited for the task. Keep that in mind as you work on your scripts in bash. Bash is great for small scripts and oneliners, but anything more complex and you're better off writing it in Perl. Note, I haven't test the above, so it probably doesn't work, but you get the general idea from it. |
|||||||||||||||||
|
You have to write a cycle to parse the parameters. Indeed you can use This is a simple example from
|
|||
|