Join Scott Simpson for an in-depth discussion in this video Working with arrays, part of Learning Bash Scripting.
…In a script, you might want to keep track…of a collection of things, rather than one off variables.…For that, you can use an array.…In Bash, you declare that a variable is an array by enclosing it in parentheses.…Here's an empty array called a and an…array called b, that I'll give three elements.…Notice that they're aren't commas between these elements…like there are in a lot of other languages.…To retrieve an element from inside an array, you use its…zero based notation along with the variable name inside of curly braces.…So in this case when I run it, I'll…get cherry, because that's the item that's at index two.…Remember that arrays are zero-based.…
You can also set array values by index…number, and, you don't have to populate every element.…These sparse arrays can be very useful, when you need to record data with a…particular position in the list, instead of just adding to the end of the array.…But if you want to add something to the end…of an array, you can use the plus equals operator.…Make sure you put the value in parentheses.…
- What is Bash?
- Managing output with grep, awk, and cut
- Understanding Bash script syntax
- Creating a basic Bash script
- Displaying text with "echo"
- Working with numbers, strings, and arrays
- Reading and writing text files
- Working with loops
- Using functions
- Getting user input during execution
- Ensuring a response
Skill Level Beginner
Linux: Bash Shell and Scriptswith Kevin Dankwardt2h 46m Intermediate
1. Working with the Command Line
2. Building Bash Scripts
3. Control Structures
4. Interacting with the User
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.