LPI 102-500 Exam Questions
LPIC-1 Exam 102, Part 2 of 2, version 5.0 (Page 3 )

Updated On: 21-Feb-2026

After issuing:

function myfunction { echo $1 $2 ; }

in Bash, which output does:

myfunction A B C

Produce?

  1. A B
  2. A B C
  3. A C
  4. B C
  5. C B A

Answer(s): A

Explanation:

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]



Which of the following commands puts the output of the command date into the shell variable mydate?

  1. mydate="$(date)"
  2. mydate="exec date"
  3. mydate="$((date))"
  4. mydate="date"
  5. mydate="${date}"

Answer(s): A

Explanation:

(date)" Comprehensive Thecorrectwaytoputtheoutputofthecommanddateintotheshellvariablemy dateistousecommandsubstitutionwiththesyntax(command). This will execute the command in a subshell and replace the expression with its standard output. The double quotes around the expression will prevent word splitting and globbing of the output. The other options are incorrect because they will either assign a literal string to the variable, use an invalid syntax, or try to execute the command as an arithmetic expression.


Reference:

[LPI Linux Essentials - Topic 105: Shells, Scripting and Data Management] [LPI Linux Administrator - Exam 102 Objectives - Topic 105: Shells and Shell Scripting]



Which of the following files, when existing, affect the behavior of the Bash shell? (Choose TWO correct answers.)

  1. ~/.bashconf
  2. ~/.bashrc
  3. ~/.bashdefaults
  4. ~/.bash_etc
  5. ~/.bash_profile

Answer(s): B,E

Explanation:

The Bash shell can be configured by various files that affect its behavior, such as setting environment variables, aliases, functions, options, and prompts. Some of these files are global, meaning they apply to all users of the system, and some are local, meaning they apply to individual users. The global files are usually located in the /etc directory, while the local files are usually located in the user's home directory, which is denoted by the tilde (~) symbol1.
The local files that affect the Bash shell are:
~/.bash_profile: This file is executed when a user logs in to the system. It is used to set up the user's environment, such as the PATH, the default editor, the umask, and other variables. It can also run commands that are needed only once per login session, such as ssh-agent or fortune. This file can also source other files, such as ~/.bashrc, to inherit their settings12. ~/.bashrc: This file is executed when a user starts a new interactive shell, such as opening a terminal window or running a script with the shebang #!/bin/bash. It is used to set up the user's shell preferences, such as aliases, functions, options, and prompts. It can also source other files, such as /etc/bashrc, to inherit their settings12.
~/.bash_logout: This file is executed when a user logs out of the system. It is used to perform any cleanup tasks, such as clearing the screen, deleting temporary files, or printing a farewell message1. The other files listed in the question are not valid Bash configuration files and do not affect the behavior of the shell. Therefore, the correct answer is B. ~/.bashrc and E. ~/.bash_profile.


Reference:

1: Bash Shell Configuration Files - Land of Linux
2: Bash Startup Files - GNU Project



What is the difference between the commands test -e path and test -f path?

  1. They are equivalent options with the same behaviour.
  2. The -f option tests for a regular file. The -e option tests for an empty file.
  3. Both options check the existence of the path. The -f option also confirms that it is a regular file.
  4. The -f option tests for a regular file. The -e option tests for an executable file.

Answer(s): C

Explanation:

The test command is used to perform checks and comparisons on files and values. The -e option tests if a given path exists, regardless of its type (file, directory, link, etc.). The -f option tests if a given path exists and is a regular file, not a directory or a special file. For example, if we have a directory named dir and a file named file, we can use the test command as follows:
test -e dir && echo "dir exists" dir exists test -f dir && echo "dir is a regular file" (no output) test -e file && echo "file exists" file exists test -f file && echo "file is a regular file" file is a regular file


Reference:

https://www.howtoforge.com/linux-test-command/ https://www.computerhope.com/unix/bash/test.htm



How can the existing environment variable FOOBAR be suppressed for the execution of the script./myscript only?

  1. unset -v FOOBAR;./myscript
  2. set -a FOOBAR="";./myscript
  3. env -u FOOBAR./myscript
  4. env -i FOOBAR./myscript

Answer(s): C

Explanation:

The env command can be used to run a utility or command in a custom environment without having to modify the currently existing environment1. The -u or --unset option can be used to remove a variable from the environment12. Therefore, the command env -u FOOBAR./myscript will run the script./myscript in an environment where the variable FOOBAR is suppressed. The other options are incorrect for the following reasons:
A . unset -v FOOBAR;./myscript: This will unset the variable FOOBAR in the current shell, not just for the script execution. The semicolon (;) separates two commands, so the script will run in the same environment as the unset command.
B . set -a FOOBAR="";./myscript: This will set the variable FOOBAR to an empty string, not suppress it. The -a option means that the variable will be exported to the environment of subsequent commands, so the script will still see the variable FOOBAR, but with no value. D . env -i FOOBAR./myscript: This will run the script in an empty environment, not just suppress the variable FOOBAR. The -i or --ignore-environment option means that no environment variables will be passed to the command12.


Reference:

env command in Linux with Examples - GeeksforGeeks, env - Wikipedia.






Post your Comments and Discuss LPI 102-500 exam dumps with other Community members:

Join the 102-500 Discussion