0
0
Bash Scriptingscripting~10 mins

Tilde expansion (~) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the current user's home directory using tilde expansion.

Bash Scripting
echo [1]
Drag options to blanks, or click blank then click option'
A~
B$PWD
C/home/user
D$HOME
Attempts:
3 left
💡 Hint
Common Mistakes
Using $PWD instead of ~, which gives the current directory, not home.
Using $HOME works but is not tilde expansion.
2fill in blank
medium

Complete the command to list files in the home directory of user 'alice' using tilde expansion.

Bash Scripting
ls [1]
Drag options to blanks, or click blank then click option'
A~alice
B~ /alice
C~/alice
D~alice/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a slash between ~ and username breaks tilde expansion.
Using ~/alice looks for a directory named 'alice' inside your home.
3fill in blank
hard

Fix the error in the command to copy a file to the home directory using tilde expansion.

Bash Scripting
cp file.txt [1]/documents/
Drag options to blanks, or click blank then click option'
A"~"
B'~'
C~
D$HOME
Attempts:
3 left
💡 Hint
Common Mistakes
Quoting ~ disables tilde expansion.
Using $HOME works but is not tilde expansion.
4fill in blank
hard

Fill both blanks to create a directory path inside the current user's home directory.

Bash Scripting
mkdir [1]/[2]
Drag options to blanks, or click blank then click option'
A~
Bprojects
Cdocuments
D/home
Attempts:
3 left
💡 Hint
Common Mistakes
Using /home instead of ~ for home directory.
Using 'documents' instead of 'projects' if the task expects 'projects'.
5fill in blank
hard

Fill all three blanks to create a file path to 'notes.txt' inside user 'bob's Documents folder using tilde expansion.

Bash Scripting
cp notes.txt [1]/[2]/[3]
Drag options to blanks, or click blank then click option'
A~bob
BDocuments
Cnotes.txt
DDownloads
Attempts:
3 left
💡 Hint
Common Mistakes
Using ~bob/Downloads instead of Documents.
Putting quotes around ~bob disables expansion.