Linux Unleashed, Third Edition:pdksh
-->
Previous
Table of Contents
Next
Wildcards
The pdksh shell makes entering commands easier by enabling the user to use wildcards. pdksh supports the same wildcards that bash does:
* matches any character and any number of characters.
? matches any single character.
[
] matches any single character contained within the brackets.
The * wildcard can be used in a way that is similar to command-line completion. For example, if the current directory contains the files
News/ bin/ games/ mail/ sample.text test/
and you want to edit the sample.text file by using the vi text editor, you can perform this task by using the following wildcard:
vi s*
The * matches any character (and any number of characters), so pdksh replaces s* with sample.text (the only file in the directory that matches the wildcard pattern).
This works reliably if there is only one file in the directory that begins with the letter s. If more than one file starts with the same letter, the shell tries to replace s* with the list of filenames that match the wildcard pattern and runs vi on the first file in this list. After you quit editing the first file, the second file in the list is loaded into vi, and so on for each file that matches the wildcard pattern. If you intend to edit more than one file, this is fine, but if you only want to edit the sample.text file, this command will not work the way you need it to.
A more practical situation in which to use the * wildcard is when you want to execute the same command on multiple files that have similar filenames. For example, assume that the current directory contains the following files:
News/ bin/ games/ mail/ sample.text
temp1.out
temp2.out temp3.out test/
If you want to delete all of the files with an .out extension, you can do it by entering the following command:
rm *.out
In this case, pdksh replaces *.out with the names of all of the files in the directory that match the wildcard pattern. After pdksh performs this substitution, the following command is processed:
rm temp1.out temp2.out temp3.out
The rm command is invoked with the arguments of temp1.out, temp2.out, and temp3.out.
The ? wildcard functions in a similar way to the * wildcard, except that the ? wildcard matches only a single character. Assuming the same directory contents as in the previous example, the ? wildcard can be used to delete all of the files with the .out extension by entering the following command:
rm temp?.out
The [
] wildcard enables you to specify characters or ranges of characters to match. To print all of the files in the previous example that have the .doc extension, enter one of the following two commands:
rm temp[123].out
rm temp[1-3].out
Command History
The pdksh shell supports a command history in much the same way as bash. The pdksh shell keeps track of the last HISTSIZE commands that have been entered (HISTSIZE is a user-definable pdksh variable).
pdksh stores the text of the last HISTSIZE commands in a history list. When you log in, the history list is initialized from a history file. The filename of the history file can be set using the HISTFILE pdksh variable. The default filename for the history file is .ksh_history which is located in your home directory. Notice that the file begins with a ., meaning that the file is hidden and appears in a directory listing only if you use the -a or -A option of the ls command.
The shell provides several ways of accessing the history list. The simplest way is to scroll through the commands that have been previously entered. In pdksh, this is done differently depending on whether you are using emacs or vi command editing.
If you are using emacs command editing, scroll up through the history list by pressing Ctrl+p and scroll down through the list by pressing Ctrl+n. If you are using vi command-line editing, scroll up through the history list by pressing either the k or - keys, and scroll down through the history list by pressing j or +.
Note: When using vi command editing, you must be in command mode for the key commands to work. You enter command mode by pressing the Esc key.
The command that is on the command line can be edited. The pdksh shell supports a complex set of editing capabilities (most of which are beyond the scope of this book). You can use the left- and right-arrow keys to move along the command line. You can insert text at any point and delete text from the command line by using the Backspace or Delete key. Most users should find these simple editing commands sufficient; for those who do not, there are many other more complicated ways of editing the command line.
Note: The complex set of editing commands that pdksh offers is similar to the commands contained in the emacs or vi text editors (you can set either emacs or vi emulation by using the set -o emacs or set -o vi commands). If you are familiar with emacs (or vi), these commands will be familiar to you.
Another method of using the history file is to display and edit it using fc (fix command), the built-in pdksh shell command. If you read Chapter 11, bash, you may remember that bash supports another command called history, which allows you to view and modify the history file. The history command was left out of the pdksh shell because all of its functionality could be provided by the fc command.
Tip: Even though the history command is not built in to pdksh, the command normally still works because it is usually set up as an alias to the fc -l command. For example, the .kshrc file usually contains a line such as alias history=fc -l, which provides behavior almost identical to the history command that is built in to other shells.
The fc command is used to edit the command history. It has a number of options, as is illustrated in the following command syntax:
fc [-e ename] [-nlr] [first] [last]
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
224 2282015 06 23 Dec nr 231 MON 12 Szczecińska DZ odznaka pamiątkowaTYT (231)TYT (228)223 22811 (231)Brother TC 228 CX17 15 2228,2,artykulSHSpec 228 6301C10 R2 12228 230228 GELBGMVCLC2U2BV5YTG6IAWG7JTEEY7EXDMPFJQwięcej podobnych podstron