Bird
Raised Fist0
Bash Scriptingscripting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. Which shell is most commonly used as the default for scripting on many Linux systems?
easy
A. Zsh
B. Bash
C. Fish
D. sh

Solution

  1. Step 1: Understand default shell usage

    Bash is widely adopted as the default shell on many Linux distributions for scripting and interactive use.
  2. Step 2: Compare with other shells

    Fish and Zsh offer more user-friendly features but are not default. sh is simpler but less common as default.
  3. Final Answer:

    Bash -> Option B
  4. Quick Check:

    Default shell for scripting = Bash [OK]
Hint: Default Linux shell for scripts is usually Bash [OK]
Common Mistakes:
  • Confusing Fish or Zsh as default shells
  • Thinking sh is default on Linux
  • Assuming all shells are equally common
2. Which of the following is the correct way to start a script with the Fish shell?
easy
A. #!/bin/bash
B. #!/bin/sh
C. #!/bin/fish
D. #!/usr/bin/zsh

Solution

  1. Step 1: Identify the shebang for Fish shell

    The Fish shell uses the shebang line #!/bin/fish to specify the interpreter.
  2. Step 2: Compare with other shells

    #!/bin/bash is for Bash, #!/bin/sh for sh, and #!/usr/bin/zsh for Zsh.
  3. Final Answer:

    #!/bin/fish -> Option C
  4. Quick Check:

    Fish shell shebang = #!/bin/fish [OK]
Hint: Fish shell scripts start with #!/bin/fish [OK]
Common Mistakes:
  • Using #!/bin/bash for Fish scripts
  • Confusing Zsh and Fish shebangs
  • Omitting shebang line
3. What will be the output of this script run in Bash but not in Fish?
echo $(( 3 + 4 ))
medium
A. 7
B. 3 + 4
C. Syntax error
D. 7 with a newline and prompt

Solution

  1. Step 1: Understand arithmetic expansion in Bash

    Bash supports $(( expression )) syntax to calculate arithmetic expressions and outputs the result.
  2. Step 2: Behavior in Fish shell

    Fish does not support $(( )) syntax; it would cause an error or print the expression literally.
  3. Final Answer:

    7 -> Option A
  4. Quick Check:

    Bash arithmetic expansion = 7 [OK]
Hint: Bash uses $(( )) for math; Fish does not support it [OK]
Common Mistakes:
  • Expecting Fish to evaluate $(( ))
  • Confusing output with syntax error
  • Thinking output includes prompt
4. You run this script in sh and get an error:
for i in {1..3}; do echo $i; done

What is the main reason?
medium
A. for loop syntax is invalid in sh
B. Missing semicolon before do
C. Variable $i is not defined
D. sh does not support brace expansion {1..3}

Solution

  1. Step 1: Check brace expansion support in sh

    sh does not support brace expansion like {1..3}; this is a Bash feature.
  2. Step 2: Validate loop syntax

    The for loop syntax is valid, and semicolons are correctly placed; $i is defined by the loop.
  3. Final Answer:

    sh does not support brace expansion {1..3} -> Option D
  4. Quick Check:

    Brace expansion unsupported in sh = A [OK]
Hint: sh lacks brace expansion like {1..3} [OK]
Common Mistakes:
  • Thinking semicolon is missing
  • Assuming $i is undefined
  • Believing for loop syntax is wrong
5. You want to write a script that works in both Bash and Zsh but uses advanced features like arrays and arithmetic. Which is the best approach?
hard
A. Use #!/bin/bash and test in Zsh for compatibility
B. Write separate scripts for Bash and Zsh
C. Use #!/bin/sh and avoid arrays and arithmetic
D. Use Fish shell for better features

Solution

  1. Step 1: Consider shell compatibility

    Bash and Zsh share many features including arrays and arithmetic, so using Bash shebang is common.
  2. Step 2: Test script in Zsh

    Testing in Zsh ensures compatibility; #!/bin/sh is too limited, and Fish syntax differs greatly.
  3. Final Answer:

    Use #!/bin/bash and test in Zsh for compatibility -> Option A
  4. Quick Check:

    Bash script tested in Zsh = A [OK]
Hint: Write in Bash, test in Zsh for shared features [OK]
Common Mistakes:
  • Using #!/bin/sh and losing features
  • Assuming Fish is compatible
  • Writing separate scripts unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard