Lab Complete!

You wrote a working bash script.

LABS / bash scripting
BEGINNER+
Tasks
What is a bash script?

A bash script is a text file full of the same commands you'd type at a terminal, run all at once. It starts with a shebang line telling Linux which program should run it.

#!/bin/bash # everything below runs as bash commands

To run it: chmod +x script.sh once, then ./script.sh any time.

Variables
NAME="student" # no spaces around = echo "Hello, $NAME"

Put $ before a variable name to read its value. Double quotes let variables expand inside the text; single quotes do not.

Loops
for i in 1 2 3 do echo $i done

A for loop repeats its body once per item in the list, with the loop variable set to each one in turn.

Conditionals
if [ $NUM -eq 0 ] then echo "zero" else echo "not zero" fi
TestMeaning
-eq -nenumbers equal / not equal
-gt -ltgreater than / less than
== !=strings equal / not equal
-z -nstring is empty / not empty
Arithmetic
RESULT=$((5 + 3)) echo $((NUM % 2)) # remainder, useful for even/odd
Functions & arguments
greet() { echo "Hi, $1" } greet Alice # $1 inside the function = "Alice"

Functions group commands under a name. When called, $1, $2... refer to the words you pass after the function's name.

This lab's editor runs a simplified bash simulator in your browser — it understands the syntax above, but not every real bash feature.
Mission: Build up script.sh in the editor on the right, one piece at a time. Click Run after each change.
1
Variable and greeting
Set a variable to your name and echo a line starting with "Hello, ".
2
Loop through numbers
Add a for loop that echoes the numbers 1 through 5, one per line.
3
Even or odd
Pick a number, use $(( )) and an if/else to print "even" or "odd".
4
Function unlocks the flag
Write a function called unlock that, when called with the argument bash, echoes the flag. Call it and submit what it prints.
Try first, then peek. Hints nudge you without the exact answer.
Assign with NAME="yourname" then echo "Hello, $NAME" — double quotes let the variable expand.
The exact shape is for i in 1 2 3 4 5 then do, your echo $i, then done on its own line.
$((NUM % 2)) is 0 for even numbers, 1 for odd. Compare it with -eq 0 inside an if.
Define with unlock() { ... }, check if [ "$1" == "bash" ] inside it, then call it on its own line below with unlock bash.
Stuck after trying? Reveal the full script.
script.sh
Output will appear here after you click Run.
What this simulator understands
SyntaxDoes
VAR=valueAssign a variable
echo "$VAR text"Print, expanding variables
for v in a b c
do ... done
Loop over a list
while [ cond ]
do ... done
Loop while true (max 500 turns)
if [ cond ]
then ... else ... fi
Branch on a test
name() { ... }Define a function
$1 $2 $#Function/script arguments
$((expr))Arithmetic
read VARPulls next value from the stdin box