Correct usage of bash getopts using long options -
i have written below code using long options getopts
, doesn't work (arguments have no effect on values of variables). correct syntax?
while getopts "c:(mode)d:(file1)e:(file2)" opt; case $opt in -c|--mode) mode=$optarg ;; -d|--file1) file1=$optarg ;; -e|--file2) file2=$optarg ;; esac done
i found code in question ksh
, not bash
. getopts
can't use long options. ended manually parsing arguments below
while test -n "$1"; case "$1" in -c|--mode) mode=$2 shift 2 ;; -d|--file1) file1=$2 shift 2 ;; -e|--file2) file2=$2 shift 2 ;; esac done
Comments
Post a Comment