| Erik's linux page: Linux information for beginners and advanced users | ||
|---|---|---|
| Prev | Chapter 2. Some general words about Linux, mostly for new users. | Next |
Environment variables
Perhaps good to know is how bash handles environment variables. This is bash specific I know, but as I've said before, bash is the most common shell. I'd like to have information how other shells does.
What is an environment variable good for ?
It's a fast way of accessing some short configuration options from every program. It's easy to change during a session and is easy to view.. or something, well, they exist and it works quite well..
How do I set/unset an environment variable, and how do I view them ?
In bash, you use export <variable>="<value>" (example: export PATH="/bin:/usr/bin") to set a variable. To remove it completely you use unset <variable> . With printenv you can see all the variables.
What more or less important variables are there ?
There are a lot of them, some of the most common being
Table 2-2. Some environment variables
| Variable | Meaning |
| PS1 | Let's you decide how your prompt should behave |
| PATH | Defines the PATH (surprise ! :) ) |
| LOGNAME | Shows which user is logged in on the current terminal |
| HOSTNAME | Contains your hostname |
| PAGER | Contains the local pager, to view textfiles |
| $$ | Gives the Process ID of 'this' process. |
| $? | Gives the errorlevel of the last command. Useful in shell scripts |
| $0 | The name of the command executing right now, also useful in shell scripts |
| $1 | The first cmdline parameter to 'this' process. |
| $2 | The second... |