< Day Day Up > |
A pipe takes the output from the command on the left-hand side of the pipe symbol and sends it to the input of a command on the right-hand side of the pipe symbol. A pipeline can consist of more than one pipe. Example 11.64.1 $ who > tmp 2 $ wc l tmp 4 tmp 3 $ rm tmp 4 $ who wc -l # Using the pipe EXPLANATION The purpose of lines 1 through 3 is to count the number of people logged on ( who ), save the output of the command in a file ( tmp ), use the wc “l to count the number of lines in the tmp file ( wc “l ), and then remove the tmp file; that is, find the number of people logged on. The pipe performs the same task in one command.
Example 11.65.1 $ ls more < lists (ls) all files one page at a time (more) > 2 $ du ~ sort n sed n '$p' 72388 /home/jody/ellie 3 $ cat lp or cat lpr EXPLANATION
11.14.1 The here document and Redirecting InputA here document captures in-line input for programs such as mail , sort , and cat . Input is placed between two words or symbols. The first word is preceded by a UNIX command and the << symbol. The next lines consist of the input to be received by the command. The last line consists of a second word that exactly matches the first word. This word is called the final terminator and marks the end of input. It is used in the same way Ctrl-D is used to terminate input. There can be no spaces surrounding the final terminator. If the first word is preceded by the << “ , leading tabs (and only tabs) may precede the final terminator. Normally, a here document is used in shell scripts, rather than interactively. A good use for a here document is to create a menu in a script. FORMAT UNIX command << TERMINATOR lines of input input TERMINATOR Example 11.66.(The Command Line) 1 $ cat << FINISH 2 > Hello there $LOGNAME 3 > The time is $(date) > I can't wait to see you!!! 4 > FINISH 5 Hello there ellie The time is Sun May 30 19:42:16 PDT 2004 I can't wait to see you!! 6 $ EXPLANATION
Example 11.67.(From the .profile File) 1 print "Select a terminal type" 2 cat << EOF [1] sun [2] ansi [3] wyse50 3 EOF 4 read TERM ... EXPLANATION
Example 11.68.(The Command Line) 1 $ cat << DONE >Hello there >What's up? >Bye now The time is $(date). 2 > DONE 3 Hello there What's up? Bye now The time is Sun May 30 19:48:23 PDT 2004. EXPLANATION
|
< Day Day Up > |