I want to pass the “--var-options
” into the “file.sh
” as follows:
/path/to/file.sh --var-options "arg1" "-arg2" "--arg3" "arg4" --foo-option "foo_1" "foo_2" "foo_3" --bar-option "bar_1" "bar_2"
Here is the format of “--var-options
“, “--foo-option
“, and “--bar-option
“:
--var-options "--arg1" "--arg2" "--arg3" "all_string_must_be_in_double_quotes"
--foo-option "foo_1" "foo_2" "foo_3"
--bar-option "bar_1" "bar_2"
Here are the possible values for “--var-options
“:
--var-options "--arg1" "--arg2" "--arg3" "all_string_must_be_in_double_quotes"
--var-options "--arg1" "all_string_in_double_quotes"
--var-options "--at-less-one_arg"
--var-options "any_length_1" ... "all_string_must_be_in_double_quotes"
Here is the file.sh
script for parsing the command line:
declare -a var_list=()
while true
do
case "$1" in
--var-options)
# How to get args for "--var-options" here?
# If the args are 2, then:
echo "2 args for --var-options are: $1, $2"
shift 3
# But the length of "--var-options" is dynamically and at less one arg:
# How to get: "$1" "$2" "$3" ... "$n" here?
# How to determine the count of args of "--var-options"
shift <var-length-count>
# Put all args related to "--var-options" into the "var_list" here
;;
--foo-option)
echo "3 args for foo are: $1, $2, $3"
shift 4
;;
--bar-option)
echo "2 args for bar are: $1, $2"
shift 3
;;
esac
done
How to get all args for the “--var-options
” and put them into the “var_list
“?