User Tools

Site Tools


nix:pathvars

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
nix:pathvars [2020/01/06 15:37]
kauffman
nix:pathvars [2020/01/06 15:51]
kauffman
Line 36: Line 36:
 </​code>​ </​code>​
  
-==== 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:
  
  
-===== Manipulating the PATH variable ​=====+===== 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. Your shell will allow you manipulate the order in which these paths appear. It's as simple as setting a variable.
Line 76: Line 76:
 </​code>​ </​code>​
  
-We will place our example script that echo's 'Hello World!'​ into ''​%%~/​bin/​hello%%'' ​and make it executable.+We will place our example script that echo's 'Hello World!'​ into ''​%%~/​bin/​hello%%''​
 <​code>​ <​code>​
 #!/bin/bash #!/bin/bash
Line 82: Line 82:
 </​code>​ </​code>​
  
 +and make it executable.
 <​code>​ <​code>​
-chmod +x ~/bin/hello+user@linux1:​~$ ​chmod +x ~/bin/hello
 </​code>​ </​code>​
  
 +Now that we have our executable ''​%%hello%%''​ we'd like to be able to call it without prepending the path like this: ''​%%~/​bin/​hello%%''​
 +
 +As you may have guessed we will want to add (pre or postpend) ''​%%~/​bin%%''​ to our ''​%%PATH%%''​ variable.
 +
 +===== Manipulating the PATH variable =====
 +
 +<​code>​
 +$ export PATH=$PATH:​~/​bin
 +</​code>​
 +
 +To test we will need the shell to reevaluate $PATH.
 +<​code>​
 +$ hash -r
 +</​code>​
 +
 +Now we can see that ''​%%hello%%''​ is in our path and we can execute it without the full path.
 +<​code>​
 +user@linux1:​~$ which hello 
 +/​home/​user/​bin/​hello
 +
 +user@linux1:​~$ hello
 +Hello World!
 +</​code>​
 +
 +===== Making the change permanent =====
 +Add the following line to a file called ''​%%~/​.bash_profile%%''​.
 +
 +   ​export PATH=$PATH:​$HOME/​bin
 +
 +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 ''​%%$PATH%%''​. Just make sure each path is separated by a colon ''​%%:​%%''​.
  
 +    export PATH=$HOME/​bin:​$PATH
  
/var/lib/dokuwiki/data/pages/nix/pathvars.txt · Last modified: 2020/01/06 16:00 by kauffman