Environment Variables, $PATH and which command
Environment Variables
Environment variables store information. They're storage locations that are a name value pair, and all the letters in the variables are typically uppercase. You can see the content of the variable by using the echo $<VAR_NAME>
command. The most widely used environment variable is $PATH
, which contains a list of command search path.
$PATH
variable
$PATH
is an environment variable. It controls the command search path. It contains a list of directories that are separated by a colon. What I mean by that it controls the command search path is that, when you type in a command at the prompt and press Enter, that command will be searched in the directories that are listed in your path environment variable.
$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
In above example, /usr/local/bin will be searched first. If the command is found there, it will be executed. If not found, then /usr/bin will be searched. This process goes on and on until either the command is found in your path or you will be told it can't be found if it doesn't match your request.
which
command
If you want to know the location or the full path to the command that you are executing, use the which
command.
$ which cat /bin/cat
If there are multiple programes named cat, then the one that gets executed depends on your search path. If cat is in /usr/local/bin and also in /usr/bin, which ever directory occurs first in your path will be the cat command that gets executed.
Latest Post
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- Combine JavaScript and CSS
- Inline Small JavaScript and CSS
- Minify JavaScript and CSS
- Defer Parsing of JavaScript
- Prefer Async Script Loading
- Components, Bootstrap and DOM
- What is HEAD in git?
- Show the changes in Git.
- What is AngularJS 2?
- Confidence Interval for a Population Mean
- Accuracy vs. Precision
- Sampling Distribution
- Working with the Normal Distribution
- Standardized score - Z score
- Percentile
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync