Free LPI 010-160 Actual Exam Questions - Question 5 Discussion

Question No. 5
The file script.sh in the current directory contains the following content:
#!/bin/bash echo $MYVAR
The following commands are used to execute this script:
MYVAR=value
./script.sh
The result is an empty line instead of the content of the variable MYVAR. How should MYVAR be set
in order to make script.sh display the content of MYVAR?
Select one option, then reveal solution.
US
SU
Saad U.
2026-02-21

B, env sets MYVAR only for that command’s run, so the script sees it correctly.

0
SU
Saad U.
2026-02-20

B, env MYVAR=value ./script.sh works because env creates a new environment for the command with MYVAR set. The original MYVAR=value ./script.sh fails since it doesn't export MYVAR to the script's environment.

0
SU
Saad U.
2026-02-16

Maybe B could work too since env sets the variable only for that command’s environment without needing export. It’s a quick way to pass MYVAR to the script.

0
RT
Ryan T.
2026-02-10

E imo, export MYVAR=value makes the variable available to the script's environment, so it can access MYVAR properly. Without export, the script won't see the value.

0
RT
Ryan T.
2026-01-28

B imo, env sets MYVAR only for the script execution without needing export.

0
RT
Ryan T.
2026-01-25

B tbh, using env MYVAR=value ./script.sh runs the script with MYVAR in its environment just for that command, so the script should see it without needing export.

0
DF
David F.
2026-01-20

That makes sense, but also think about how environment variables work with scripts. Just doing MYVAR=value before running the script (option C) sets it only in the current shell and doesn’t pass it to the script’s environment. Using env MYVAR=value ./script.sh (option B) explicitly runs the script with that variable in its environment, so B should work too. So, either exporting the variable beforehand (E) or using env (B) will fix it.

0
MV
Mark V.
2026-01-17

It’s E, you gotta export MYVAR for the script to see it.

0