Linux+ Powered by LPI 2

Here you have the best CompTIA LX0-104 practice exam questions

  • You have 99 total questions to study from
  • Each page has 5 questions, making a total of 20 pages
  • You can navigate through the pages using the buttons at the bottom
  • This questions were last updated on November 20, 2024
Question 1 of 99

Which of the following configuration files should be modified to globally set shell variables for all users?

    Correct Answer: B

    The correct configuration file to modify in order to globally set shell variables for all users is /etc/profile. This file is executed for login shells and applies settings that should be available to all users on the system. Therefore, modifying /etc/profile ensures that the shell variables are globally set for everyone.

Question 2 of 99

Which of the following commands are used to manage the environment and shell variables within a shell process? (Choose TWO correct answers.)

    Correct Answer: A, D

    The 'export' command is used to set environment variables that are passed to child processes. The 'set' command is used to set and unset shell options and positional parameters. These commands are essential for managing environment and shell variables within a shell process.

Question 3 of 99

Which of the following commands creates a function in Bash that outputs the sum of two numbers?

    Correct Answer: A

    In Bash, the correct syntax for defining a function is to use the 'function' keyword followed by the function name and curly braces to enclose the commands of the function. To output the sum of two numbers, we can use the 'echo' command and arithmetic expansion with $(($1 + $2)). This allows us to pass two arguments to the function, add them together, and print the result. The other options use incorrect keywords or do not perform the arithmetic operation correctly.

Question 4 of 99

What output will the following command sequence produce?

echo '1 2 3 4 5 6' | while read a b c; do echo result: $c $b $a; done

    Correct Answer: E

    The command sequence uses 'echo' to produce the string '1 2 3 4 5 6', which is then piped into a 'while read' loop. The 'read' command reads into three variables 'a', 'b', and 'c'. Since 'read' splits the input by spaces, 'a' gets '1', 'b' gets '2', and 'c' gets '3'. The 'echo' command in the loop then prints 'result: $c $b $a', which translates to 'result: 3 2 1'. The 'while' loop only runs once because the 'read' command consumes the whole input in one go when it reads into multiple variables and doesn't process remaining input fields separately. Thus, the output is 'result: 3 2 1'.

Question 5 of 99

When the command echo $? outputs 1, which of the following statements are true?

    Correct Answer: C

    The command echo $? outputs the exit value of the command executed immediately before echo. If the output is 1, it indicates that the prior command terminated with a non-zero exit value, usually signifying an error or failure.