13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

24Chapter 1An Embarrassment of Riches: The <strong>Linux</strong> Envir<strong>on</strong>mentThe most important shell variable to know is PATH. It defines the directoriesin the filesystem where the shell will look for programs to execute. Whenyou type a command like ls or javac the shell will look in all of the directoriesspecified in the PATH variable, in the order specified, until it finds theexecutable.$ echo $PATH/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:.$The PATH shown in the example has five directories, separated by col<strong>on</strong>s(“:”). (Note the fifth <strong>on</strong>e, the “.”; it says to look in the current directory.)Where do you suppose it will find cat? You can look for it yourself by searchingin each directory specified in PATH. Or you can use the which command:$ which cat/bin/cat$Some commands (like exit) d<strong>on</strong>’t show up, since they are built into theshell. Others may be aliases—but that opens a whole other topic that we aren’tcovering here. Just remember that each directory in the PATH variable is examinedfor the executable you want to run. If you get a command not found error,the command may be there, it just may not be <strong>on</strong> your PATH.To look at it the other way around: If you want to install a command sothat you can execute it from the command line, you can either always type itsfull pathname, or (a more user-friendly choice) you can set your PATH variableto include the locati<strong>on</strong> of the new command’s executable.So where and how do you set PATH? Whenever a shell is started up, it readssome initializati<strong>on</strong> files. These are shell scripts that are read and executed as ifthey were typed by the user—that is, not in a subshell. Am<strong>on</strong>g other acti<strong>on</strong>s,they often set values for variables like PATH. If you are using bash, look at.bashrc in your home directory.Shell scripts are just shell commands stored in a file so that you d<strong>on</strong>’t needto type the same commands and opti<strong>on</strong>s over and over. There are two ways torun a shell script. The easiest, often used when testing the script, is$ sh myscript

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!