102-500 practice question 1 of 30
What output is produced by the following command sequence? echo ‘1 2 3 4 5 6’ | while read a b c; do echo result $c $b $a; done
Full set: 233 questionsThe read command, when given more words in an input line than variable names, assigns the remaining words to the last specified variable. In this case, the single input line is '1 2 3 4 5 6'. The read a b c command assigns '1' to a, '2' to b, and the rest of the line, '3 4 5 6', to c. The echo command then prints the result by substituting these variables in the order $c, $b, $a, producing the output result 3 4 5 6 2 1. The loop runs only once as there is only one line of input.
A. result: 6 5 4: This output would require different input and loop logic, such as processing an input line of only "4 5 6".
B. result: 1 2 3 4 5 6: This would be the output if the command simply printed the original string, not reordered it.
D. result: 6 5 4 3 2 1: This implies a full reversal of all words, which the read command logic here does not perform.
E. result: 3 2 1: This would be the output if the input string from echo was only "1 2 3".
- GNU Bash Reference Manual, Version 5.1, Section 8.4, "Bash Builtin Commands", read builtin. "If there are more words than names, the remaining words and their intervening delimiters are assigned to the last name."
- The Single UNIX Specification, read utility, IEEE Std 1003.1-2017. "If there are more fields than variables, the last variable shall be assigned the value of the last field and all subsequent fields."
- Newham, C., & Rosenblatt, B. (1998). Learning the bash Shell. O'Reilly Media. Chapter 4, "Basic Shell Features", Section "The read Command".
Keep practicing
Take the free 102-500 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 102-500 practice questions
- Question 2Which command will set the local machine's timezone to UTC?
- Question 3Which of the following SQL statements will select the fields name and address from the co…
- Question 4Which of the following commands can remove a user from a group?
- Question 5Where are user specific crontabs stored?
- Question 6Which of the following crontab entries will execute myscript at 30 minutes past every hou…
- Question 8Which file, when using Sendmail or a similar MTA system, will allow a user to redirect al…
