Managing the Shell

The Bourne Again Shell (bash) is a user interface to the Linux operating system. You use bash commands to run programs, manage your files, and interact with your hardware through the Linux kernel. You can configure bash with a number of local and system-wide files and variables .

Shells such as bash are also known as command-line interpreters, which is a user interface that responds to specific commands, such as ls , cd , or cp . Shells also respond to programs or scripts that you create.

As you move around the command line, keep in mind that Linux is case sensitive. In other words, the ls command lists the files in your current directory, whereas the LS, Ls, or lS commands are meaningless in any current Linux shell.

Two ways the bash shell can help you are based on its history of previous commands and the ease with which you can complete a longer command. These characteristics are known as interactivity and command completion .

Interactivity

Interactivity allows you to run through previous commands. It also allows you to interact with current commands. You can use basic keys, such as the Home and arrow keys, to correct typos; alternatively, you can even use commands that you ve used in a text editor.

Interactivity and History

You can interact with a history of Linux commands. Open a command-line interface and type the history command. If you ve previously used the command-line interface, you ll see a result similar to that shown in Figure 8.1.

click to expand
Figure 8.1: A history of previous commands

By default, you can repeat previous commands in several ways. The easiest way is to use the Up and Down arrow keys on your keyboard. Go to your command-line interface. When you press the Up arrow key, you ll see the previous commands that you used, in reverse order. The list may even include commands that you used during previous sessions. You can reverse the process with the Down arrow key.

Alternatively, if you remember the first letter of a recent command, use an exclamation point ( ! ) to recall that earlier command. For example, based on the output of the history command shown in Figure 8.1, if you type !r the shell recalls the last time you used a command that started with the letter r ”in this case, redhat-config-xfree86 ”and runs that command.

This feature is flexible; you can add a bit more information, such as !rp . Based on the history shown in Figure 8.1, the shell would respond by running the rpm -q kernel-source command. The feature lets you go back quite a bit. If you type the env more command, you should find a HISTSIZE=1000 line, which means that you can go back and rerun any of the past 1000 commands.

Interactivity and Editors

You can also interact with the details of a current or a previous command. For example, take the following command, which includes a typographical error:

 # rpm -Vvh /mnt/cdrom/RedHat/RPMS/sendmail-* 

You realize that you should have typed the rpm -Uvh command, but you don t want to retype the entire command. Fortunately, you don t have to erase the entire command. You can use basic keys such as the Left and Right arrows and the Home key to move the cursor toward the beginning of the command.

Alternatively, you can use the commands that you know in a text editor. For example, if you want to set vi as the default command-line editor, run the following command:

 # set -o vi 
Note  

The set command is counterintuitive; while set -o editor enables that editor , set +o editor disables it. For this command, editor can be emacs or vi .

Now you can use vi editor commands. By default, you re in insert mode at the command-line interface. As we discussed in Chapter 06 , you can switch to command mode by pressing the Esc key. Then you can apply the vi commands of your choice to that line. Some useful vi commands not described in Chapter 06 are shown in Table 8.1.

Table 8.1: More vi Commands

Command

Description

Home

Moves to the beginning of a line

b

Moves left one word

w

Moves right one word

Remember, other vi commands are available as well, such as cw , which deletes the current word and starts insert mode.

Command Completion

The bash shell allows you to use the Tab key to complete commands. You need to type only part of a command. For example, to use the ypdomainname command to find the NIS domain name for your system, type the following letters :

 # ypd 

When you press the Tab key, bash completes the command for you. If there is more than one available command that starts with ypd , press the Tab key again, and you ll see a list of these commands.

 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net