The following is a simple array manipulation in bash:
1: #Create a new array2:3: declare -a Animales =('Dog' 'Cat' 'Hourse' 'Monkey' );4:5: Animales[4] = 'Pig'6:7: #print the Hourse8: echo ${Animales[2]}9:10: #The total no of animales in the array11:12: echo ${#Animales[@]}13:14: #get the 2th and the 3rt elements15:16: echo ${Animales[@]:2:2}17:18: #Replacing Cat with Lion19:20: echo ${Animales[@]/Cat/Lion}21:22: #Firing the Dog23:24: unset Animales[0]
We can although loop over the array
1: #loop over the array2: for i in "${Animales[@]}"3: do4: echo $i5: done6: #loop over the array last 3 elements7: for i in "${Animales[@]:2:3}"8: do9: echo $i10: done
Resources:
http://www.thegeekstuff.com/2010/06/bash-array-tutorial/
http://www.cyberciti.biz/faq/bash-for-loop-array/
אין תגובות:
הוסף רשומת תגובה