Free preview.You're sampling one lesson — enroll free to unlock all 7 lessons and track your progress.
Enroll free lesson
Variables and Logic
Variables and Logic
In this lesson — part of Scripting Basics — you'll learn variables and logic in Bash and why it matters in real work.
Why it matters
Variables are how programs remember values — the foundation of every computation.
Key ideas
- A variable is a name bound to a value
- Choose clear, descriptive names
- Constants vs. reassignable variables
- Values have types
In practice
Here's how it looks in idiomatic Bash:
name="Ross" # no spaces around = in assignment
readonly PI=3.14159 # immutable for the rest of the script
declare -i count=0 # integer attribute: count+="3x" stays numeric
count+=5 # arithmetic add because of -i, not string concat
unset name # remove the variable entirely
echo "${greeting:-hello}, $USER ($count)" # default if unset/empty
Bash note: Whitespace around = breaks assignment because Bash would parse name = x as the command name with arguments, so assignments must be tight.
Try it yourself
Exercise: Declare three variables in Bash (a name, an age, and whether you're learning) and print them.
Recap
You now understand variables and logic and can apply it in Bash. Mark this lesson complete and continue to the next one.
