Using getopts in Shell properly??
I have a program which is basically written in sh (has to be) and it is trying to read inputs from the command line and if no input is given then it takes the default value.
Here is the code Code:
#!/bin/sh Code:
./test -t (option1|option2) This script is not working. It is sourcing correctly from the file and assigning the default value and echo out is correct. But I think because I am not mentioning -D -w -r etc , the getopts does not work Can anyone suggest how to get this working?? Ta |
You will have to define further, "does not work"? Seems to provide the output I would expect based on script and input.
|
If I get it right, the options p and i shouldn’t get a colon behind them as you don’t use $OPTARG in these cases. If an option like -p isn’t specified, its case won’t get executed. Do you referring to a missing set $NUM and $IPATH? Maybe these two should just go behind the case statement as they should always be executed.
|
All times are GMT -5. The time now is 02:59 PM. |