bash argument case for args in $@

后端 未结 5 1671
无人共我
无人共我 2021-02-02 12:14

I have a script with a long list of OPTIONAL arguments. some have associated values.

Such as:

.script --first 2012-12-25 --last 2012-12-26 --copy --remov         


        
5条回答
  •  隐瞒了意图╮
    2021-02-02 12:36

    Use shift in the end of each case statement.

    Quote from a bash manual:

    shift [n]

    The positional parameters from n+1 ... are renamed to $1 .... Parameters represented by the numbers $# down to $#-n+1 are unset. n must be a non-negative number less than or equal to $#. If n is 0, no parameters are changed. If n is not given, it is assumed to be 1. If n is greater than $#, the positional parameters are not changed. The return status is greater than zero if n is greater than $# or less than zero; otherwise 0.

提交回复
热议问题