Unix Power ToolsUnix Power ToolsSearch this book

4.5. C-Shell Prompt Causes Problems in vi, rsh, etc.

Stray prompts can cause trouble for many commands that start a noninteractive shell. This problem may have (and probably has) been fixed in your C shell, but some of the following tricks will speed up your .cshrc, so keep reading.

If you set prompt in your .cshrc file without carefully checking first whether prompt was already set (Section 4.1), many older versions of the C shell will cheerfully print prompts into the pipe vi uses to expand glob characters, such as filename wildcards (*, ?, [ ]) (Section 1.13) and the tilde (~) (Section 31.11).

When you type :r abc*, vi opens a pipe to the C shell, writes the command echo abc* down the pipe, then reads the response. If the response contains spaces or newlines, vi gets confused. If you set your prompt to (n) in your .cshrc [i.e., if you show the history number in parentheses as the prompt -- TOR], vi tends to get:

(1) abc.file (2)

back from the C shell, instead of just abc.file.

The solution is to kludge your .cshrc like this:

if ($?prompt) then
    # things to do for an interactive shell, like:
    set prompt='(\!) '
endif

This works because a noninteractive shell has no initial prompt, while an interactive shell has it set to % .

If you have a large .cshrc, this can speed things up quite a bit when programs run other programs with csh -c 'command', if you put all of it inside that test.

-- CT



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.