0
0
Linux CLIscripting~20 mins

Shell concept (Bash, Zsh) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shell Scripting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this Bash command?
Consider the following command run in Bash shell:

echo $((3 + 5 * 2))

What will be printed on the screen?
Linux CLI
echo $((3 + 5 * 2))
A13
B16
C10
DError: invalid arithmetic expression
Attempts:
2 left
💡 Hint
Remember the order of operations in arithmetic expressions.
📝 Syntax
intermediate
1:30remaining
Which option correctly defines a function in Bash?
You want to create a function named greet that prints 'Hello'. Which of these is the correct syntax?
Afunction greet { echo 'Hello'; }
Bdef greet() { echo 'Hello' }
Cgreet() echo 'Hello'
Dfunction greet() echo 'Hello';
Attempts:
2 left
💡 Hint
Bash functions can be declared with or without the 'function' keyword, but syntax matters.
🔧 Debug
advanced
2:00remaining
Why does this script fail to print the variable value?
Given this script:

#!/bin/bash VAR=5 if [ $VAR -gt 3 ] then echo "Value is $var" fi

What is the reason for the output being empty?
Linux CLI
#!/bin/bash
VAR=5
if [ $VAR -gt 3 ]
then
  echo "Value is $var"
fi
AThe script lacks execution permission, so it doesn't run.
BVariable names are case-sensitive; $var is empty because VAR was set, not var.
CThe if condition syntax is wrong; it should use double brackets [[ ]].
DThe echo command is missing quotes around $var.
Attempts:
2 left
💡 Hint
Check how variable names are written and used.
🚀 Application
advanced
2:00remaining
Which command lists all files including hidden ones in long format sorted by modification time?
You want to see all files, including hidden ones (those starting with a dot), in your current directory. You want the list in long format and sorted by newest modified first. Which command achieves this?
Als -l -a -t
Bls -ltr
Cls -lat
Dls -l -a -r -t
Attempts:
2 left
💡 Hint
Check what each option means: -l, -a, -t, -r
🧠 Conceptual
expert
2:00remaining
What happens when you run this pipeline in Bash?
Consider this command:

echo 'apple banana cherry' | while read word; do echo $word; done

What will be the output?
A
apple
banana
cherry
B
apple banana cherry
apple banana cherry
CNo output, the loop does not run
Dapple
Attempts:
2 left
💡 Hint
Think about how 'read' works with default IFS and how the pipeline feeds input.