nerdexam
Linux_Foundation

LFCS · Question #90

After issuing: function myfunction { echo $1 $2 ; } in Bash, which output does: myfunction A B C Produce?

The correct answer is A. A B. When the Bash function myfunction is called with A B C, it only echoes the first two positional parameters, $1 and $2, resulting in "A B".

Submitted by chiamaka_o· Apr 18, 2026Essential Commands

Question

After issuing: function myfunction { echo $1 $2 ; } in Bash, which output does: myfunction A B C Produce?

Options

  • AA B
  • BA B C
  • CA C
  • DB C
  • EC B A

How the community answered

(57 responses)
  • A
    84% (48)
  • B
    2% (1)
  • C
    4% (2)
  • D
    2% (1)
  • E
    9% (5)

Why each option

When the Bash function `myfunction` is called with `A B C`, it only echoes the first two positional parameters, `$1` and `$2`, resulting in "A B".

AA BCorrect

In Bash, `$1` refers to the first argument passed to a function or script, and `$2` refers to the second. The function `myfunction` is defined to `echo` only `$1` and `$2`. When called with `A B C`, `A` becomes `$1`, `B` becomes `$2`, and `C` is `$3` but is not used by the function's `echo` command.

BA B C

`A B C` would be produced if the function echoed `$1 $2 $3` or all arguments like `$@`.

CA C

`A C` would require the function to explicitly skip `$2`.

DB C

`B C` would mean the function ignored `$1` and started from `$2` and `$3`.

EC B A

`C B A` would require specific reversal logic not present in the function.

Concept tested: Bash function positional parameters

Source: https://www.gnu.org/software/bash/manual/bash.html#Shell-Functions

Topics

#Bash functions#Positional parameters#Shell scripting#Argument passing

Community Discussion

No community discussion yet for this question.

Full LFCS Practice