Multiline Commands, Secondary Prompts
Both the Bourne shell and the C shell support multiline commands. In the Bourne shell, a newline following an open quote ('
or "
), a pipe symbol (|
), or a backslash () will not cause the command to be executed. Instead, you'll get a secondary prompt (from the PS2 environment variable, set to >
by default) and you can continue the command on the next line. For example, to send a quick write () message without making the other user wait for you to type the message:
$echo "We're leaving in 10 minutes. See you downstairs." |
>write joanne
In the C shell, you can continue a line by typing a backslash () before the newline (). You won't get the secondary prompt.
Obviously, this is a convenience if you're typing a long command line. It is a minor feature and one easily overlooked; however, it makes it much easier to use a program like sed () from the command line. For example, if you know you chronically make the typos "mvoe" (for "move") and "thier" (for "their"), you might be inspired to type the following command:
nroff lp |
$ |
---|
More importantly, the ability to issue multiline commands lets you use the shell's developing features interactively from the command line. In both the Bourne and the C shell, multiline developing constructs automatically generate a secondary prompt (>
in the Bourne shell, ?
in the C shell) until the construct is completed.
For example, here's a place to use my favorite developing construct for non-developers, the for loop ():
$for x in file1 file2 file3
>do
>sed 's/thier/their/g' $x > ,$x
>mv ,$x $x
>done
$
Or in the C shell with foreach ():
%foreach x (file1 file2 file3)
?sed 's/thier/their/g' $x > ,$x
?mv ,$x $x
?end
%
While a simple command like this could be saved into a shell script (), it is often even easier to use it interactively.
Users of sed should of course makesure their script works correctly before overwritingtheir original file . ()
- TOR