help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting variable with getopts


From: hancooper
Subject: Setting variable with getopts
Date: Mon, 09 Aug 2021 18:57:05 +0000

>
> Try
>
> echo "${@:$OPTIND}"
>
> before the if to see if it has the value you expect. I'm guessing you may
> need to adjust the offset value.
>

Hi Dennis, I can see what you mean. "${@:$OPTIND}" is giving all argumunts from
$OPTIND onwards.  So now I am using

      ("v")
        echo "\${@:\$OPTIND}: ${@:$OPTIND}"
        if [[ ${@:$OPTIND:1} =~ ^[0-9]+$ ]]; then
          vb=${@:$OPTIND:1}
          OPTIND=$((OPTIND+1))
        else
          vb=1
        fi
        ;;

Would the change be satisfactory?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]