i have script launch checks on ubuntu machine.
i call script : ./script -f /tmp/file.txt --modules 001 002 003
all files 001, 002, etc... bash scripts.
the following main function problem :
main () { opts=`getopt -o hf:m: --long help,file:,modules: -n 'script.sh' -- "$@"` eval set -- "$opts" [ $# -eq 0 ] && echo "unknown options or parameters" && usage while [ $# -gt 0 ]; case "$1" in -f|--file) file="$2" shift ;; -h|--help) usage exit 1 ;; -m|--modules) modules="$2" shift ;; esac shift done [ -z "$modules" ] && echo "no module specified" && usage }
i $modules variable contains example 001 002 004
.
tried different things shift, that's complicated..
ideally, if can use "$@" rest of script settings , great.
edit : ./script.sh -f /tmp/file.txt --modules "001 002 003"
$modules variable contains "001 002 003" , example.
but have loop seems not iterate on args, on first... each $module
contains "001 002 003".
for module in "$modules"; echo "importing module $module" . modules/$module >> "$file" done
getopt can't arbitrary numbers of values, can pass modules list parameter usign " , later parser it:
./script -f /tmp/file.txt --modules "001 002 003"
inside script can each individual value:
for module in $modules ; echo $module done
Comments
Post a Comment