start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 7.2 Basics of Setting the Prompt Chapter 7
Setting Your Shell Prompt
Next: 7.4 Faster Prompt Setting with Built-Ins
 

7.3 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 been fixed in your C shell. The point Chris makes about speeding up your .cshrc still applies, though. -JP]

If you set prompt in your .cshrc file without carefully checking first whether or not prompt was already set (2.9), many versions of the C shell will cheerfully print prompts into the pipe vi uses to expand glob characters [ filename wildcards (*, ?, []) (1.16) and the tilde (~) (14.11) -JP ].

When you type :r abc*, vi opens a pipe to the C shell and 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 (2.9) like this:

if $?prompt 


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 in net.unix-wizards on Usenet, 22 April 1984


Previous: 7.2 Basics of Setting the Prompt UNIX Power ToolsNext: 7.4 Faster Prompt Setting with Built-Ins
7.2 Basics of Setting the Prompt Book Index7.4 Faster Prompt Setting with Built-Ins

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System