Lesson 24 / 29
Variables & Conditionals
Storing values and branching in bash.
Variables
No spaces around =. Read a variable's value with $name.
name="Bob"
count=3
echo "$name has $count files"
Output:
Bob has 3 files
if / else
Test expressions go inside [ ] (spaces matter). -f checks a file exists.
if [ -f "notes.txt" ]; then
echo "File exists"
else
echo "Not found"
fi
Output:
File exists