Iterate through parameters skipping the first

前端 未结 5 1952
野的像风
野的像风 2020-12-24 02:25

Hi i have the following:

bash_script parm1 a b c d ..n

I want to iterate and print all the values in the command line starting from a, not

5条回答
  •  轮回少年
    2020-12-24 02:35

    This method will keep the first param, in case you want to use it later

    #!/bin/bash
    
    for ((i=2;i<=$#;i++))
    do
      echo ${!i}
    done
    

    or

    for i in ${*:2} #or use $@
    do
      echo $i
    done
    

提交回复
热议问题