Exam 102-500 Topic 5 Question 20 Discussion
Actual exam question for Lpi's 102-500 exam
Question #: 20
Topic #: 5
Question #: 20
Topic #: 5
After issuing:
function myfunction { echo $1 $2 ; }
in Bash, which output does:
myfunction A B C
Produce?
function myfunction { echo $1 $2 ; }
in Bash, which output does:
myfunction A B C
Produce?
Suggested Answer: A Vote an answer
In Bash, a function is a block of code that can be invoked by its name. A function can take arguments, which are passed to the function as positional parameters. The $1 variable refers to the first argument, $2 to the second argument, and so on. The function can access the number of arguments passed to it by using the $# variable. In this case, the function myfunction simply echoes the first and second arguments to the standard output. Therefore, when the command myfunction A B C is executed, the output is A B, since the third argument C is ignored by the function. Reference:
[LPI Linux Essentials - Topic 103: Command Line Basics]
[Bash Functions]
[LPI Linux Essentials - Topic 103: Command Line Basics]
[Bash Functions]
by Brady at Jul 05, 2025, 08:10 PM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).