Cheers,
Connie
P.S. There is a controversy about what bash option processing tool to use, since this one (getopts) does not support long options, while "getopt" does. Hard to pick a winner, both seem to have defects. More about the other tool in the next post.
BASH: getopts retrieving multiple variables from one flag - Stack Overflow
5 | I am stuck and need your guys help with with getops I created a bash script which looks like this when run: $ foo.sh -i env -d directory -s subdirectory -f file It works correctly when handling one argument from each flag. But when I envoke several arguements from each flag I am not sure how to pull the multiple varibale information out of the variables in getops.
After grabbing the options I then want to build directory structures from the variables foo.sh -i test -d directory -s subdirectory -s subdirectory2 -f file1 file2 file3 Then the directory structure would be
Any ideas? | |||
feedback |
3 | getopts options can only take zero or one argument. You might want to change your interface to remove the -f option, and just iterate over the remaining non-option arguments
So,
| ||||||
|
...
As you don't show how you hope to construct your list
it's a little unclear how to proceed, but basically you need to keep appending any new values to the appropriate variable, i.e.
Note that on the first pass dir will be empty, and you'll wind up with a space leading at the from of your final value for ${dirList} . (If you really need code that doesn't include any extra spaces, front or back, there is a command I can show you, but it will be hard to understand, and it doesn't seem that you'll need it here, but let me know)You can then wrap your list variables in for loops to emit all the values, i.e.
Finally, it is considered good practice to 'trap' any unknown inputs to your case statement, i.e.
I hope this helps. | |||
'via Blog this'