Modifying a parameter pass to a script (Bash)

前端 未结 3 531
醉酒成梦
醉酒成梦 2021-01-12 13:41

I have been looking on Google for quite a while now and can\'t find anything that is matching what I need/want to do.

My objective is to write a script that takes tw

3条回答
  •  被撕碎了的回忆
    2021-01-12 14:25

    To set the positional parameters $1, $2, ..., use the set command:

    set foo bar baz
    echo "$*"   # ==> foo bar baz
    echo $1     # ==> foo
    
    set abc def
    echo "$*"   # ==> abc def
    

    If you want to modify one positional parameter without losing the others, first store them in an array:

    set foo bar baz
    args=( "$@" )
    args[1]="BAR"
    set "${args[@]}"
    echo "$*"   # ==> foo BAR baz
    

提交回复
热议问题