100 Useful Command-Line Utilities

by Oliver; 2014

103. Bonus: Global Variables

To see all global variables, type:
$ set
Where bash looks for commands and scripts:
$PATH
Add a directory path to the back of the path:
$ PATH=$PATH:/my/new/path
Add a directory path to the front of the path:
$ PATH=/my/new/path:$PATH
Now we know where to put bash commands, but what about other programs? What if you've installed a package or a module in a local directory and you want the program to have access to it? In that case, the following global variables come into play.

Where matlab looks for commands and scripts:
$MATLABPATH
Where R looks for packages:
$R_LIBS
Where awk looks for commands and scripts:
$AWKPATH
Where Python looks for modules:
$PYTHONPATH
Where Cpp looks for libraries:
$LD_LIBRARY_PATH
Where Perl looks for modules:
$PERL5LIB
This will come into play when you've locally installed a module and have to make sure Perl sees it. Then you'll probably have to export it. E.g.:
$ export PERL5LIB=/some/path/lib64/perl5
Text editor:
$EDITOR
You can set this by typing, e.g.:
export EDITOR=/usr/bin/nano
Then Control-x-e will invoke the text editor.

The specially designated temporary directory:
$TMPDIR
A shell variable that stores a random number for you:
$RANDOM
For example:
$ echo $RANDOM
1284
$ echo $RANDOM
27837

<PREV   NEXT>