0
0
Bash Scriptingscripting~20 mins

Bash vs other shells (Zsh, Fish, sh) in Bash Scripting - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shell Scripting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output difference: Bash vs Fish shell variable assignment
What is the output of the following commands when run in Bash and Fish shells respectively?

VAR=hello; echo $VAR
Bash Scripting
VAR=hello; echo $VAR
Ahello\nhello
Bhello\n$VAR
C$VAR\nhello
D$VAR\n$VAR
Attempts:
2 left
💡 Hint
Think about how variable assignment and expansion syntax differs between Bash and Fish.
💻 Command Output
intermediate
2:00remaining
Which shell supports this array syntax?
Consider this code snippet:

arr=(one two three)
echo ${arr[1]}


Which shell will output two when running this?
Bash Scripting
arr=(one two three)
echo ${arr[1]}
ABash
Bsh
CFish
DAll shells
Attempts:
2 left
💡 Hint
Think about which shells support arrays and their indexing style.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Fish shell function
Which option shows the correct Fish shell function syntax to print 'Hello World'?
A
greet() {
  echo 'Hello World'
}
B
function greet() {
  echo 'Hello World'
}
C
def greet():
  echo 'Hello World'
D
function greet
  echo 'Hello World'
end
Attempts:
2 left
💡 Hint
Fish shell uses a unique function syntax different from Bash or sh.
🔧 Debug
advanced
2:00remaining
Why does this sh script fail but Bash runs it?
Given this script:

#!/bin/sh for i in {1..3}; do echo $i; done

Why does it fail in sh but work in Bash?
Bash Scripting
#!/bin/sh
for i in {1..3}; do echo $i; done
Ash does not support for loops, Bash does
Bsh requires 'do' on the same line as 'for', Bash does not
Csh does not support brace expansion like {1..3}, Bash does
Dsh needs 'echo "$i"' with quotes, Bash does not
Attempts:
2 left
💡 Hint
Check which shell features are supported by POSIX sh.
🚀 Application
expert
3:00remaining
Automate environment setup: Which shell command sets a variable permanently?
You want to set an environment variable MY_VAR to 'value' permanently for your user.
Which command correctly adds this to your shell configuration for Bash, Zsh, and Fish respectively?
Aecho 'set -x MY_VAR value' >> ~/.bashrc && echo 'set -x MY_VAR value' >> ~/.zshrc && echo 'export MY_VAR=value' >> ~/.config/fish/config.fish
Becho 'export MY_VAR=value' >> ~/.bashrc && echo 'export MY_VAR=value' >> ~/.zshrc && echo 'set -x MY_VAR value' >> ~/.config/fish/config.fish
Cecho 'export MY_VAR=value' >> ~/.bash_profile && echo 'set -x MY_VAR value' >> ~/.zshrc && echo 'export MY_VAR=value' >> ~/.config/fish/config.fish
Decho 'set MY_VAR=value' >> ~/.bashrc && echo 'set MY_VAR=value' >> ~/.zshrc && echo 'set MY_VAR=value' >> ~/.config/fish/config.fish
Attempts:
2 left
💡 Hint
Remember the syntax for setting environment variables differs between Bash/Zsh and Fish.