Variables
Think of a variable as a named bucket that we can place data into. We can then use these variables (or, more practically, their contents) within our code.
To create, or Declare a variable, simply enter its name followed by an =
with no spaces, and then the value of the variable (again with no spaces):
Pro-Tip: BE CONSISTENT WITH YOUR NAMING SCHEMA
We can then reference variables with a $ sign:
Now, there are a few tripping points here. Consider the following:
Because there was a space in the variable value, bash tried to interpret it, viewing World as a command. To get around this, we have to encapsulate our input in either ' '
or " "
, but there are differences between them...
‘ ’
- The contents between them are literal, including special characters“ ”
- The contents between them are literal, but certain special characters are still interpreted, such as$
,\
, and`
Last updated