Working with arrays

An array is a list of variables. For example, we can create an array called FRUIT, which will contain the names of many fruits. The array does not have a limit on how many variables it may contain. It can contain any type of data. The first element in an array will have the index value of 0:

[student@localhost ~]$ FRUITS=(Mango Banana Apple)[student@localhost ~]$ echo ${FRUITS[*]}Mango Banana Apple[student@localhost ~]$ echo $FRUITS[*]Mango[*][student@localhost ~]$ echo ${FRUITS[2]}Apple[student@localhost ~]$ FRUITS[3]=Orange[student@localhost ~]$ echo ${FRUITS[*]}Mango Banana Apple Orange

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.