This guide is the beginner-friendly reference for BashMissions.
It is here to answer the questions that many early levels assume you are still learning:
- What is Bash?
- What does a shell script do?
- What are
$1,$2, and"$@"? - How do strings, variables, conditions, loops, and functions work?
- Why does quoting matter so much?
If a level feels confusing, come back here. You do not need to memorize everything at once.
Bash is a shell and a scripting language.
When you type commands in a terminal, Bash can run them one at a time. A Bash script is just a text file containing terminal commands and simple programming logic so the computer can repeat tasks for you.
Example:
#!/usr/bin/env bash
echo "Hello"
echo "World"If that file is called solution.sh, Bash runs the lines from top to bottom.
Many scripts start like this:
#!/usr/bin/env bashThis tells the system to run the file with Bash.
You will also often see:
set -euo pipefailThis makes scripts safer:
-e: stop when a command fails-u: error on undefined variablespipefail: fail a pipeline if part of it fails
For learning, this is useful because mistakes appear earlier and more clearly.
Suppose you have:
#!/usr/bin/env bash
echo "Hello from Bash"You can run it with:
bash solution.shOr make it executable and run:
chmod +x solution.sh
./solution.shWhen a script is run with extra words after its name, those are arguments.
Example:
./solution.sh apple bananaInside the script:
$1isapple$2isbanana$3is the third argument$#is the number of arguments"$@"means all arguments, safely quoted
Example:
#!/usr/bin/env bash
echo "First: $1"
echo "Second: $2"
echo "Count: $#"Quoting is one of the biggest Bash basics.
Use quotes around variables unless you have a very specific reason not to.
Good:
echo "$1"
cp "$source" "$target"Risky:
echo $1
cp $source $targetWithout quotes, spaces can break your input into multiple pieces.
Example:
name="Ada Lovelace"
echo "$name"This prints one value: Ada Lovelace
Set a variable like this:
name="Fatemeh"Use it like this:
echo "$name"Important:
- No spaces around
= - Variable names are usually letters, numbers, and
_
Good:
count=3
user_name="sam"Bad:
count = 3Strings are just text values.
Examples:
message="hello"
echo "$message"Single quotes and double quotes are different:
name="Ada"
echo '$name'
echo "$name"Output:
$name
Ada
Single quotes keep the text literal. Double quotes allow variable expansion.
You can store command output in a variable:
today=$(date +%Y-%m-%d)
echo "$today"This runs date +%Y-%m-%d and stores the result.
Commands return an exit status:
0usually means success- non-zero usually means failure
You can set a script exit code:
exit 0
exit 1Many BashMissions levels check both output and exit status.
An if statement lets your script choose what to do.
Example:
#!/usr/bin/env bash
if [ -f "$1" ]; then
echo "file exists"
else
echo "missing"
exit 1
fiCommon tests:
[ -f "$path" ]file exists[ -d "$path" ]directory exists[ "$a" = "$b" ]strings equal[ "$a" != "$b" ]strings not equal[ -n "$value" ]string not empty[ -z "$value" ]string is empty
Loops repeat work.
for item in one two three; do
echo "$item"
donecount=1
while [ "$count" -le 3 ]; do
echo "$count"
count=$((count + 1))
doneUse arithmetic expansion:
count=2
next=$((count + 1))
echo "$next"You can read from the user or from redirected input:
read -r name
echo "Hello, $name"The -r flag is a good default because it avoids surprising backslash behavior.
Functions let you reuse logic.
say_hello() {
echo "Hello, $1"
}
say_hello "Ada"They make longer scripts easier to organize.
Many missions work with files.
Useful commands:
cat file.txtshow file contentscp source targetcopy a filemv old newmove or renamerm file.txtremove a filemkdir dircreate a directory
Inside Bash scripts, always think carefully about whether a path exists before using it.
You can send output into files:
echo "hello" > out.txt
echo "world" >> out.txt>overwrite>>append
You can read input from a file:
while read -r line; do
echo "$line"
done < data.txtA pipe sends output from one command into another:
cat data.txt | wc -lYou will often see cleaner versions like:
wc -l < data.txtor:
grep "error" data.txtecho $1Safer:
echo "$1"Wrong:
name = "sam"Correct:
name="sam"BashMissions often checks exact output. Even a missing colon, extra space, or extra line can fail a level.
Some levels want success for one path and exit 1 for another.
If the level mentions optional arguments or missing files, your script must handle those too.
When a level feels hard, use this order:
- Read the mission carefully.
- Identify the inputs.
- Identify the exact required output.
- Identify the required exit code.
- Write the smallest script that handles the happy path.
- Add the failure path or edge cases.
- Run
check. - If stuck, use
hint. - If still stuck, use
guide. - If completely blocked, use
answer, then study why it works.
A Bash script usually does four things:
- Read input
- Make a decision
- Run commands
- Print output and exit with the right status
If you keep asking those four questions, most early BashMissions levels become much easier to reason about.
You do not need to “feel ready” before moving forward.
Bash gets easier by repetition:
- read the mission
- write a tiny script
- run the check
- fix one mistake at a time
That is the whole game.