-->

Previous | Table of Contents | Next

Page 87

Features of the csh-Compatible Shell—tcsh

The tcsh shell, by William Joy (and 47 other contributors), features 53 built-in commands, and 18 command-line options. This shell emulates the csh shell, but has many more features, including a command-line editor with spelling correction.

This shell is not only compatible with the bash shell prompts, it offers more prompt options than bash. Tcsh uses the file csh.cshrc under the /etc/directory if the .tcshrc or .cshrc file does not exist in your home directory. Like the bash shell, you can scroll through commands you've entered and edit the command line.

Get a list of the tcsh commands by using the builtins command (the tcsh does not have help like the bash shell).


# builtins

:          @          alias      alloc      bg         bindkey    break

breaksw    builtins   case       cd         chdir      complete   continue

default    dirs       echo       echotc     else       end        endif

endsw      eval       exec       exit       fg         filetest   foreach

glob       goto       hashstat   history    hup        if         jobs

kill       limit      log        login      logout     ls-F       nice

nohup      notify     onintr     popd       printenv   pushd      rehash

repeat     sched      set        setenv     settc      setty      shift

source     stop       suspend    switch     telltc     time       umask

unalias    uncomplete unhash     unlimit    unset      unsetenv   wait

where      which      while

For more information about this shell, read the tcsh manual page, or look in the tcsh directory under the /usr/doc directory. You'll find a Frequently Asked Questions file and other text files.

zsh

The zsh shell, originally by Paul Falstad, is one of the largest shells for Linux, and features 84 built-in commands. The zsh shell has more than 50 different command-line options, and also emulates the sh and ksh shell commands.

Like the bash and tcsh shells, the zsh shell enables you to scroll through previous commands and complete, edit, or spell check the command line. It also enables you to use job control to manage running programs. This shell features advanced command-line options for searching or matching file patterns.

Systemwide startup files for this shell are in the /etc directory:


/etc/zlogin

/etc/zlogout

/etc/zprofile

/etc/zshenv

/etc/zshrc

Page 88

These files are parsed if the zsh shell cannot find equivalent files, but with a leading period, such as .zlogin, in your home directory. This shell also has more command-line prompt options than other shells, such as bash or tcsh. You'll find that this shell has features similar to all other shells, and can emulate the sh or ksh shells when called as a symbolic link (although your Red Hat Linux system has the sh shell linked to the bash shell).

There's a lot of information for this shell: 10 manual page files, along with a /usr/doc directory filled with help files, examples, and other up-to-date and useful information.

Understanding the Shell Command Line

When you use the shell to start a program at the command line, the shell interprets your command and the command echoes its output back to your screen. Using the shell, you can have the program's output sent elsewhere, such as to a file. The shell also can feed the program's input from another program or even another file. For example, you can redirect the standard output of the ls command to a file:


# touch /tmp/trash/file1 /tmp/trash/file2 /tmp/trash/file3 /tmp/trash/file4

# ls -w 1 /tmp/trash/* >trashfiles.txt

The first command line creates four files in the /tmp/trash directory. The second command line creates a text file, using the ls command's output, containing the names of the files under the /tmp/trash directory. The greater-than (>) character is called a standard output redirection operator, and is used to redirect the output of a command somewhere else. You also can use the less-than (<) character, or standard input redirection operator, to feed information to other programs. As a trivial example, you can use the file containing filenames created to build an archive using the cpio command. You can do this by using the standard input to feed the file names into the cpio command.


# cpio -o <trashfiles.txt >trash.cpio

1 block

This command line causes the cpio command to read a list of files from the standard input, the trashfiles.txt file, and then creates an archive by sending its output through the standard output to a file called trash.cpio.

Generally, most programs you run from the shell command line have the ability to read from the standard input and write to the standard output. Along with the standard input and standard output, there is also a standard error output (which almost always prints to your display). Using the previous example, if the list of files fed into the cpio command contains an error, the cpio command should complain, and send an error message to your screen:


# rm -fr /tmp/trash/file3

# cpio -o < trashfiles.txt >trash.cpio

cpio: /tmp/trash/file3: No such file or directory

Page 89


1 block

One of the existing files has been deleted, but the input file, trashfiles.txt, which still contains the list of files has not been changed. When you try to use the list as a valid input to build an archive, the cpio command complains and sends an error message to your screen (but still builds the archive).

Each input and output also has an assigned file number in your shell. For the standard input, the number is zero (0). For the standard output, the number is one (1), and for the standard error, the number is two (2). Knowing this, you can run cpio silently, and can cause any errors to be sent to a file. Do this by combining the standard output redirection operator and the standard error's file number, as shown in the following example.


# cpio -o < trashfiles.txt >trash.cpio 2>cpio.errors

# cat cpio.errors

cpio: /tmp/trash/file3: No such file or directory

1 block

As you can see, the cpio command sent its errors, which normally would be sent to the standard error output (your display), to a file called cpio.errors.

Normally, each time you redirect output to a file, either the named file is created, or if it exists, the named file is overwritten and its previous contents are irrevocably lost.

CAUTION
You should use file redirection carefully. If you redirect output to an existing file, you lose the original file, which may not be what you want.

If you'd like to retain the original contents of a file, you can append the output of a program to a file by using the concatenate (>>), or append redirection operator:


# cpio -o < trashfiles.txt >trash.cpio 2>>cpio.errors

This command line saves the previous contents of the cpio.errors file, and appends any new errors to the end of the file. This approach keeps a log of errors when you run the cpio command. This method is used if you've enabled system logging for Linux. Take a look at the contents of the file called messages, found under the /var/log directory.

If you recall the simple cat command text editor example from Hour 4, "Reading and Navigation Commands," you'll remember that the standard output redirection operator was used with the cat command to read input from the terminal to create a text file:


# cat >file.txt

this is a line

this is another line

EOF

# cat file.txt

Previous | Table of Contents | Next