Which TWO statements about bash shell functions are correct? (Choose two.)

LPIC-1 Exam 102-500, objective 105. Shells and shell scripting medium

Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.

Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

The options

Choose 2.

Correct A function refers to the arguments it was called with as $1, $2 and so on, and may use them in any position

Correct. A function call sets the positional parameters for the duration of the call, which is what lets a function place its arguments anywhere in the commands it runs.

Correct A function can be placed in the environment of child bash processes with export -f

Correct. export -f name marks a function for export, and a child bash inherits the definition. Aliases have no equivalent.

Not correct A function must be defined in ~/.bash_profile; definitions in ~/.bashrc are ignored

Wrong. ~/.bashrc is the usual home for functions, since it is read by every interactive non-login shell. Neither file is privileged for function definitions.

Not correct Defining a function requires the function keyword; the name() form is not valid in bash

Wrong. Both name() { ...; } and function name { ...; } are accepted, and only the first is POSIX-portable.

Not correct A function is removed from the current shell with unalias

Wrong. unalias removes aliases. A function is removed with unset -f name; plain unset without -f looks for a variable of that name first.

Why

A function is a named compound command stored in the shell, so it takes positional parameters, contains control flow and can be exported with export -f. An alias is a text substitution of the first word of a command, so it cannot see its arguments and is not inherited by child processes at all. Where the two overlap, prefer the function: it behaves the same in scripts, whereas alias expansion is off by default in non-interactive shells.

Where this comes from

Cited
manual page bash(1)

Practise this

Reading one question is not practice. The trainer will draw a short set from objective 105 and space the ones you get wrong.

Practise LPIC-1 Exam 102-500

More questions on this objective

All questions on Shells and shell scripting

Practise LPIC-1 Exam 102-500