When you type in a non-internal command on the command line, the UNIX shell looks for the executable file in your bin directory which is a sub-directory of your home directory. To get the programs there in the first place you can either copy them there with cp or move them there with mv:
To be able to run a program, you first have to make it an executable file as follows:
|chmod -x newprogram||designate the file as executable
|rehash||update the shell's hash table
When the shell starts up, it searches all the 'executable paths' for all the executable files on the system. It builds a list of all these executable files in what is called its hash table. The rehash command adds the new program to this table. The next time the shell starts up this new program will be put into the hash table automatically.
However, for this to work, there must be a path command in the .login file pointing to your own bin directory. If you are a new user, this might not have been done. To set a search path to your own bin directory, enter:
If you are using the Bourne or Korn shells, the path command is:
You must add this to the .profile file in the case of Borne & Korn.
Shell Script Arguments
If you create a horrendous command with lots of arguments, to save on typing each time you use it, you put it in a shell script - perhaps along with other horrendously complex commands. UNIX allows you to pass arguments to these horrendously complex commands from the shell script command itself as follows:
Suppose you have the command:
pr -f -2 file1 file2 file3 | lp
You can put this in a shell script called 2print in the form:
pr -f -2 $* | lp
Then you can perform the same thing by typing:
2print file1 file2 file3
The file name arguments file1 file2 and file3 are visible within the script file as $1, $2 and $3. The internal argument $* therefore refers to each of them in turn. The arguments do not have to be file names. Whatever they are, the first argument on the script's command line is visible to commands inside the script as $1, the second as $2 and the third as $3 and so on.
To Run Another User's Program
To run a program called prog1 in Ruby's bin directory, type:
|~ruby/bin/prog1||for the C-shell
|/home/ruby/bin/prog1||for the Borne or Korn shells
If you want to use this program a lot, you can make it appear to be in your directory under a different name. You use the link command ln from your home directory as follows:
ln ~ruby/bin/prog1 bin/ruby1
You can then run the program any time thereafter by typing:
If later, Ruby deletes her file prog1, her program ruby1 will still be in your directory.
To be able to set up such a link, both your stuff and Ruby's stuff must be on the same disk. If it is not, you can only set up a soft link adding the -s switch as follows:
ln -s ~ruby/bin/prog1 bin/ruby1
Everything works the same except that if Ruby deletes her program, you lose it too and the file name ruby1 points to limbo. You must delete the name using rm.
Using an Alias
You can create an short alias for a long command as follows:
|alias ruby1 '/home/ruby/bin/prog1'||C-shell
|alias ruby1='/home/ruby/bin/prog1'||Korn Shell
You can alias any command you like, eg:
alias sortnprint 'sort -r bigfile | pr -2 | lp'
To make alias commands permanent, you have to put them in the .login file or the .profile file.
Using a Shell Script
You can alternatively make a shell script called ruby1 in which you place the command line:
You then make it executable and add it to the hash table by typing:
chmod -x ruby1
You can then run Ruby's program by typing ruby1.
Getting Programs off The Internet
You can acquire programs from places on the Internet
Save the incoming email message in a file called something like received.shar.file.
Use a text editor to delete all lines up to the first line that begins with a #.
Feed the file to the shell by typing the command:
The shell then unbundles the shar file into one or more other files. Some may be normal text files. Some may be uuencoded binary files. A program will at this stage be a uuencoded file called something like ruby1.uu. It will begin something like:
begin 775 ruby1
To get the executable binary version that will run on your computer you must decode it by typing:
© 1998 Robert John Morton