Using getopts inside a Bash function

后端 未结 3 929
臣服心动
臣服心动 2020-11-28 04:59

I\'d like to use getopts inside a function that I have defined in my .bash_profile. The idea is I\'d like to pass in some flags to this function to alter its be

3条回答
  •  孤独总比滥情好
    2020-11-28 05:26

    The argument is stored in the varable $OPTARG.

    function t() {
      echo $*
      getopts "a:" OPTION
      echo $OPTION
      echo $OPTARG
    }
    

    Output:

    $ t -a bc
    -a bc
    a
    bc

提交回复
热议问题