Topics

Topics

The topics are formatted as minichapters, each with a few words of explanation about the relevant concepts and perhaps some examples followed by the relevant commands.

Command Line Options

Though the TC shell is generally invoked at login time without options, it is of course possible to call it from the command line. The following options can be used when invoking tcsh:

-b

Forces the shell to treat any remaining arguments in the argument list as nonoption arguments.

-ccommand

Tells the shell to treat the next argument as a command, store it in the command shell variable for reference, and execute it.

-d

This option is a way to force nonlogin shells to load the directory stack from ~/.cshdirs.

-Dname[=value]

Sets the environment variable name to the specified value.

-e

Tells the shell to exit if any command that it invokes terminates with a nonzero exit status.

-f

Starts the shell up faster by ignoring ~/.tcshrc.

-i

Forces the shell to run interactively, even if it does not recognize the device it is being run on as a terminal.

-l

The shell is a login shell.

-m

Tells tcsh to load ~/.tcshrc even if it isn't owned by the effective user.

-n

Debugging option tells the shell to parse commands but not execute them.

-q

Disables job control, but tells the shell to handle SIGQUIT.

-s

Tells tcsh to take commands from standard input.

-t

Tells the shell to read and execute a single line of input. Optionally, the line may be extened using a '\' to escape the newline character at the end of the line.

-v

Verbose execution. Command input is echoed after history substitution is performed.

-x

Commands are echoed immediately before execution.

-V

Sets the verbose shell variable even before executing ~/.tcshrc.

Startup and Shutdown

The most common means of invoking the tcsh shell is as a login shell. Specifically, after the login program validates a user's login name and password, it will invoke the user's preferred shell as specified in the rightmost entry of the /etc/passwd file:

shawkins:x:505:100:Scott Hawkins:/home/shawkins:/bin/tcsh

In addition to the command line options, the tc shell is designed to read from a variety of possible files at startup and shutdown. Exactly which files are read is a function of the files that are present and whether or not the shell is a login shell. The circumstances and order of file reads are specified next.

Login Shell File Sequence

Startup

1.       Execute systemwide startup files /etc/csh.cshrc and /etc/csh.login

2.       Execute command files in the user's home directory: first ~/.tcshrc or, if ~/.tcshrc does not exist, ~/.cshrc. Next read in the command history from the file specified by the histfile shell variable (~/.history by default). Finally, execute .login and read the directory stack from the file specified by the dirsfile shell variable (typically ~/.cshdirs).

Shutdown

1.       Execute commands from the file /etc/csh.logout

2.       Execute commands from the file ~/.logout

Nonlogin Shell File Sequence

Startup

1.       Read /etc/csh.cshrc

2.       Read ~/.tcshrc or ~/.cshrc

Shutdown

<none>

Logging out may be accomplished in a variety of ways. The quickest is to type ^D at the command line. The commands 'logout' and 'exit' will also work.

Command Line Editor

The command line editor can be set to function like either of the two most popular text editors (vi and Emacs). To tell tcsh to use vi-like command line editing, type

bindkey -v

Alternatively, you can set it to behave as if it were "Emacs-esque" by typing

bindkey -e

The bindkey command is a fairly handy feature of the tcsh shell. Note the distinction between shell built-ins such as "cd" and system executables such as "ls", "cat", or something else. The easiest way to tell if a command is a shell built-in or a system executable is to type 'which <command>'.

At any rate, you can also use the following bindkey command to display the possible editor commands:

bindkey -l

Or, if you prefer, just display the keys and their bindings by using

bindkey

Command Completion

To save typing, the tcsh offers a feature called command completion. The idea is that you type the first few letters of a command or command argument and press the <Tab> key, whereupon the shell will fill in whatever you didn't type. Sounds great, right? Well, I agree, but only in theory. In practice, however, I've found that what usually happens instead is that the shell beeps at you, indicating that you have not supplied enough information for it to narrow the choices down to one possibility. In such cases, you can get a list of the options that your shell is trying to choose from by typing <Ctrl>D. Here's an example:


shawkins@odin:~/ldr2e> ls t <Ctrl>D

t tcsh.fmt tcsh.bak

shawkins@odin:~/ldr2e> ls t

You can now scan the list of choices and provide more information to the shell, and then press tab again. Here's what it looks like:

shawkins@odin:~/ldr2e> ls tcsh.f<Tab>

The result is

shawkins@odin:~/ldr2e> ls tcsh.fmt

Or you could just type the command yourself. Pardon me if I seem less than enthusiastic there are a lot of people out there who swear by command completion, but I never really caught the hang of it.

Note also that command completion works anywhere in the line, not just at the end. Successfully pressing <Tab> in the middle of a line will shift any remaining text to the right. If the autolist shell variable is set, enter:

set autolist

the shell will display all the possibilities when it cannot uniquely complete a word, rather than just beeping at you.

The shell parses the input buffer to determine whether the word you want to complete should be completed as a filename, command, or variable. The first word in the buffer and the first word following ';', '|', '|&', '&&', or '||' is considered to be a command. A word begining with '$' is considered to be a variable. Anything else is a filename. For example,

complete [command [word//pattern//list[::select]//[[suffix]//] ]]

Without arguments, this command lists all possible completions. If provided an argument, this command lists only the completions possible for that argument.

Example:

c

Curent-word completion. pattern is a globpattern that must match the beginning of the current word on the command line. pattern is ignored when completing the current word.

C

Like c, but includes pattern when completing the current word.

n

Next-word completion. pattern is a globpattern that must match the beginning of the previous word on the command line.

N

Like n, but must match the begining of the word "two" before the current word.

p

Position-dependent completion. pattern is a numeric range, with the same syntax used to index shell variables, which must include the current word.

Uncomplete Pattern

Remove all completions whose names match pattern.

Example: To uncomplete all commands whose names match ls*, use

uncomplete ls*



Linux Desk Reference
Linux Desk Reference (2nd Edition)
ISBN: 0130619892
EAN: 2147483647
Year: 2000
Pages: 174
Authors: Scott Hawkins

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