Unix - Shell Array MCQs

Shell Array MCQs : This section focuses on "Array" in Shell Progamming in Unix. These Multiple Choice Questions (MCQ) should be practiced to improve the unix skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.

1. What is true about array variable in Shell?

A. Shell supports a different type of variable called an array variable.
B. array variable can hold multiple values at the same time.
C. Arrays provide a method of grouping a set of variables
D. All of the above

View Answer


2. Which of the following is correct syntax for defining array values?

A. array_name{index}=value
B. array_name(index)=value
C. array_name[index]=value
D. [index]array_name=value

View Answer


3. What is the syntax of array initialization when you are using ksh shell?

A. array_name[index]=value
B. set -A array_name value1 value2 ... Valuen
C. array_name=(value1 ... valuen)
D. ${array_name[index]}=value

View Answer


4. What is the syntax of array initialization when you are using bash shell?

A. array_name[index]=value
B. set -A array_name value1 value2 ... Valuen
C. array_name=(value1 ... valuen)
D. ${array_name[index]}=value

View Answer


5. what is the syntax to access array values?

A. ${array_name[index]}
B. #{array_name[index]}
C. $${array_name[index]}
D. $[array_name{index}]

View Answer


6. A shell variable is capable enough to hold a single value. These variables are called __________________.

A. vector variables
B. scalar variables
C. array variables
D. None of the above

View Answer


7. Which of the following syntax is used to access all the items in an array?

A. ${array_name[*]}
B. ${array_name[@]}
C. ${array_name[$]}
D. Both A and B

View Answer


8. Which of the following code is used to print elements in range?

A. ${arr[@]:1:4}
B. ${arr[@]}
C. ${arr[*]}
D. Both A and C

View Answer


9. Which of the following code will count Length of in Array?

A. ${#arr[0]}
B. ${#arr}
C. ${#arr[#]}
D. Both A and B

View Answer


10. Which of the following is correct code to search in array?

A. ${arr[@]/*[aA]*/}
B. ${arr[#]/*[aA]*/}
C. ${arr[*]/*[aA]*/}
D. Both A and C

View Answer





Discussion



* You must be logged in to add comment.