0
0
Bash Scriptingscripting~20 mins

Tilde expansion (~) in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tilde Expansion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command?
Consider the following bash command run by user 'alice' whose home directory is '/home/alice':

echo ~

What will be printed?
Bash Scripting
echo ~
A/root
B~
C/home
D/home/alice
Attempts:
2 left
💡 Hint
The tilde (~) expands to the current user's home directory in bash.
💻 Command Output
intermediate
1:30remaining
What does this command output?
Given that user 'bob' exists with home directory '/home/bob', what is the output of:

echo ~bob

when run by user 'alice'?
Bash Scripting
echo ~bob
A/home/bob
B~bob
C/home/alice
DError: user not found
Attempts:
2 left
💡 Hint
Tilde followed by a username expands to that user's home directory.
📝 Syntax
advanced
2:00remaining
Which command correctly uses tilde expansion to list files in the home directory?
You want to list all files in your home directory using tilde expansion. Which of the following commands will work correctly?
Als '~/'
Bls "~/"
Cls ~/
Dls ~
Attempts:
2 left
💡 Hint
Tilde expansion does not occur inside quotes.
💻 Command Output
advanced
1:30remaining
What is the output of this command?
Assuming user 'carol' has home directory '/home/carol', what is the output of:

echo ~carol/Documents

when run by user 'dave'?
Bash Scripting
echo ~carol/Documents
A/home/carol/Documents
B~carol/Documents
CError: user carol not found
D/home/dave/Documents
Attempts:
2 left
💡 Hint
Tilde expansion works with usernames followed by paths.
💻 Command Output
expert
2:00remaining
What is the output of this script snippet?
Consider this bash script snippet run by user 'eve' whose home directory is '/home/eve':

dir=~
echo "$dir"

What will be printed?
Bash Scripting
dir=~
echo "$dir"
A/home/eve
B~
CError: invalid assignment
D$HOME
Attempts:
2 left
💡 Hint
Tilde expansion does not happen during variable assignment without evaluation.