0
0
Bash Scriptingscripting~10 mins

Bash vs other shells (Zsh, Fish, sh) in Bash Scripting - Interactive 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 shell name using an environment variable.

Bash Scripting
echo $[1]
Drag options to blanks, or click blank then click option'
ASHELL
BPATH
CHOME
DUSER
Attempts:
3 left
💡 Hint
Common Mistakes
Using PATH or HOME instead of SHELL.
2fill in blank
medium

Complete the code to list all files in the current directory using a shell command.

Bash Scripting
[1] -l
Drag options to blanks, or click blank then click option'
Apwd
Bcd
Cecho
Dls
Attempts:
3 left
💡 Hint
Common Mistakes
Using cd or pwd which do not list files.
3fill in blank
hard

Fix the error in the script to correctly check if the shell is Zsh.

Bash Scripting
if [ "$SHELL" = [1] ]; then
echo "You are using Zsh"
fi
Drag options to blanks, or click blank then click option'
A"/bin/zsh"
B"/bin/sh"
C"/usr/bin/fish"
D"/bin/bash"
Attempts:
3 left
💡 Hint
Common Mistakes
Using bash or fish paths instead of zsh.
4fill in blank
hard

Fill both blanks to create a script that prints 'Fish shell detected' if the shell is Fish.

Bash Scripting
if [ $[1] = [2] ]; then
echo "Fish shell detected"
fi
Drag options to blanks, or click blank then click option'
A$SHELL
B"/usr/bin/fish"
C"/bin/fish"
D$USER
Attempts:
3 left
💡 Hint
Common Mistakes
Using $USER or wrong shell paths.
5fill in blank
hard

Fill all three blanks to create a script that prints the shell name without the path.

Bash Scripting
shell_name=$(basename [1])
echo "Current shell is [2]"
# Check if shell is [3]
Drag options to blanks, or click blank then click option'
A$SHELL
B$shell_name
Cbash
Dfish
Attempts:
3 left
💡 Hint
Common Mistakes
Using the full path instead of just the shell name.