How to use getopts to accept multiple parameters for a single option ?
Hi,
My requirement is to accept multiple parameters using a single option. can anyone help me on this ? For example : Suppose a script by name 'solar'. The aim of the script is to accept multiple filenames from the command prompt and search for a string which is also passed thru the command line. Something like: ./solar -s <string to be searched> -f <file1> <file2> <file3>I understood that I can use getopts to accept multiple arguments. But not sure how to accept multiple parameters for a single option. Can anyone help me on this ? |
getopts does not support multiple arguments to an option. A comma-separated list of values would be a single argument which you could then parse into individual values in the script.
Code:
./solar -s <string to be searched> -f <file1>,<file2>,<file3> Code:
Code:
IFS=',' files=($OPTARG) |
All times are GMT -5. The time now is 05:34 PM. |