Convert command line arguments into an array in Bash

后端 未结 7 1383
清歌不尽
清歌不尽 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:46

    Here is another usage :

    #!/bin/bash
    array=( "$@" )
    arraylength=${#array[@]}
    for (( i=0; i<${arraylength}; i++ ));
    do
       echo "${array[$i]}"
    done
    

提交回复
热议问题