100% Latest & Updated LPI 102-500 Practice Test Questions, Exam Dumps & Verified Answers!
30 Days Free Updates, Instant Download!
Question 40
An admin changes an environment setting in ~/.bashrc and runs a new script, but the current prompt still has the earlier value. Which THREE actions form a suitable remediation, verification and prevention plan? Select THREE.
- Test both branches of operational recovery scripts with controlled return codes.
- Validate changes in a disposable shell before sourcing large configurations in production.
- Inspect the generated record and confirm it contains the evaluated short hostname.
- Print the variable before and after source ~/.bashrc without closing the shell.
- Source ~/.bashrc in the current compatible Bash shell, then launch the dependent command.
- Assign host=$(hostname -s), then quote "$host" when writing the record.
Explanation
Correct Answers
B:Validate changes in a disposable shell before sourcing large configurations in production. It preserves the corrective behavior established through: Source ~/.bashrc in the current compatible Bash shell, then launch the dependent command.
D:Print the variable before and after source ~/.bashrc without closing the shell. The observation confirms the diagnosis or falsifies it before declaring the incident resolved.
E:Source ~/.bashrc in the current compatible Bash shell, then launch the dependent command. This is appropriate because Editing a startup file changes what future shells read; it does not rewrite the running shell's variables.
Incorrect Answers
A:The test for conditional recovery on failure would be: Simulate primary success and failure separately and verify recovery runs only for failure. The relevant acceptance check here is: Print the variable before and after source ~/.bashrc without closing the shell.
C:That choice responds to a capture command output safely failure. In this incident, Editing a startup file changes what future shells read; it does not rewrite the running shell's variables.
F:It would address capture command output safely rather than the present problem. The appropriate correction here is: Source ~/.bashrc in the current compatible Bash shell, then launch the dependent command.
Question 41
A site needs to remove temporary session files when interactive login shells exit, but a ~/.bashrc command runs on entry instead. Which mechanism best explains the difference between expectation and result?
- A semicolon executes the next command regardless of the earlier command's exit code.
- The read builtin normally treats backslashes as escapes unless -r is supplied.
- Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
- In POSIX shell the loop body must be between do and done to repeat each operation.
Explanation
Correct Answer
C:Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook. Addressing the cause requires: Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
Incorrect Answers
A:A semicolon executes the next command regardless of the earlier command's exit code. could help with successful command chaining; it neither resolves nor demonstrates the current requirement. The distinguishing check is: Exit a test login shell and verify only its intended temporary artifacts are removed.
B:That choice responds to a read lines without mangling backslashes failure. In this incident, Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
D:This belongs to loop over ordered sequence, where In POSIX shell the loop body must be between do and done to repeat each operation. The current issue instead is: Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
Question 42
A site needs to remove temporary session files when interactive login shells exit, but a ~/.bashrc command runs on entry instead. What should the administrator do to correct this behavior?
- Run narrowly scoped privileged operations through a reviewed sudo policy or a dedicated privileged service instead.
- Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
- Quote "$file" at each use and iterate safely over properly expanded pathnames.
- Use [ -n "$value" ] or a Bash-native conditional that handles empty strings safely.
Explanation
Correct Answer
B:Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling. It is the direct response; verify the result by: Exit a test login shell and verify only its intended temporary artifacts are removed.
Incorrect Answers
A:Linux generally ignores setuid elevation on interpreter scripts because it is unsafe. That describes a different fault. Here, Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
C:It would address preserve spaces in file paths rather than the present problem. The appropriate correction here is: Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
D:The test for avoid globbing in scalar tests would be: Run the script with the parameter empty, unset and populated to verify branching. The relevant acceptance check here is: Exit a test login shell and verify only its intended temporary artifacts are removed.
Question 43
A site needs to remove temporary session files when interactive login shells exit, but a ~/.bashrc command runs on entry instead. Which observation should be used for acceptance testing?
- Exercise the condition with 9, 10 and 12 and inspect its exit status.
- Exit a test login shell and verify only its intended temporary artifacts are removed.
- Inspect the generated record and confirm it contains the evaluated short hostname.
- Run the script with the parameter empty, unset and populated to verify branching.
Explanation
Correct Answer
B:Exit a test login shell and verify only its intended temporary artifacts are removed. It verifies that the targeted action (Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.) achieved its intended outcome.
Incorrect Answers
A:Exercise the condition with 9, 10 and 12 and inspect its exit status. belongs to a situation where Shell test string comparison does not perform numeric ordering; integer flags such as -gt are needed. Here the evidence supports a different requirement: Exit a test login shell and verify only its intended temporary artifacts are removed.
C:The script passes a command name as text instead of performing command substitution. That describes a different fault. Here, Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
D:The test for avoid globbing in scalar tests would be: Run the script with the parameter empty, unset and populated to verify branching. The relevant acceptance check here is: Exit a test login shell and verify only its intended temporary artifacts are removed.
Question 44
A site needs to remove temporary session files when interactive login shells exit, but a ~/.bashrc command runs on entry instead. Which repeatable check would reduce recurrence?
- Make logout hooks idempotent and avoid destructive cleanup on shared directories.
- Declare the required interpreter and avoid assuming every /bin/sh implementation is Bash.
- Standardize IFS= read -r for line-oriented scripts handling untrusted text.
- Test both branches of operational recovery scripts with controlled return codes.
Explanation
Correct Answer
A:Make logout hooks idempotent and avoid destructive cleanup on shared directories. It makes the outcome of the targeted repair (Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.) repeatable.
Incorrect Answers
B:This option assumes A /bin/sh shebang does not promise Bash extensions and direct execution follows the shebang interpreter. The reported symptoms instead call for: Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
C:The read builtin normally treats backslashes as escapes unless -r is supplied. That describes a different fault. Here, Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
D:Test both branches of operational recovery scripts with controlled return codes. belongs to a situation where The fallback lacks a failure condition, so it executes on the successful path as well. Here the evidence supports a different requirement: Make logout hooks idempotent and avoid destructive cleanup on shared directories.
Question 45
A site needs to remove temporary session files when interactive login shells exit, but a ~/.bashrc command runs on entry instead. Select TWO justified actions that address this particular problem and confirm closure.
- Exit a test login shell and verify only its intended temporary artifacts are removed.
- Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
- Use #!/usr/bin/env bash or an approved absolute Bash path for the Bash-dependent script.
- Test with a filename containing whitespace and confirm each file is processed once.
- Add an example of expected expansion to the script's acceptance tests.
Explanation
Correct Answers
A:Exit a test login shell and verify only its intended temporary artifacts are removed. This check is tied to the expected behavior rather than mere process uptime.
B:Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling. The change should be accepted only after this test: Exit a test login shell and verify only its intended temporary artifacts are removed.
Incorrect Answers
C:This option assumes A /bin/sh shebang does not promise Bash extensions and direct execution follows the shebang interpreter. The reported symptoms instead call for: Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
D:It would address preserve spaces in file paths rather than the present problem. The appropriate correction here is: Use ~/.bash_logout for appropriate per-user login-shell cleanup, with guarded path handling.
E:That choice responds to a capture command output safely failure. In this incident, Bash's ~/.bash_logout is the per-user login-shell exit hook, while ~/.bashrc is an interactive startup hook.
Question 46
A build command needs a one-off LANG=C without changing the user's interactive locale or later commands. Which diagnosis is supported by the observations?
- The script passes a command name as text instead of performing command substitution.
- An unquoted empty expansion removes an argument from the test expression.
- Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
- A /bin/sh shebang does not promise Bash extensions and direct execution follows the shebang interpreter.
Explanation
Correct Answer
C:Exporting LANG globally to the shell would affect subsequent children, not just the single build execution. Addressing the cause requires: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
Incorrect Answers
A:This option assumes The script passes a command name as text instead of performing command substitution. The reported symptoms instead call for: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
B:An unquoted empty expansion removes an argument from the test expression. could help with avoid globbing in scalar tests; it neither resolves nor demonstrates the current requirement. The distinguishing check is: Print LANG in the build subprocess and again afterward in the parent shell.
D:A /bin/sh shebang does not promise Bash extensions and direct execution follows the shebang interpreter. That describes a different fault. Here, Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
Question 47
A build command needs a one-off LANG=C without changing the user's interactive locale or later commands. Which remedial step follows from the observed mechanism?
- Run narrowly scoped privileged operations through a reviewed sudo policy or a dedicated privileged service instead.
- Capture status=$? immediately after the monitored command before printing further output.
- Assign host=$(hostname -s), then quote "$host" when writing the record.
- Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
Explanation
Correct Answer
D:Run LANG=C followed by the intended command so the assignment is scoped to that invocation. Unlike a broad workaround, it targets the observed cause: Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
Incorrect Answers
A:That choice responds to a script permissions and suid expectations failure. In this incident, Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
B:It would address exit status after a failing command rather than the present problem. The appropriate correction here is: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
C:Assign host=$(hostname -s), then quote "$host" when writing the record. belongs to a situation where The script passes a command name as text instead of performing command substitution. Here the evidence supports a different requirement: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
Question 48
A build command needs a one-off LANG=C without changing the user's interactive locale or later commands. Which check would provide the strongest evidence that the fix worked?
- Execute the script directly under the production launcher and verify it runs with Bash semantics.
- Print LANG in the build subprocess and again afterward in the parent shell.
- Run the script with the parameter empty, unset and populated to verify branching.
- Force a nonzero monitored result and confirm the captured value is unchanged after logging.
Explanation
Correct Answer
B:Print LANG in the build subprocess and again afterward in the parent shell. The test is evidence-based because the underlying failure was: Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
Incorrect Answers
A:The test for interpreter line selects bash would be: Execute the script directly under the production launcher and verify it runs with Bash semantics. The relevant acceptance check here is: Print LANG in the build subprocess and again afterward in the parent shell.
C:This belongs to avoid globbing in scalar tests, where An unquoted empty expansion removes an argument from the test expression. The current issue instead is: Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
D:This belongs to exit status after a failing command, where The special parameter $? reports the immediately preceding command's exit status, and echo overwrote it. The current issue instead is: Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
Question 49
A build command needs a one-off LANG=C without changing the user's interactive locale or later commands. Which practice is most useful after the immediate repair succeeds?
- Declare the required interpreter and avoid assuming every /bin/sh implementation is Bash.
- Gate success-side effects on checked exit statuses instead of command order alone.
- Use command-scoped environment overrides for reproducible automation and preserve user defaults.
- Use shell syntax checks and a controlled small fixture before rolling out looping probes.
Explanation
Correct Answer
C:Use command-scoped environment overrides for reproducible automation and preserve user defaults. It preserves the corrective behavior established through: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
Incorrect Answers
A:It would address interpreter line selects bash rather than the present problem. The appropriate correction here is: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
B:Gate success-side effects on checked exit statuses instead of command order alone. belongs to a situation where A semicolon executes the next command regardless of the earlier command's exit code. Here the evidence supports a different requirement: Use command-scoped environment overrides for reproducible automation and preserve user defaults.
D:Use shell syntax checks and a controlled small fixture before rolling out looping probes. belongs to a situation where In POSIX shell the loop body must be between do and done to repeat each operation. Here the evidence supports a different requirement: Use command-scoped environment overrides for reproducible automation and preserve user defaults.
Question 50
A build command needs a one-off LANG=C without changing the user's interactive locale or later commands. Choose THREE measures that together correct the failure, demonstrate success and reduce recurrence.
- Include filenames with whitespace and glob characters in automated script regression tests.
- Exercise the condition with 9, 10 and 12 and inspect its exit status.
- Print LANG in the build subprocess and again afterward in the parent shell.
- Use command-scoped environment overrides for reproducible automation and preserve user defaults.
- Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
- Place the network probe inside a for loop with a properly bounded sequence and do/done.
Explanation
Correct Answers
C:Print LANG in the build subprocess and again afterward in the parent shell. The test is evidence-based because the underlying failure was: Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
D:Use command-scoped environment overrides for reproducible automation and preserve user defaults. Sustained checks matter because Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
E:Run LANG=C followed by the intended command so the assignment is scoped to that invocation. It corrects the mechanism identified in the scenario: Exporting LANG globally to the shell would affect subsequent children, not just the single build execution.
Incorrect Answers
A:This option assumes Unquoted shell expansions undergo word splitting and pathname expansion after variable substitution. The reported symptoms instead call for: Run LANG=C followed by the intended command so the assignment is scoped to that invocation.
B:Exercise the condition with 9, 10 and 12 and inspect its exit status. could help with numeric comparison in sh; it neither resolves nor demonstrates the current requirement. The distinguishing check is: Print LANG in the build subprocess and again afterward in the parent shell.
F:The test for loop over ordered sequence would be: Log each expected host ID and verify all four are tested once. The relevant acceptance check here is: Print LANG in the build subprocess and again afterward in the parent shell.
LPI Level 1 (102-500) Practice Tests