shflags
shflags copied to clipboard
Feature request: support for multi-value arguments
Will it be possible to support something like such in Bash getopts?
#! /bin/bash
while getopts ":t:" opt; do
case $opt in
t)
TAGS+=($OPTARG)
;;
esac
done
shift $((OPTIND-1))
for $tag in "${TAGS[@]}"; do
echo "Tag: $tag"
done
Output:
$ foo.sh -t one -t two
Tag: one
Tag: two
Do you mean just to incorporate tags or multi-value parameters into the template? Like the following
while getopts ":vht:" optname
do
case "$optname" in
"v")
echo "Version $VERSION"
exit 0;
;;
"h")
echo $USAGE
exit 0;
;;
"t")
TAGS+=($OPTARG)
I meant having multi-value parameters. "tags" is just an example of mine as most things that are taggable these days have multiple tags.
The existing boolean/integer/float/string data types may not be sufficient to represent TAGS in the example. It might make sense to have DEFINE_array but I can imagine it being pretty difficult to implement.
Ok, I see. You are right saying multi-value parameters are pretty useful. Will try to reuse/invent something. Thank you for providing valuable comments and sharing your ideas.