Posted: Tue 04 Aug 2009, 10:11
Chapter 83 - A little more about variables
Global Variables - These variables are set for system wide use. Some of the variables we set and exported in profile.local are global variables.
You want to try and avoid giving your script the same names as the global variables unless that's what you want.
PATH is a particularly important global variable. One time on the forum the coder used PATH=with:his:values and the rest of the script didn't run. The script has precedence.
Most of the variables I've set, in this series, I've used quotes. Actually, you don't need to quote your variables if there aren't spaces.
EDITOR=mp (doesn't need quotes)
EDITOR="mp" (doesn't hurt or change the end result)
EDITOR='mp' (also doesn't hurt or change the end result)
However sometimes quotes are the last thing you should use in a variable. As you have learned, many characters have special or double meanings in bash and utilities.
If you want your variable interpreted literally, use ' ' and not " "
In order to demonstrate the concept, try this exercise:
echo $PATH
echo "$PATH"
echo '$PATH'
echo Puppy Linux
echo " Puppy Linux "
echo ' "Puppy Linux" '
Between these two examples, you will get an idea of what I mean by a literal interpretation when you use ' ' instead of " "
~
Chapter 83 - A little more about variables
Global Variables - These variables are set for system wide use. Some of the variables we set and exported in profile.local are global variables.
You want to try and avoid giving your script the same names as the global variables unless that's what you want.
PATH is a particularly important global variable. One time on the forum the coder used PATH=with:his:values and the rest of the script didn't run. The script has precedence.
Most of the variables I've set, in this series, I've used quotes. Actually, you don't need to quote your variables if there aren't spaces.
EDITOR=mp (doesn't need quotes)
EDITOR="mp" (doesn't hurt or change the end result)
EDITOR='mp' (also doesn't hurt or change the end result)
However sometimes quotes are the last thing you should use in a variable. As you have learned, many characters have special or double meanings in bash and utilities.
If you want your variable interpreted literally, use ' ' and not " "
In order to demonstrate the concept, try this exercise:
echo $PATH
echo "$PATH"
echo '$PATH'
echo Puppy Linux
echo " Puppy Linux "
echo ' "Puppy Linux" '
Between these two examples, you will get an idea of what I mean by a literal interpretation when you use ' ' instead of " "
~
Chapter 83 - A little more about variables