If you want to store a short piece of information where you can use it later, such as a directory path you don't want to keep typing over and over, you can put it in a Unix variable. This is not like a math variable, but just a little box you can put something in.
To put something into a variable, pick a name (capital letters are traditional) and type what you want to put there:
$ MYSTREET="123 Fourth Avenue" |
It is usually best to surround your information with double-quotes as shown above.
To get the value back out of the variable, put a dollar sign in front of the variable name, like this:
$ echo "$MYSTREET" |
Again, it is recommended to use double-quotes as illustrated. You can have other words inside the double-quotes if you want:
$ echo "I live at $MYSTREET in Phoenix." |
Here are some frequently-used Unix variables:
| Variable name | Discussion |
|---|---|
| HOME | Your personal storage space within the Unix shared disk drive. When you first log in, you will be in your "$HOME" directory. You can always return back to your "$HOME" by typing cd "$HOME" or as an additional shortcut, just type cd and Unix will assume you want to go HOME. |
| PATH | Lists all the directories where commands might be found. So if you type a command like godoit Unix might look first to find /usr/bin/godoit and if that doesn't exist, Unix might next look for /export/home4/msimkin/lib/godoit and if that exists, Unix will run that program. |
| PWD | Remembers your current working directory. |
| START | You have a separate working directory for the purposes of this GLG410 Unix class. After logging into Unix (which places you in your HOME directory) if you type /export/home4/msimkin/shared/setup the START variable will be created and you will be placed within your START directory. If you cd to somewhere else, you can get back by typing cd "$START". This is just a shortcut I made for your use during this class; you will (probably) not find START on other Unix systems you may use in the future (although you are free to make your own START on other Unix systems, if you want it). |
|
|
|