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

前端 未结 4 1004
迷失自我
迷失自我 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-01 23:53

    See http://www.thegeekstuff.com/2010/06/bash-array-tutorial

    1. Remove an Element from an Array

    ...

    Unix=('Debian' 'Red hat' 'Ubuntu' 'Suse' 'Fedora' 'UTS' 'OpenLinux');
    
    pos=3
    
    Unix=(${Unix[@]:0:$pos} ${Unix[@]:$(($pos + 1))})
    

    This contracts the array around pos, which the original poster wanted.

提交回复
热议问题