Which of the following will output “onetwothree”?
- a. for n in one two three ; do echo –n $n ; done
- b. for val ; do echo –n $val ; done <one two three
- for n in one two three ; do echo -n $n ; done
- d. foreach n in one two three; do echo –n $n ; done
- e. foreach n in one two three { echo –n $n }
Reveal answer
Fill a bubble to check yourself
C
Correct answer
Explanation
The for loop iterates through the list 'one', 'two', 'three'. The echo -n $n command prints each without a newline. When concatenated, this produces 'onetwothree'. Option C is the correct syntax for this operation.
AI explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) for n in one two three ; do echo -n \$n ; done - This option is incorrect because it uses the incorrect syntax for the echo command. The correct option should use a hyphen (-n) instead of an en dash (–n).
Option B) `for val ; do echo -n \$val ; done