@@ -21,6 +21,12 @@ if test $# -lt 1; then
2121 <argname> <datatype> <varname> <help>
2222 ...
2323 help" >&2
24+
25+ echo " With <argname>:
26+ x for flags x with value (e.g., -f value, -h being reserved for help)
27+ - for sequential arguments in the order defined, without flags
28+ + to capture all remaining arguments as a single variable with spaces as separators
29+ & to capture all remaining arguments as a single variable with newlines as separators" >&2
2430 return 1
2531fi
2632
@@ -47,6 +53,9 @@ while read argname datatype varname help; do
4753 elif [ " $argname " = " +" ]; then
4854 line=" <$datatype ...>"
4955 helpinfo=" $helpinfo \n\t$( printf ' %-12s : %s' " $name " " $help " ) "
56+ elif [ " $argname " = " &" ]; then
57+ line=" <$datatype ...>>"
58+ helpinfo=" $helpinfo \n\t$( printf ' %-12s : %s' " $name " " $help " ) "
5059 else
5160 if [ " $datatype " = " -" ]; then
5261 line=" [-$argname ]"
@@ -108,17 +117,25 @@ else
108117 fi
109118 done
110119
111- # Process remaining '=' parameters
112- for arg in $( echo $varnames | grep -E " ^=" | cut -f2) ; do
113- if [ " $# " -gt " 0" ]; then
114- echo " $arg ='$1 '" && shift 1
115- fi
120+ # Process remaining '&' parameters
121+ for arg in $( echo $varnames | grep -E " ^&" | cut -f2) ; do
122+ lines=" "
123+ while [ " $# " -gt " 0" ]; do
124+ # spaces that are not escaped should be preserved as part of the argument
125+ if [ -z " $lines " ]; then
126+ lines=" $1 "
127+ else
128+ lines=" $lines \\\\ n$1 "
129+ fi
130+ shift 1
131+ done
132+ echo " $arg ='$lines '"
116133 done
117134
118135 # Process remaining '+' parameters
119136 for arg in $( echo $varnames | grep -E " ^\+" | cut -f2) ; do
120137 if [ " $# " -gt " 0" ]; then
121- echo " $arg ='$( echo $@ | sed " s/ /\t/g " ) '" && shift $#
138+ echo " $arg ='$@ '" && shift $#
122139 fi
123140 done
124141
0 commit comments