nix:pathvars
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
nix:pathvars [2020/01/06 15:12] – a bit about PATH glk | nix:pathvars [2020/01/06 15:51] – kauffman | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PATH Variables ====== | ====== PATH Variables ====== | ||
- | I'm not sure how one first gets exposed to path variables, only that it can be confusing at first glance. This document tries to remedy that without going into the history of everything. | + | I'm not sure how one first gets exposed to path variables, only that it can be confusing at first glance. This document tries to remedy that without going into the history of **everything**. |
Line 22: | Line 22: | ||
* '' | * '' | ||
* '' | * '' | ||
- | |||
- | If you are aiming to use (command-line) programs that are not within one of these canonical '' | ||
- | To add new directories to your path, you need to add them to '' | + | ===== Path Search ===== |
+ | Ever wonder what happens when you type in a command ('' | ||
- | '' | + | Assuming the command is not a shell command, the shell will check the appropriate variable which includes search locations |
- | where ''/ | + | In our example, |
- | ... FINISH: can do this per-shell, but then doesn't persist | + | We can find out where it by using the command '' |
+ | < | ||
+ | user@linux1: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | ===== Intro the the PATH variable ===== | ||
+ | |||
+ | Generally your search path for binaries will look something like the below. | ||
+ | < | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | We can see what is in our path variable by using the command '' | ||
+ | |||
+ | < | ||
+ | user@linux1: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | When a search occurs it will take the left most path, search that directory, then proceed to the next path to its right IF and ONLY IF it does not find what it is looking for in the directory it is currently searching. | ||
+ | |||
+ | Fore example: Lets take a look at the executable | ||
+ | |||
+ | '' | ||
+ | < | ||
+ | user@linux1: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | There also exists and pip executable in '' | ||
+ | |||
+ | |||
+ | ===== Setting up an Example ===== | ||
+ | |||
+ | Your shell will allow you manipulate the order in which these paths appear. It's as simple as setting a variable. | ||
+ | |||
+ | For the following examples I assume you are using the bash shell, which is the default in CS. The concept will translate | ||
+ | |||
+ | A common example to manipulate your path is if you have written a script and you'd like to invoke it without providing the full path: | ||
+ | |||
+ | Lets create the directory '' | ||
+ | < | ||
+ | user@linux1: | ||
+ | </ | ||
+ | |||
+ | We will place our example script that echo's 'Hello World!' | ||
+ | < | ||
+ | # | ||
+ | echo 'Hello World!' | ||
+ | </ | ||
+ | |||
+ | and make it executable. | ||
+ | < | ||
+ | user@linux1: | ||
+ | </ | ||
+ | |||
+ | Now that we have our executable '' | ||
+ | |||
+ | As you may have guessed we will want to add (pre or postpend) '' | ||
+ | |||
+ | ===== Manipulating the PATH variable ===== | ||
+ | |||
+ | < | ||
+ | $ export PATH=$PATH: | ||
+ | </ | ||
+ | |||
+ | To test we will need the shell to reevaluate $PATH. | ||
+ | < | ||
+ | $ hash -r | ||
+ | </ | ||
+ | |||
+ | Now we can see that '' | ||
+ | < | ||
+ | user@linux1: | ||
+ | / | ||
+ | |||
+ | user@linux1: | ||
+ | Hello World! | ||
+ | </ | ||
+ | |||
+ | ===== Making the change permanent ===== | ||
+ | Add the following line to a file called '' | ||
+ | |||
+ | | ||
+ | |||
+ | This will postpend our custom path to the search path every time we launch a bash login shell. | ||
+ | |||
+ | If you'd like to prepend just move your path in front of '' | ||
+ | |||
+ | export PATH=$HOME/ | ||
- | ... thus, have to add setting '' |
/var/lib/dokuwiki/data/pages/nix/pathvars.txt · Last modified: 2020/01/06 16:00 by kauffman