Given the Bash array animals defined as ("a dog" "a cat" "a fish"), what does echo ${animals[1]} print?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

Given the Bash array animals defined as ("a dog" "a cat" "a fish"), what does echo ${animals[1]} print?

Explanation:
In Bash, array indices start at zero. The array defined has three elements: index 0 holds "a dog", index 1 holds "a cat", and index 2 holds "a fish". When you reference the element at index 1, you’re selecting the second item. Echoing that value prints "a cat". Note that the value contains a space, but echo prints it as that two-word string.

In Bash, array indices start at zero. The array defined has three elements: index 0 holds "a dog", index 1 holds "a cat", and index 2 holds "a fish". When you reference the element at index 1, you’re selecting the second item. Echoing that value prints "a cat". Note that the value contains a space, but echo prints it as that two-word string.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy