For the first part of this chapter, we'll describe a few things we could not place properly in others parts of the book. With the exception of the first subject,arrays, bothhistory
andalias
are not really used in a scripting context so we elected to present them here. But first, arrays!
If you come from a developer background or have dabbled in programming, you will have (probably) come across the term array. If we needed to explain arrays in a single sentence, it would look like this: Arrays allow us to store a collection of dataof the same type. To make this a little less abstract, we'll show you how we can create an array of strings in Bash:
reader@ubuntu:~$ array=("This" "is" "an" "array") reader@ubuntu:~$ echo ${array[0]} This reader@ubuntu:~$ echo ${array[1]} is reader@ubuntu:~$ echo ${array[2]} an reader@ubuntu:~$ echo ${array[3]} array
In this string array, we place four elements:
- This
- is
- an
- array
If we want to print the string in the first place in the array...