Linux for Developers
/Beginner
Variables
Definition
Temporary storage locations in a Bash script used to hold data (like strings or numbers) that can be referenced or changed later in the script.
Explain Like I'm New
A labeled box. You put the word 'Alice' into a box labeled 'NAME'. Later in the script, you tell the computer to 'Print NAME', and it prints 'Alice'.
Real World Example
In a script: `BACKUP_DIR="/var/backups"` `cp database.sql $BACKUP_DIR` If the company changes their backup folder location, the developer only has to change the variable at the top of the script once, rather than hunting through 500 lines of code.
Common Use Cases
- •Making scripts reusable
- •Storing dynamic paths
Interview Questions
basic
- In Bash, why will `NAME = 'Alice'` (with spaces around the equals sign) cause a massive error?
intermediate
- What is the difference between single quotes (`'`) and double quotes (`"`) when using variables?