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:28] – kauffman | nix:pathvars [2020/01/06 15:51] – kauffman | ||
---|---|---|---|
Line 36: | Line 36: | ||
</ | </ | ||
- | ==== Intro the the PATH variable ==== | + | ===== Intro the the PATH variable |
Generally your search path for binaries will look something like the below. | Generally your search path for binaries will look something like the below. | ||
Line 63: | Line 63: | ||
+ | ===== 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 to other shells, though the syntax may be different. | ||
+ | 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!' | ||
+ | < | ||
+ | #!/bin/bash | ||
+ | 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/ | ||
/var/lib/dokuwiki/data/pages/nix/pathvars.txt · Last modified: 2020/01/06 16:00 by kauffman