102-500 practice question 14 of 30
After issuing: function myfunction { echo $1 $2 ; } in Bash, which output does: myfunction A B C Produce?
Full set: 233 questionsBash functions process arguments as positional parameters. The function myfunction is defined to print only the first ($1) and second ($2) parameters it receives. When called as myfunction A B C, the shell assigns A to $1, B to $2, and C to $3. Since the function's echo command only references $1 and $2, it outputs A B, and the third argument C is ignored.
B. This is incorrect because the function's definition does not include $3 or a mechanism like $@ to process all arguments.
C. This is incorrect because $2 is assigned the value B, not C. The arguments are processed in the order they are given.
D. This is incorrect because the function is defined to print $1 and $2, not $2 and $3.
E. This is incorrect as it reverses the order of arguments and includes an argument ($3) that the function's code ignores.
1. GNU Bash Manual, Section 3.5.3 "Shell Functions". It states, "Positional parameters to the function are set when the function is executed... The special parameter ‘#’ is updated to reflect the change." This confirms functions use positional parameters like scripts.
2. "The Missing Semester of Your CS Education," MIT, 2020, Lecture 2: Shell Tools and Scripting. The lecture notes explain that $1, $2, etc., refer to the script's (or function's) arguments.
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 1What output is produced by the following command sequence? echo ‘1 2 3 4 5 6’ | while rea…
- 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…
