0
0
Linux CLIscripting~20 mins

PATH variable management in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PATH Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PATH modification?
Consider the following commands run in a Linux shell:

export PATH=/usr/local/bin:$PATH

What will be the first directory in the PATH variable after running this command if the original PATH was /usr/bin:/bin?
Linux CLI
export PATH=/usr/local/bin:$PATH
echo $PATH
A/usr/local/bin:/usr/bin:/bin
B/usr/bin:/bin:/usr/local/bin
C/bin:/usr/bin:/usr/local/bin
D/usr/bin:/usr/local/bin:/bin
Attempts:
2 left
💡 Hint
Remember that placing a directory before $PATH adds it to the front.
💻 Command Output
intermediate
2:00remaining
What happens if you append an empty directory to PATH?
Given the command:

export PATH=$PATH::/usr/bin

What is the effect of the double colon (::) in the PATH variable?
Linux CLI
export PATH=$PATH::/usr/bin
echo $PATH
AIt inserts the current directory (.) in the PATH at the position of the empty entry
BIt causes a syntax error and PATH is not updated
CIt removes the last directory from PATH
DIt adds an empty directory that is ignored by the shell
Attempts:
2 left
💡 Hint
Empty entries in PATH are interpreted as the current directory.
📝 Syntax
advanced
2:00remaining
Which command correctly removes /usr/local/bin from PATH?
You want to remove /usr/local/bin from the PATH variable in a bash shell. Which of the following commands will do this correctly?
Aexport PATH=$(echo $PATH | sed -e 's|:/usr/local/bin:||')
Bexport PATH=$(echo $PATH | sed -e 's|:/usr/local/bin||')
Cexport PATH=$(echo $PATH | sed -e 's|/usr/local/bin||')
Dexport PATH=$(echo $PATH | sed -e 's|/usr/local/bin:||')
Attempts:
2 left
💡 Hint
Consider the position of /usr/local/bin in PATH and the colon separators.
💻 Command Output
advanced
2:00remaining
What is the output of this PATH check script?
Given this bash script snippet:

if [[ ":$PATH:" == *":/opt/bin:"* ]]; then
echo "Found"
else
echo "Not Found"
fi

What will be printed if PATH is /usr/bin:/opt/bin:/bin?
Linux CLI
PATH=/usr/bin:/opt/bin:/bin
if [[ ":$PATH:" == *":/opt/bin:"* ]]; then
echo "Found"
else
echo "Not Found"
fi
ANo output
BSyntax error
CFound
DNot Found
Attempts:
2 left
💡 Hint
The script adds colons around PATH to avoid partial matches.
🚀 Application
expert
3:00remaining
How to permanently add a directory to PATH for all users?
You want to add /custom/tools to the PATH environment variable permanently for all users on a Linux system. Which file is the best place to add this export command to achieve this?
A/root/.bash_profile
B/etc/profile
C/etc/bash.bashrc
D~/.bashrc
Attempts:
2 left
💡 Hint
Think about system-wide environment variables for all users.