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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.