The shell gives you the option to set variables for PATH, HISTORY, etc.
The pathname is a string of text that indicates the location of a file or folder. There is a variable for this called PATH. As you'll see, this one makes your life a lot easier.
Lesson 8 / Lesson 10
If it weren't for the path variable, you'd have to type in a complete path--including all directories and subdirectories--for every command you enter on the command-line. So, if you wanted to use the "less" utility to look at the contents of "newtext.txt", you'd have to enter:
The path variable tells the shell to look in certain directories to find the executable files that make your programs and system utilities work. With the path variable set, you can abbreviate the above command to:
You can use the echo command to see how the path variable is set.
Note that there are several separate paths in this statement. Each path is separated from the next by a colon. You can invoke an executable in any one of these paths without having to enter the entire path on the command-line. But, what if you want to invoke an executable that's not in any of these paths?
You can invoke the command by entering the entire path, as we did in the above example with the less utility. Or, you can cd to the directory where the program executable is located, and prefix the command with a "./".
The "./" tells the shell to look in the current working directory for the program executable that's being invoked.
Note: In the DOS/Windows world, the current working directory is an implied part of the path variable. So, if you're in the directory where the program executable that you want to invoke is stored, you don't need to prefix the command with anything. In the Linux world, the current working directory isn't implied as part of the path variable, so you need to implicitly tell the system to look there when you want to invoke a program. This was purposely set up this way for security reasons.
Finally, you can use the export command to add a new path to the path variable:
Note how the new path is added at the end of the path statement.
When a command is executed without a path, the shell searches the PATH variable to locate it. When it is found it places that in a hash table. After that Bash checks the hash table first.
There are several other environment variables that may be set on your system. One of the important aspects of the environment is that when the parent process spawns a child, the child and any applications that start from the child process will inherit the environment from the parent.
You can see what all of them are by issuing the "env" command.
Or, use the echo command if you just want to see the value of one variable. (It'll work the same way as it did in the previous examples.)
Here's a table of some of the more common environment variables.
The username of the person who is currently logged on to the system.
The path to the shell that is currently in use.
The current working directory.
This is the TCP/IP hostname of the computer.
A colon-delimited list of directories in which the system looks when you type an executable program name. This variable gets built in several configuration files, such as /etc/profile and the .bashrc file that resides in the user's home directory.
This holds the path for the current user's home directory. Some programs will use this variable to determine where to find configuration files or determine the default location to store files.
It works like the path variable. Some programs will use it to help find their library files.
The default bash prompt.
Some newsreader programs may use this variable to set the name of the news server.
This specifies the current terminal type. You'll probably see it set as "xterm". The system needs to know which terminal type is in use so that it will know how to move the cursor and display text effects in text-mode programs.
This variable allows you to have multiple displays running from the same computer. If you're only running one display, you'll see a returned value of ":0.0". (That means, the first display on the current computer.)
This sets the default text editor that you want to use. You have several choices, but for best results, always set it to use a text-mode editor. Some good choices would be vi, joe, or emacs.
The history Command
The history command remembers the last 1000 commands that you have performed at the command line. The value of the history command is that you can go back and review a command that you used in case you do not remember or you can see where you made a mistake.
558 ls /usr/sbin
560 su - diane
561 ls /usr/sbin
564 finger tom
565 ifdown eth0
566 ap-get update
567 apt-get update
The history is listed from the last 1000 commands (500 for Ubuntu) starting with the furthest back as number 1 and the most recent as number 1000. If you have not run 1000 commands you will see that it will list the number that you have used.
If you pipe the history command to the command less you may scroll backwards and forwards by using the arrow keys. The | symbol pipes the output of one command into another.
history | less
This history is kept in the hidden file .bash_history in your home directory. There are several configurable variables that you may want to adjust.
HISTCMD history number of current command
HISTFILE history command saves data here ~/.bash_history
HISTFILESIZE max number of lines stored in history
HISTSIZE max number of commands to remember in history
View these variables by using the echo command:
You may change the history file size with this command:
That would change the history file size to 1200 instead of 500.
You can also review your past commands using the up and down arrow keys on your keyboard to call-up previously entered commands. If you keep pressing the up arrow key, you'll scroll through the list of previous commands, starting with the last one entered. If you go past the command that you want, you can use the down arrow key to get back to it. When you finally do get to the command that you want to repeat, you can either press the Enter key to enter it as is, or edit it and then press Enter.
Copyright CyberMontana Inc. and BeginLinux.com
All rights reserved. Cannot be reproduced without written permission. Box 1262 Trout Creek, MT 59874