Variables in the Shell
When a variable is first used you assign it a value with an equals sign like this:
myvariable="Hello"
When you want to access the variable, put a dollar sign in front of it:
echo $myvariable
Hello
There are also built-in variables like:
- $HOME
- $PATH
- $USER or $USERNAME
- $OSTYPE
- $LINES
- $SHELL
- $COLUMNS
For example, to find your home directory, you can type echo $HOME, or use it in a script. The following line will download the source code from the URL http://www.example.com/ and save it to the Desktop of the current user:
lynx -source "http://www.example.com/" > $HOME/Desktop/example.html