Challenge - 5 Problems
Shell Scripting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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 $VARBash Scripting
VAR=hello; echo $VAR
Attempts:
2 left
💡 Hint
Think about how variable assignment and expansion syntax differs between Bash and Fish.
✗ Incorrect
In Bash, 'VAR=hello' assigns the variable and 'echo $VAR' prints 'hello'. In Fish, the same syntax works similarly for this simple case, so both print 'hello'.
💻 Command Output
intermediate2:00remaining
Which shell supports this array syntax?
Consider this code snippet:
Which shell will output
arr=(one two three)
echo ${arr[1]}Which shell will output
two when running this?Bash Scripting
arr=(one two three)
echo ${arr[1]}Attempts:
2 left
💡 Hint
Think about which shells support arrays and their indexing style.
✗ Incorrect
Bash supports arrays with zero-based indexing and ${arr[1]} outputs 'two'. sh does not support arrays. Fish uses a different syntax for arrays.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this Fish shell function
Which option shows the correct Fish shell function syntax to print 'Hello World'?
Attempts:
2 left
💡 Hint
Fish shell uses a unique function syntax different from Bash or sh.
✗ Incorrect
Fish shell functions start with 'function name' and end with 'end'. Options A and D use Bash-style syntax. Option D is Python-like.
🔧 Debug
advanced2:00remaining
Why does this sh script fail but Bash runs it?
Given this script:
Why does it fail in sh but work in Bash?
#!/bin/sh
for i in {1..3}; do echo $i; doneWhy does it fail in sh but work in Bash?
Bash Scripting
#!/bin/sh for i in {1..3}; do echo $i; done
Attempts:
2 left
💡 Hint
Check which shell features are supported by POSIX sh.
✗ Incorrect
Brace expansion {1..3} is a Bash feature, not POSIX sh. sh treats it as a literal string, causing the loop to run once with '{1..3}'.
🚀 Application
expert3: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?
Which command correctly adds this to your shell configuration for Bash, Zsh, and Fish respectively?
Attempts:
2 left
💡 Hint
Remember the syntax for setting environment variables differs between Bash/Zsh and Fish.
✗ Incorrect
Bash and Zsh use 'export VAR=value' in their rc files. Fish uses 'set -x VAR value' in its config.fish file to export variables.