How to pass an array argument to the Bash script

后端 未结 4 1236
猫巷女王i
猫巷女王i 2020-11-29 05:42

It is surprising me that I do not find the answer after 1 hour search for this. I would like to pass an array to my script like this:

test.sh argument1 array         


        
4条回答
  •  独厮守ぢ
    2020-11-29 06:19

    If this is your command:

    test.sh argument1 ${array[*]} argument2
    

    You can read the array into test.sh like this:

    arg1=$1
    arg2=${2[*]}
    arg3=$3
    

    It will complain at you ("bad substitution"), but will work.

提交回复
热议问题