Convert command line arguments into an array in Bash

后端 未结 7 1381
清歌不尽
清歌不尽 2020-11-27 11:10

How do I convert command-line arguments into a bash script array?

I want to take this:

./something.sh arg1 arg2 arg3

and convert it

7条回答
  •  误落风尘
    2020-11-27 11:36

    Easier Yet, you can operate directly on $@ ;)

    Here is how to do pass a a list of args directly from the prompt:

    function echoarg { for stuff in "$@" ; do echo $stuff ; done ; } 
    
        echoarg Hey Ho Lets Go
        Hey
        Ho
        Lets
        Go
    

提交回复
热议问题