linux - Shell script to loop command line switches and arguments -
i'm trying write bash script check command line switchess , use next argument switches argument.
example:
sh myprogram.sh -s switcharg -p programarg start
within script i'm trying loop way:
if [ "$#" -gt 2 ] { i=1 arg in "$@" if [ "$arg" == "-s" ] || [ "$arg" == "-s" ] { i=$((i++)) myarg=$i # gets used later in script continue } elif [ "$arg" == "-p" ] || [ "$arg" == "-p" ] { i=$((i++)) myarg2=$i # gets used later in script continue } else { echo "illegal option: $arg" } done stuff } fi
how can detect switch , use next arg argument of switch regardless of amount of switches?
you can use "shift" remove first parameter..
instance:
arg1=$1; shift arg2=$1
Comments
Post a Comment