📖 Scenario: You are learning about different command-line shells used in computers. Each shell has its own features and ways to run commands. You want to see how Bash compares to other popular shells like Zsh, Fish, and sh.
🎯 Goal: Create a simple script that stores the names of these shells, adds a description for each, and then prints out the list with their descriptions. This will help you understand the differences in a clear way.
📋 What You'll Learn
Create a dictionary called shells with keys: Bash, Zsh, Fish, sh
Add a variable called highlight_shell set to Bash
Use a for loop with variables shell and description to iterate over shells
Print each shell and its description, marking the highlight_shell with an arrow
💡 Why This Matters
🌍 Real World
Understanding different shells helps you choose the right environment for scripting and daily command-line work.
💼 Career
Many IT and developer jobs require knowledge of shells like Bash and Zsh for automation and system management.
Progress0 / 4 steps
1
Create the shells dictionary
Create a dictionary called shells with these exact entries: 'Bash': 'Common default shell with scripting support', 'Zsh': 'Extended features and customization', 'Fish': 'User-friendly with smart suggestions', 'sh': 'Basic shell for scripting compatibility'
Bash Scripting
Hint
Use curly braces {} to create the dictionary with the exact keys and values.
2
Add a highlight shell variable
Add a variable called highlight_shell and set it to the string 'Bash'
Bash Scripting
Hint
Just assign the string 'Bash' to the variable highlight_shell.
3
Loop over shells and descriptions
Use a for loop with variables shell and description to iterate over shells.items(). Inside the loop, create a variable marker that is '->' if shell equals highlight_shell, otherwise an empty string ''.
Bash Scripting
Hint
Use a for loop with shell, description and a conditional expression for marker.
4
Print the shells with highlight
Inside the for loop, print the marker, the shell name, a colon, and the description. The output should look like: -> Bash: Common default shell with scripting support for the highlighted shell and without arrow for others.
Bash Scripting
Hint
Use an f-string to print the marker, shell, and description in one line.
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
Step 1: Understand default shell usage
Bash is widely adopted as the default shell on many Linux distributions for scripting and interactive use.
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.
Final Answer:
Bash -> Option B
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
Step 1: Identify the shebang for Fish shell
The Fish shell uses the shebang line #!/bin/fish to specify the interpreter.
Step 2: Compare with other shells
#!/bin/bash is for Bash, #!/bin/sh for sh, and #!/usr/bin/zsh for Zsh.
Final Answer:
#!/bin/fish -> Option C
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
Step 1: Understand arithmetic expansion in Bash
Bash supports $(( expression )) syntax to calculate arithmetic expressions and outputs the result.
Step 2: Behavior in Fish shell
Fish does not support $(( )) syntax; it would cause an error or print the expression literally.
Final Answer:
7 -> Option A
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
Step 1: Check brace expansion support in sh
sh does not support brace expansion like {1..3}; this is a Bash feature.
Step 2: Validate loop syntax
The for loop syntax is valid, and semicolons are correctly placed; $i is defined by the loop.
Final Answer:
sh does not support brace expansion {1..3} -> Option D
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
Step 1: Consider shell compatibility
Bash and Zsh share many features including arrays and arithmetic, so using Bash shebang is common.
Step 2: Test script in Zsh
Testing in Zsh ensures compatibility; #!/bin/sh is too limited, and Fish syntax differs greatly.
Final Answer:
Use #!/bin/bash and test in Zsh for compatibility -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.