Basically I am making a script where I would like to give a list of parameters to some option, say -l
, eg:
usr@domain:$./somescript -l hi bye cry nigh
The list specified to -l
would be then stored into a specific array and iterated over.
So far, I have been using these lines from Arch linux's mkinitcpio script to do so. This allows one to specify a comma-separated list to an option:
_optaddhooks()
while :; do
case $1 in
-A|--add|--addhooks)
shift
IFS=, read -r -a add <<< "$1"
_optaddhooks+=("${add[@]}")
unset add
;;
What are some other methods to do this, particularly when other options/parameters will be used? Can the list provided to an option be space separated? Or is specifying a list by "," (or some other character") easier to manage?