How to pass an array argument to the Bash script

后端 未结 4 1241
猫巷女王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:31

    You can write your array to a file, then source the file in your script. e.g.:

    array.sh

    array=(a b c)
    

    test.sh

    source $2
    ...
    

    Run the test.sh script:

    ./test.sh argument1 array.sh argument3
    

提交回复
热议问题