Skip to Main Content
Learning Linux Shell Scripting
book

Learning Linux Shell Scripting

by Ganesh Sanjiv Naik
December 2015
Beginner content levelBeginner
306 pages
5h 2m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting

Working with arrays

An array is a list of variables. For example, we can create an array FRUIT, which will contain many fruit names. 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 as 0:

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

Creating an array and initializing it

You will learn about creating an array in the Bash shell.

If the array name is FRUIT, then we can create an array as follows:

FRUIT[index]=value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Shell Scripting Essentials

Linux Shell Scripting Essentials

Sinny Kumari

Publisher Resources

ISBN: 9781785286216Purchase Link