How can i delete an element in an array and then shift the array in Shell Script?

前端 未结 4 1006
迷失自我
迷失自我 2021-01-01 23:46

First let me state my problem clearly:

Ex: Let\'s pretend this is my array, (the elements don\'t matter as in my actual code they vary):

array=(jim         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-02 00:04

    Try this:

    user@pc:~$ array=(jim 0 26 chris billy 78 hello foo bar)
    user@pc:~$ for itm2rm in chris 78 hello; do array=(\`echo ${array[@]} | sed "s/\<${itm2rm}\>//g"\`); done ; echo ${array[@]}
    jim 0 26 billy foo bar
    

提交回复
热议问题