Debian Codegraph @

HTML/special-chars.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Special Characters</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
9 "><LINK
10 REL="HOME"
11 TITLE="Advanced Bash-Scripting Guide"
12 HREF="index.html"><LINK
13 REL="UP"
14 TITLE="Basics"
15 HREF="part2.html"><LINK
16 REL="PREVIOUS"
17 TITLE="Basics"
18 HREF="part2.html"><LINK
19 REL="NEXT"
20 TITLE="Introduction to Variables and Parameters"
21 HREF="variables.html"><META
22 HTTP-EQUIV="Content-Style-Type"
23 CONTENT="text/css"><LINK
24 REL="stylesheet"
25 HREF="common/kde-common.css"
26 TYPE="text/css"><META
27 HTTP-EQUIV="Content-Type"
28 CONTENT="text/html; charset=iso-8859-1"><META
29 HTTP-EQUIV="Content-Language"
30 CONTENT="en"><LINK
31 REL="stylesheet"
32 HREF="common/kde-localised.css"
33 TYPE="text/css"
34 TITLE="KDE-English"><LINK
35 REL="stylesheet"
36 HREF="common/kde-default.css"
37 TYPE="text/css"
38 TITLE="KDE-Default"></HEAD
39 ><BODY
40 CLASS="CHAPTER"
41 BGCOLOR="#FFFFFF"
42 TEXT="#000000"
43 LINK="#AA0000"
44 VLINK="#AA0055"
45 ALINK="#AA0000"
46 STYLE="font-family: sans-serif;"
47 ><DIV
48 CLASS="NAVHEADER"
49 ><TABLE
50 SUMMARY="Header navigation table"
51 WIDTH="100%"
52 BORDER="0"
53 CELLPADDING="0"
54 CELLSPACING="0"
55 ><TR
56 ><TH
57 COLSPAN="3"
58 ALIGN="center"
59 >Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
60 ></TR
61 ><TR
62 ><TD
63 WIDTH="10%"
64 ALIGN="left"
65 VALIGN="bottom"
66 ><A
67 HREF="part2.html"
68 ACCESSKEY="P"
69 >Prev</A
70 ></TD
71 ><TD
72 WIDTH="80%"
73 ALIGN="center"
74 VALIGN="bottom"
75 ></TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="bottom"
80 ><A
81 HREF="variables.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="CHAPTER"
92 ><H1
93 ><A
94 NAME="SPECIAL-CHARS"
95 ></A
96 >Chapter 3. Special Characters</H1
97 ><P
98 >What makes a character <I
99 CLASS="FIRSTTERM"
100 >special</I
101 >?
102 If it has a meaning beyond its
103 <I
104 CLASS="FIRSTTERM"
105 >literal meaning</I
106 >, a <A
107 HREF="regexp.html#METAMEANINGREF"
108 >meta-meaning</A
109 >, then we refer
110 to it as a <I
111 CLASS="FIRSTTERM"
112 >special character</I
113 >. Along
114 with commands and <A
115 HREF="internal.html#KEYWORDREF"
116 >keywords</A
117 >,
118 <I
119 CLASS="FIRSTTERM"
120 >special characters</I
121 > are building blocks
122 of Bash scripts.</P
123 ><DIV
124 CLASS="VARIABLELIST"
125 ><P
126 ><B
127 ><A
128 NAME="SCHARLIST1"
129 ></A
130 >Special Characters Found In
131 Scripts and Elsewhere</B
132 ></P
133 ><DL
134 ><DT
135 ><A
136 NAME="HASHMARKREF"
137 ></A
138 ><SPAN
139 CLASS="TOKEN"
140 >#</SPAN
141 ></DT
142 ><DD
143 ><DIV
144 CLASS="FORMALPARA"
145 ><P
146 ><B
147 >Comments. </B
148 >Lines beginning with a <SPAN
149 CLASS="TOKEN"
150 >#</SPAN
151 >
152 (with the exception of <A
153 HREF="sha-bang.html#MAGNUMREF"
154 > <SPAN
155 CLASS="TOKEN"
156 >#!</SPAN
157 ></A
158 >) are comments and will
159 <SPAN
160 CLASS="emphasis"
161 ><I
162 CLASS="EMPHASIS"
163 >not</I
164 ></SPAN
165 > be executed.</P
166 ></DIV
167 ><P
168 ><TABLE
169 BORDER="0"
170 BGCOLOR="#E0E0E0"
171 WIDTH="90%"
172 ><TR
173 ><TD
174 ><PRE
175 CLASS="PROGRAMLISTING"
176 > 1&nbsp;# This line is a comment.</PRE
177 ></TD
178 ></TR
179 ></TABLE
180 ></P
181 ><P
182 >Comments may also occur following the end of a command.</P
183 ><P
184 ><TABLE
185 BORDER="0"
186 BGCOLOR="#E0E0E0"
187 WIDTH="90%"
188 ><TR
189 ><TD
190 ><PRE
191 CLASS="PROGRAMLISTING"
192 > 1&nbsp;echo "A comment will follow." # Comment here.
193 2&nbsp;# ^ Note whitespace before #</PRE
194 ></TD
195 ></TR
196 ></TABLE
197 ></P
198 ><P
199 ><A
200 NAME="WSBCOMM"
201 ></A
202 > Comments may also follow <A
203 HREF="special-chars.html#WHITESPACEREF"
204 >whitespace</A
205 > at the beginning
206 of a line.</P
207 ><P
208 > <TABLE
209 BORDER="0"
210 BGCOLOR="#E0E0E0"
211 WIDTH="90%"
212 ><TR
213 ><TD
214 ><PRE
215 CLASS="PROGRAMLISTING"
216 > 1&nbsp; # A tab precedes this comment.</PRE
217 ></TD
218 ></TR
219 ></TABLE
220 >
221 </P
222 ><P
223 ><A
224 NAME="COMMINPIPE"
225 ></A
226 >Comments may even be embedded
227 within a <A
228 HREF="special-chars.html#PIPEREF"
229 >pipe</A
230 >.</P
231 ><P
232 ><TABLE
233 BORDER="0"
234 BGCOLOR="#E0E0E0"
235 WIDTH="90%"
236 ><TR
237 ><TD
238 ><PRE
239 CLASS="PROGRAMLISTING"
240 > 1&nbsp;initial=( `cat "$startfile" | sed -e '/#/d' | tr -d '\n' |\
241 2&nbsp;# Delete lines containing '#' comment character.
242 3&nbsp; sed -e 's/\./\. /g' -e 's/_/_ /g'` )
243 4&nbsp;# Excerpted from life.sh script</PRE
244 ></TD
245 ></TR
246 ></TABLE
247 >
248 </P
249 ><DIV
250 CLASS="CAUTION"
251 ><TABLE
252 CLASS="CAUTION"
253 WIDTH="90%"
254 BORDER="0"
255 ><TR
256 ><TD
257 WIDTH="25"
258 ALIGN="CENTER"
259 VALIGN="TOP"
260 ><IMG
261 SRC="common/caution.png"
262 HSPACE="5"
263 ALT="Caution"></TD
264 ><TD
265 ALIGN="LEFT"
266 VALIGN="TOP"
267 ><P
268 >A command may not follow a comment on the
269 same line. There is no method of terminating the comment,
270 in order for <SPAN
271 CLASS="QUOTE"
272 >"live code"</SPAN
273 > to begin on the same
274 line. Use a new line for the next command.</P
275 ></TD
276 ></TR
277 ></TABLE
278 ></DIV
279 ><DIV
280 CLASS="NOTE"
281 ><TABLE
282 CLASS="NOTE"
283 WIDTH="90%"
284 BORDER="0"
285 ><TR
286 ><TD
287 WIDTH="25"
288 ALIGN="CENTER"
289 VALIGN="TOP"
290 ><IMG
291 SRC="common/note.png"
292 HSPACE="5"
293 ALT="Note"></TD
294 ><TD
295 ALIGN="LEFT"
296 VALIGN="TOP"
297 ><P
298 >Of course, a <A
299 HREF="quoting.html#QUOTINGREF"
300 >quoted</A
301 >
302 or an <A
303 HREF="escapingsection.html#ESCP"
304 >escaped</A
305 > <SPAN
306 CLASS="TOKEN"
307 >#</SPAN
308 >
309 in an <A
310 HREF="internal.html#ECHOREF"
311 >echo</A
312 > statement does
313 <SPAN
314 CLASS="emphasis"
315 ><I
316 CLASS="EMPHASIS"
317 >not</I
318 ></SPAN
319 > begin a comment. Likewise, a
320 <SPAN
321 CLASS="TOKEN"
322 >#</SPAN
323 > appears in <A
324 HREF="parameter-substitution.html#PSUB2"
325 >certain
326 parameter-substitution constructs</A
327 > and in <A
328 HREF="numerical-constants.html#NUMCONSTANTS"
329 > numerical constant expressions</A
330 >.
331
332 <TABLE
333 BORDER="0"
334 BGCOLOR="#E0E0E0"
335 WIDTH="90%"
336 ><TR
337 ><TD
338 ><PRE
339 CLASS="PROGRAMLISTING"
340 > 1&nbsp;echo "The # here does not begin a comment."
341 2&nbsp;echo 'The # here does not begin a comment.'
342 3&nbsp;echo The \# here does not begin a comment.
343 4&nbsp;echo The # here begins a comment.
344 5&nbsp;
345 6&nbsp;echo ${PATH#*:} # Parameter substitution, not a comment.
346 7&nbsp;echo $(( 2#101011 )) # Base conversion, not a comment.
347 8&nbsp;
348 9&nbsp;# Thanks, S.C.</PRE
349 ></TD
350 ></TR
351 ></TABLE
352 >
353
354 The standard <A
355 HREF="quoting.html#QUOTINGREF"
356 >quoting and
357 escape</A
358 > characters (" ' \) escape the #.
359 </P
360 ></TD
361 ></TR
362 ></TABLE
363 ></DIV
364 ><P
365 >Certain <A
366 HREF="parameter-substitution.html#PSOREX1"
367 >pattern matching
368 operations</A
369 > also use the <SPAN
370 CLASS="TOKEN"
371 >#</SPAN
372 >.</P
373 ></DD
374 ><DT
375 ><A
376 NAME="SEMICOLONREF"
377 ></A
378 ><SPAN
379 CLASS="TOKEN"
380 >;</SPAN
381 ></DT
382 ><DD
383 ><DIV
384 CLASS="FORMALPARA"
385 ><P
386 ><B
387 >Command separator [semicolon]. </B
388 >Permits putting two or more commands on the same
389 line.</P
390 ></DIV
391 ><P
392 > <TABLE
393 BORDER="0"
394 BGCOLOR="#E0E0E0"
395 WIDTH="90%"
396 ><TR
397 ><TD
398 ><PRE
399 CLASS="PROGRAMLISTING"
400 > 1&nbsp;echo hello; echo there
401 2&nbsp;
402 3&nbsp;
403 4&nbsp;if [ -x "$filename" ]; then # Note the space after the semicolon.
404 5&nbsp;#+ ^^
405 6&nbsp; echo "File $filename exists."; cp $filename $filename.bak
406 7&nbsp;else # ^^
407 8&nbsp; echo "File $filename not found."; touch $filename
408 9&nbsp;fi; echo "File test complete."</PRE
409 ></TD
410 ></TR
411 ></TABLE
412 ></P
413 ><P
414 >Note that the <SPAN
415 CLASS="QUOTE"
416 >"<SPAN
417 CLASS="TOKEN"
418 >;</SPAN
419 >"</SPAN
420 >
421 <A
422 HREF="moreadv.html#FINDREF0"
423 >sometimes needs to be
424 <I
425 CLASS="FIRSTTERM"
426 >escaped</I
427 ></A
428 >.</P
429 ></DD
430 ><DT
431 ><SPAN
432 CLASS="TOKEN"
433 >;;</SPAN
434 ></DT
435 ><DD
436 ><DIV
437 CLASS="FORMALPARA"
438 ><P
439 ><B
440 >Terminator in a <A
441 HREF="testbranch.html#CASEESAC1"
442 >case</A
443 > option [double semicolon]. </B
444 ><A
445 NAME="DOUBLESEMICOLON"
446 ></A
447 ></P
448 ></DIV
449 ><P
450 ><TABLE
451 BORDER="0"
452 BGCOLOR="#E0E0E0"
453 WIDTH="90%"
454 ><TR
455 ><TD
456 ><PRE
457 CLASS="PROGRAMLISTING"
458 > 1&nbsp;case "$variable" in
459 2&nbsp; abc) echo "\$variable = abc" ;;
460 3&nbsp; xyz) echo "\$variable = xyz" ;;
461 4&nbsp;esac</PRE
462 ></TD
463 ></TR
464 ></TABLE
465 ></P
466 ></DD
467 ><DT
468 ><SPAN
469 CLASS="TOKEN"
470 >;;&#38;</SPAN
471 >, <SPAN
472 CLASS="TOKEN"
473 >;&#38;</SPAN
474 ></DT
475 ><DD
476 ><DIV
477 CLASS="FORMALPARA"
478 ><P
479 ><B
480 ><A
481 HREF="bashver4.html#NCTERM"
482 >Terminators</A
483 >
484 in a <I
485 CLASS="FIRSTTERM"
486 >case</I
487 > option (<A
488 HREF="bashver4.html#BASH4REF"
489 >version 4+</A
490 > of Bash). </B
491 ></P
492 ></DIV
493 ></DD
494 ><DT
495 ><SPAN
496 CLASS="TOKEN"
497 >.</SPAN
498 ></DT
499 ><DD
500 ><P
501 ><A
502 NAME="DOTREF"
503 ></A
504 ></P
505 ><DIV
506 CLASS="FORMALPARA"
507 ><P
508 ><B
509 ><SPAN
510 CLASS="QUOTE"
511 >"dot"</SPAN
512 > command [period]. </B
513 >Equivalent to <A
514 HREF="internal.html#SOURCEREF"
515 >source</A
516 > (see
517 <A
518 HREF="internal.html#EX38"
519 >Example 15-22</A
520 >). This is a bash <A
521 HREF="internal.html#BUILTINREF"
522 >builtin</A
523 >.</P
524 ></DIV
525 ></DD
526 ><DT
527 ><SPAN
528 CLASS="TOKEN"
529 >.</SPAN
530 ></DT
531 ><DD
532 ><DIV
533 CLASS="FORMALPARA"
534 ><P
535 ><B
536 ><SPAN
537 CLASS="QUOTE"
538 >"dot"</SPAN
539 >, as a component of a filename. </B
540 >When working with filenames, a leading dot is the prefix
541 of a <SPAN
542 CLASS="QUOTE"
543 >"hidden"</SPAN
544 > file, a file that an
545 <A
546 HREF="external.html#LSREF"
547 >ls</A
548 > will not normally show.
549 <TABLE
550 BORDER="0"
551 BGCOLOR="#E0E0E0"
552 WIDTH="90%"
553 ><TR
554 ><TD
555 ><PRE
556 CLASS="SCREEN"
557 > <TT
558 CLASS="PROMPT"
559 >bash$ </TT
560 ><TT
561 CLASS="USERINPUT"
562 ><B
563 >touch .hidden-file</B
564 ></TT
565 >
566 <TT
567 CLASS="PROMPT"
568 >bash$ </TT
569 ><TT
570 CLASS="USERINPUT"
571 ><B
572 >ls -l</B
573 ></TT
574 >
575 <TT
576 CLASS="COMPUTEROUTPUT"
577 >total 10
578 -rw-r--r-- 1 bozo 4034 Jul 18 22:04 data1.addressbook
579 -rw-r--r-- 1 bozo 4602 May 25 13:58 data1.addressbook.bak
580 -rw-r--r-- 1 bozo 877 Dec 17 2000 employment.addressbook</TT
581 >
582
583
584 <TT
585 CLASS="PROMPT"
586 >bash$ </TT
587 ><TT
588 CLASS="USERINPUT"
589 ><B
590 >ls -al</B
591 ></TT
592 >
593 <TT
594 CLASS="COMPUTEROUTPUT"
595 >total 14
596 drwxrwxr-x 2 bozo bozo 1024 Aug 29 20:54 ./
597 drwx------ 52 bozo bozo 3072 Aug 29 20:51 ../
598 -rw-r--r-- 1 bozo bozo 4034 Jul 18 22:04 data1.addressbook
599 -rw-r--r-- 1 bozo bozo 4602 May 25 13:58 data1.addressbook.bak
600 -rw-r--r-- 1 bozo bozo 877 Dec 17 2000 employment.addressbook
601 -rw-rw-r-- 1 bozo bozo 0 Aug 29 20:54 .hidden-file</TT
602 >
603 </PRE
604 ></TD
605 ></TR
606 ></TABLE
607 >
608 </P
609 ></DIV
610 ><P
611 ><A
612 NAME="DOTDIRECTORY"
613 ></A
614 ></P
615 ><P
616 >When considering directory names, <I
617 CLASS="FIRSTTERM"
618 >a single
619 dot</I
620 > represents the current working directory,
621 and <I
622 CLASS="FIRSTTERM"
623 >two dots</I
624 > denote the parent
625 directory.</P
626 ><P
627 > <TABLE
628 BORDER="0"
629 BGCOLOR="#E0E0E0"
630 WIDTH="90%"
631 ><TR
632 ><TD
633 ><PRE
634 CLASS="SCREEN"
635 > <TT
636 CLASS="PROMPT"
637 >bash$ </TT
638 ><TT
639 CLASS="USERINPUT"
640 ><B
641 >pwd</B
642 ></TT
643 >
644 <TT
645 CLASS="COMPUTEROUTPUT"
646 >/home/bozo/projects</TT
647 >
648
649 <TT
650 CLASS="PROMPT"
651 >bash$ </TT
652 ><TT
653 CLASS="USERINPUT"
654 ><B
655 >cd .</B
656 ></TT
657 >
658 <TT
659 CLASS="PROMPT"
660 >bash$ </TT
661 ><TT
662 CLASS="USERINPUT"
663 ><B
664 >pwd</B
665 ></TT
666 >
667 <TT
668 CLASS="COMPUTEROUTPUT"
669 >/home/bozo/projects</TT
670 >
671
672 <TT
673 CLASS="PROMPT"
674 >bash$ </TT
675 ><TT
676 CLASS="USERINPUT"
677 ><B
678 >cd ..</B
679 ></TT
680 >
681 <TT
682 CLASS="PROMPT"
683 >bash$ </TT
684 ><TT
685 CLASS="USERINPUT"
686 ><B
687 >pwd</B
688 ></TT
689 >
690 <TT
691 CLASS="COMPUTEROUTPUT"
692 >/home/bozo/</TT
693 >
694 </PRE
695 ></TD
696 ></TR
697 ></TABLE
698 >
699 </P
700 ><P
701 >The <I
702 CLASS="FIRSTTERM"
703 >dot</I
704 > often appears as the
705 destination (directory) of a file movement command,
706 in this context meaning <I
707 CLASS="FIRSTTERM"
708 >current
709 directory</I
710 >.</P
711 ><P
712 > <TABLE
713 BORDER="0"
714 BGCOLOR="#E0E0E0"
715 WIDTH="90%"
716 ><TR
717 ><TD
718 ><PRE
719 CLASS="SCREEN"
720 > <TT
721 CLASS="PROMPT"
722 >bash$ </TT
723 ><TT
724 CLASS="USERINPUT"
725 ><B
726 >cp /home/bozo/current_work/junk/* .</B
727 ></TT
728 >
729 </PRE
730 ></TD
731 ></TR
732 ></TABLE
733 >
734 Copy all the <SPAN
735 CLASS="QUOTE"
736 >"junk"</SPAN
737 > files to
738 <A
739 HREF="variables2.html#PWDREF"
740 >$PWD</A
741 >.</P
742 ></DD
743 ><DT
744 ><SPAN
745 CLASS="TOKEN"
746 >.</SPAN
747 ></DT
748 ><DD
749 ><DIV
750 CLASS="FORMALPARA"
751 ><P
752 ><B
753 ><SPAN
754 CLASS="QUOTE"
755 >"dot"</SPAN
756 > character match. </B
757 >When <A
758 HREF="regexp.html#REGEXDOT"
759 >matching
760 characters</A
761 >, as part of a <A
762 HREF="regexp.html#REGEXREF"
763 >regular expression</A
764 >, a
765 <SPAN
766 CLASS="QUOTE"
767 >"dot"</SPAN
768 > <A
769 HREF="regexp.html#REGEXDOT"
770 >matches a
771 single character</A
772 >.</P
773 ></DIV
774 ></DD
775 ><DT
776 ><SPAN
777 CLASS="TOKEN"
778 >"</SPAN
779 ></DT
780 ><DD
781 ><DIV
782 CLASS="FORMALPARA"
783 ><P
784 ><B
785 ><A
786 HREF="variables.html#DBLQUO"
787 >partial
788 quoting</A
789 > [double quote]. </B
790 ><SPAN
791 CLASS="emphasis"
792 ><I
793 CLASS="EMPHASIS"
794 >"STRING"</I
795 ></SPAN
796 > preserves (from
797 interpretation) most of the special characters within
798 <SPAN
799 CLASS="emphasis"
800 ><I
801 CLASS="EMPHASIS"
802 >STRING</I
803 ></SPAN
804 >. See <A
805 HREF="quoting.html"
806 >Chapter 5</A
807 >.</P
808 ></DIV
809 ></DD
810 ><DT
811 ><SPAN
812 CLASS="TOKEN"
813 >'</SPAN
814 ></DT
815 ><DD
816 ><DIV
817 CLASS="FORMALPARA"
818 ><P
819 ><B
820 ><A
821 HREF="variables.html#SNGLQUO"
822 >full
823 quoting</A
824 > [single quote]. </B
825 ><SPAN
826 CLASS="emphasis"
827 ><I
828 CLASS="EMPHASIS"
829 >'STRING'</I
830 ></SPAN
831 > preserves all special
832 characters within <SPAN
833 CLASS="emphasis"
834 ><I
835 CLASS="EMPHASIS"
836 >STRING</I
837 ></SPAN
838 >. This is a
839 stronger form of quoting than <SPAN
840 CLASS="emphasis"
841 ><I
842 CLASS="EMPHASIS"
843 >"STRING"</I
844 ></SPAN
845 >.
846 See <A
847 HREF="quoting.html"
848 >Chapter 5</A
849 >.</P
850 ></DIV
851 ></DD
852 ><DT
853 ><SPAN
854 CLASS="TOKEN"
855 >,</SPAN
856 ></DT
857 ><DD
858 ><DIV
859 CLASS="FORMALPARA"
860 ><P
861 ><B
862 ><A
863 HREF="operations.html#COMMAOP"
864 >comma
865 operator</A
866 >. </B
867 >The <I
868 CLASS="FIRSTTERM"
869 >comma operator</I
870 >
871
872 <A
873 NAME="AEN612"
874 HREF="#FTN.AEN612"
875 >[1]</A
876 >
877
878 links together a
879 series of arithmetic operations. All are evaluated,
880 but only the last one is returned.
881 <TABLE
882 BORDER="0"
883 BGCOLOR="#E0E0E0"
884 WIDTH="90%"
885 ><TR
886 ><TD
887 ><PRE
888 CLASS="PROGRAMLISTING"
889 > 1&nbsp;let "t2 = ((a = 9, 15 / 3))"
890 2&nbsp;# Set "a = 9" and "t2 = 15 / 3"</PRE
891 ></TD
892 ></TR
893 ></TABLE
894 >
895 </P
896 ></DIV
897 ><P
898 ><A
899 NAME="COMMAOP2"
900 ></A
901 >The <I
902 CLASS="FIRSTTERM"
903 >comma</I
904 >
905 operator can also concatenate strings.
906 <TABLE
907 BORDER="0"
908 BGCOLOR="#E0E0E0"
909 WIDTH="90%"
910 ><TR
911 ><TD
912 ><PRE
913 CLASS="PROGRAMLISTING"
914 > 1&nbsp;for file in /{,usr/}bin/*calc
915 2&nbsp;# ^ Find all executable files ending in "calc"
916 3&nbsp;#+ in /bin and /usr/bin directories.
917 4&nbsp;do
918 5&nbsp; if [ -x "$file" ]
919 6&nbsp; then
920 7&nbsp; echo $file
921 8&nbsp; fi
922 9&nbsp;done
923 10&nbsp;
924 11&nbsp;# /bin/ipcalc
925 12&nbsp;# /usr/bin/kcalc
926 13&nbsp;# /usr/bin/oidcalc
927 14&nbsp;# /usr/bin/oocalc
928 15&nbsp;
929 16&nbsp;
930 17&nbsp;# Thank you, Rory Winston, for pointing this out.</PRE
931 ></TD
932 ></TR
933 ></TABLE
934 >
935 </P
936 ></DD
937 ><DT
938 ><SPAN
939 CLASS="TOKEN"
940 >,</SPAN
941 >, <SPAN
942 CLASS="TOKEN"
943 >,</SPAN
944 ></DT
945 ><DD
946 ><DIV
947 CLASS="FORMALPARA"
948 ><P
949 ><B
950 ><A
951 HREF="bashver4.html#CASEMODPARAMSUB"
952 >Lowercase
953 conversion</A
954 > in <I
955 CLASS="FIRSTTERM"
956 >parameter substitution</I
957 >
958 (added in <A
959 HREF="bashver4.html#BASH4REF"
960 >version 4</A
961 > of Bash). </B
962 ></P
963 ></DIV
964 ></DD
965 ><DT
966 ><SPAN
967 CLASS="TOKEN"
968 >\</SPAN
969 ></DT
970 ><DD
971 ><DIV
972 CLASS="FORMALPARA"
973 ><P
974 ><B
975 ><A
976 HREF="escapingsection.html#ESCP"
977 >escape</A
978 > [backslash]. </B
979 >A quoting mechanism for single characters.</P
980 ></DIV
981 ><P
982 ><TT
983 CLASS="USERINPUT"
984 ><B
985 >\X</B
986 ></TT
987 >
988 <I
989 CLASS="FIRSTTERM"
990 >escapes</I
991 > the character
992 <SPAN
993 CLASS="emphasis"
994 ><I
995 CLASS="EMPHASIS"
996 >X</I
997 ></SPAN
998 >. This has the effect of
999 <SPAN
1000 CLASS="QUOTE"
1001 >"quoting"</SPAN
1002 > <SPAN
1003 CLASS="emphasis"
1004 ><I
1005 CLASS="EMPHASIS"
1006 >X</I
1007 ></SPAN
1008 >, equivalent
1009 to <SPAN
1010 CLASS="emphasis"
1011 ><I
1012 CLASS="EMPHASIS"
1013 >'X'</I
1014 ></SPAN
1015 >. The <SPAN
1016 CLASS="TOKEN"
1017 >\</SPAN
1018 > may
1019 be used to quote <SPAN
1020 CLASS="TOKEN"
1021 >"</SPAN
1022 > and <SPAN
1023 CLASS="TOKEN"
1024 >'</SPAN
1025 >,
1026 so they are expressed literally.</P
1027 ><P
1028 >See <A
1029 HREF="quoting.html"
1030 >Chapter 5</A
1031 > for an in-depth explanation
1032 of escaped characters.</P
1033 ></DD
1034 ><DT
1035 ><SPAN
1036 CLASS="TOKEN"
1037 >/</SPAN
1038 ></DT
1039 ><DD
1040 ><DIV
1041 CLASS="FORMALPARA"
1042 ><P
1043 ><B
1044 >Filename path separator [forward slash]. </B
1045 >Separates the components of a filename (as in
1046 <TT
1047 CLASS="FILENAME"
1048 >/home/bozo/projects/Makefile</TT
1049 >).</P
1050 ></DIV
1051 ><P
1052 >This is also the division <A
1053 HREF="operations.html#AROPS1"
1054 >arithmetic operator</A
1055 >.</P
1056 ></DD
1057 ><DT
1058 ><A
1059 NAME="BACKTICKSREF"
1060 ></A
1061 ><SPAN
1062 CLASS="TOKEN"
1063 >`</SPAN
1064 ></DT
1065 ><DD
1066 ><DIV
1067 CLASS="FORMALPARA"
1068 ><P
1069 ><B
1070 ><A
1071 HREF="commandsub.html#COMMANDSUBREF"
1072 >command substitution</A
1073 >. </B
1074 >The <B
1075 CLASS="COMMAND"
1076 >`command`</B
1077 > construct makes
1078 available the output of <B
1079 CLASS="COMMAND"
1080 >command</B
1081 >
1082 for assignment to a variable. This is also known as
1083 <A
1084 HREF="commandsub.html#BACKQUOTESREF"
1085 >backquotes</A
1086 > or
1087 backticks.</P
1088 ></DIV
1089 ></DD
1090 ><DT
1091 ><A
1092 NAME="COLON0REF"
1093 ></A
1094 ><SPAN
1095 CLASS="TOKEN"
1096 >:</SPAN
1097 ></DT
1098 ><DD
1099 ><P
1100 ><A
1101 NAME="NULLREF"
1102 ></A
1103 ></P
1104 ><DIV
1105 CLASS="FORMALPARA"
1106 ><P
1107 ><B
1108 >null command [colon]. </B
1109 >This is the shell equivalent of a
1110 <SPAN
1111 CLASS="QUOTE"
1112 >"NOP"</SPAN
1113 > (<TT
1114 CLASS="REPLACEABLE"
1115 ><I
1116 >no op</I
1117 ></TT
1118 >, a
1119 do-nothing operation). It may be considered a synonym for
1120 the shell builtin <A
1121 HREF="internal.html#TRUEREF"
1122 >true</A
1123 >. The
1124 <SPAN
1125 CLASS="QUOTE"
1126 >"<SPAN
1127 CLASS="TOKEN"
1128 >:</SPAN
1129 >"</SPAN
1130 > command is itself a
1131 <I
1132 CLASS="FIRSTTERM"
1133 >Bash</I
1134 > <A
1135 HREF="internal.html#BUILTINREF"
1136 >builtin</A
1137 >, and its <A
1138 HREF="exit-status.html#EXITSTATUSREF"
1139 >exit status</A
1140 > is
1141 <I
1142 CLASS="FIRSTTERM"
1143 >true</I
1144 >
1145 (<SPAN
1146 CLASS="RETURNVALUE"
1147 >0</SPAN
1148 >).</P
1149 ></DIV
1150 ><P
1151 ><TABLE
1152 BORDER="0"
1153 BGCOLOR="#E0E0E0"
1154 WIDTH="90%"
1155 ><TR
1156 ><TD
1157 ><PRE
1158 CLASS="PROGRAMLISTING"
1159 > 1&nbsp;:
1160 2&nbsp;echo $? # 0</PRE
1161 ></TD
1162 ></TR
1163 ></TABLE
1164 ></P
1165 ><P
1166 >Endless loop:</P
1167 ><P
1168 ><TABLE
1169 BORDER="0"
1170 BGCOLOR="#E0E0E0"
1171 WIDTH="90%"
1172 ><TR
1173 ><TD
1174 ><PRE
1175 CLASS="PROGRAMLISTING"
1176 > 1&nbsp;while :
1177 2&nbsp;do
1178 3&nbsp; operation-1
1179 4&nbsp; operation-2
1180 5&nbsp; ...
1181 6&nbsp; operation-n
1182 7&nbsp;done
1183 8&nbsp;
1184 9&nbsp;# Same as:
1185 10&nbsp;# while true
1186 11&nbsp;# do
1187 12&nbsp;# ...
1188 13&nbsp;# done</PRE
1189 ></TD
1190 ></TR
1191 ></TABLE
1192 >
1193 </P
1194 ><P
1195 >Placeholder in if/then test:</P
1196 ><P
1197 ><TABLE
1198 BORDER="0"
1199 BGCOLOR="#E0E0E0"
1200 WIDTH="90%"
1201 ><TR
1202 ><TD
1203 ><PRE
1204 CLASS="PROGRAMLISTING"
1205 > 1&nbsp;if condition
1206 2&nbsp;then : # Do nothing and branch ahead
1207 3&nbsp;else # Or else ...
1208 4&nbsp; take-some-action
1209 5&nbsp;fi</PRE
1210 ></TD
1211 ></TR
1212 ></TABLE
1213 >
1214 </P
1215 ><P
1216 >Provide a placeholder where a binary operation is
1217 expected, see <A
1218 HREF="operations.html#ARITHOPS"
1219 >Example 8-2</A
1220 > and <A
1221 HREF="parameter-substitution.html#DEFPARAM"
1222 >default parameters</A
1223 >.</P
1224 ><P
1225 ><TABLE
1226 BORDER="0"
1227 BGCOLOR="#E0E0E0"
1228 WIDTH="90%"
1229 ><TR
1230 ><TD
1231 ><PRE
1232 CLASS="PROGRAMLISTING"
1233 > 1&nbsp;: ${username=`whoami`}
1234 2&nbsp;# ${username=`whoami`} Gives an error without the leading :
1235 3&nbsp;# unless "username" is a command or builtin...
1236 4&nbsp;
1237 5&nbsp;: ${1?"Usage: $0 ARGUMENT"} # From "usage-message.sh example script.</PRE
1238 ></TD
1239 ></TR
1240 ></TABLE
1241 ></P
1242 ><P
1243 >Provide a placeholder where a command is expected in a
1244 <A
1245 HREF="here-docs.html#HEREDOCREF"
1246 >here document</A
1247 >. See <A
1248 HREF="here-docs.html#ANONHEREDOC"
1249 >Example 19-10</A
1250 >.</P
1251 ><P
1252 >Evaluate string of variables using
1253 <A
1254 HREF="parameter-substitution.html#PARAMSUBREF"
1255 >parameter substitution</A
1256 >
1257 (as in <A
1258 HREF="parameter-substitution.html#EX6"
1259 >Example 10-7</A
1260 >).
1261
1262 <TABLE
1263 BORDER="0"
1264 BGCOLOR="#E0E0E0"
1265 WIDTH="90%"
1266 ><TR
1267 ><TD
1268 ><PRE
1269 CLASS="PROGRAMLISTING"
1270 > 1&nbsp;: ${HOSTNAME?} ${USER?} ${MAIL?}
1271 2&nbsp;# Prints error message
1272 3&nbsp;#+ if one or more of essential environmental variables not set.</PRE
1273 ></TD
1274 ></TR
1275 ></TABLE
1276 ></P
1277 ><P
1278 ><B
1279 CLASS="COMMAND"
1280 ><A
1281 HREF="parameter-substitution.html#EXPREPL1"
1282 >Variable expansion / substring
1283 replacement</A
1284 ></B
1285 >.</P
1286 ><P
1287 >In combination with the <SPAN
1288 CLASS="TOKEN"
1289 >&#62;</SPAN
1290 > <A
1291 HREF="io-redirection.html#IOREDIRREF"
1292 >redirection operator</A
1293 >,
1294 truncates a file to zero length, without changing its
1295 permissions. If the file did not previously exist,
1296 creates it.
1297
1298 <TABLE
1299 BORDER="0"
1300 BGCOLOR="#E0E0E0"
1301 WIDTH="90%"
1302 ><TR
1303 ><TD
1304 ><PRE
1305 CLASS="PROGRAMLISTING"
1306 > 1&nbsp;: &#62; data.xxx # File "data.xxx" now empty.
1307 2&nbsp;
1308 3&nbsp;# Same effect as cat /dev/null &#62;data.xxx
1309 4&nbsp;# However, this does not fork a new process, since ":" is a builtin.</PRE
1310 ></TD
1311 ></TR
1312 ></TABLE
1313 >
1314 See also <A
1315 HREF="textproc.html#EX12"
1316 >Example 16-15</A
1317 >.</P
1318 ><P
1319 >In combination with the <SPAN
1320 CLASS="TOKEN"
1321 >&#62;&#62;</SPAN
1322 >
1323 redirection operator, has no effect on a pre-existing
1324 target file (<TT
1325 CLASS="USERINPUT"
1326 ><B
1327 >: &#62;&#62; target_file</B
1328 ></TT
1329 >).
1330 If the file did not previously exist, creates it.</P
1331 ><DIV
1332 CLASS="NOTE"
1333 ><TABLE
1334 CLASS="NOTE"
1335 WIDTH="90%"
1336 BORDER="0"
1337 ><TR
1338 ><TD
1339 WIDTH="25"
1340 ALIGN="CENTER"
1341 VALIGN="TOP"
1342 ><IMG
1343 SRC="common/note.png"
1344 HSPACE="5"
1345 ALT="Note"></TD
1346 ><TD
1347 ALIGN="LEFT"
1348 VALIGN="TOP"
1349 ><P
1350 ><A
1351 NAME="REGFILEREF"
1352 ></A
1353 >This applies to regular files,
1354 not pipes, symlinks, and certain special files.</P
1355 ></TD
1356 ></TR
1357 ></TABLE
1358 ></DIV
1359 ><P
1360 >May be used to begin a comment line, although this is not
1361 recommended. Using <SPAN
1362 CLASS="TOKEN"
1363 >#</SPAN
1364 > for a comment turns
1365 off error checking for the remainder of that line, so
1366 almost anything may appear in a comment. However,
1367 this is not the case with
1368 <SPAN
1369 CLASS="TOKEN"
1370 >:</SPAN
1371 >.
1372 <TABLE
1373 BORDER="0"
1374 BGCOLOR="#E0E0E0"
1375 WIDTH="90%"
1376 ><TR
1377 ><TD
1378 ><PRE
1379 CLASS="PROGRAMLISTING"
1380 > 1&nbsp;: This is a comment that generates an error, ( if [ $x -eq 3] ).</PRE
1381 ></TD
1382 ></TR
1383 ></TABLE
1384 >
1385 </P
1386 ><P
1387 >The <SPAN
1388 CLASS="QUOTE"
1389 >"<SPAN
1390 CLASS="TOKEN"
1391 >:</SPAN
1392 >"</SPAN
1393 > serves as a <A
1394 HREF="special-chars.html#FIELDREF"
1395 >field</A
1396 >
1397 separator, in <A
1398 HREF="files.html#DATAFILESREF1"
1399 ><TT
1400 CLASS="FILENAME"
1401 >/etc/passwd</TT
1402 ></A
1403 >,
1404 and in the <A
1405 HREF="variables2.html#PATHREF"
1406 >$PATH</A
1407 > variable.
1408 <TABLE
1409 BORDER="0"
1410 BGCOLOR="#E0E0E0"
1411 WIDTH="90%"
1412 ><TR
1413 ><TD
1414 ><PRE
1415 CLASS="SCREEN"
1416 > <TT
1417 CLASS="PROMPT"
1418 >bash$ </TT
1419 ><TT
1420 CLASS="USERINPUT"
1421 ><B
1422 >echo $PATH</B
1423 ></TT
1424 >
1425 <TT
1426 CLASS="COMPUTEROUTPUT"
1427 >/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin:/usr/games</TT
1428 ></PRE
1429 ></TD
1430 ></TR
1431 ></TABLE
1432 >
1433 </P
1434 ><P
1435 ><A
1436 NAME="COLONFNAME"
1437 ></A
1438 ></P
1439 ><P
1440 >A <I
1441 CLASS="FIRSTTERM"
1442 >colon</I
1443 > is <A
1444 HREF="functions.html#FSTRANGEREF"
1445 >acceptable as a function name</A
1446 >.
1447 <TABLE
1448 BORDER="0"
1449 BGCOLOR="#E0E0E0"
1450 WIDTH="90%"
1451 ><TR
1452 ><TD
1453 ><PRE
1454 CLASS="PROGRAMLISTING"
1455 > 1&nbsp;:()
1456 2&nbsp;{
1457 3&nbsp; echo "The name of this function is "$FUNCNAME" "
1458 4&nbsp; # Why use a colon as a function name?
1459 5&nbsp; # It's a way of obfuscating your code.
1460 6&nbsp;}
1461 7&nbsp;
1462 8&nbsp;:
1463 9&nbsp;
1464 10&nbsp;# The name of this function is :</PRE
1465 ></TD
1466 ></TR
1467 ></TABLE
1468 >
1469
1470 This is not <A
1471 HREF="portabilityissues.html"
1472 >portable</A
1473 >
1474 behavior, and therefore not a recommended practice.
1475 In fact, more recent releases of Bash do not permit
1476 this usage. An underscore <B
1477 CLASS="COMMAND"
1478 >_</B
1479 > works,
1480 though.</P
1481 ><P
1482 ><A
1483 NAME="COLONINFUNCTION"
1484 ></A
1485 ></P
1486 ><P
1487 >A <I
1488 CLASS="FIRSTTERM"
1489 >colon</I
1490 > can serve
1491 as a placeholder in an otherwise empty
1492 function.</P
1493 ><P
1494 ><TABLE
1495 BORDER="0"
1496 BGCOLOR="#E0E0E0"
1497 WIDTH="90%"
1498 ><TR
1499 ><TD
1500 ><PRE
1501 CLASS="PROGRAMLISTING"
1502 > 1&nbsp;not_empty ()
1503 2&nbsp;{
1504 3&nbsp; :
1505 4&nbsp;} # Contains a : (null command), and so is not empty.</PRE
1506 ></TD
1507 ></TR
1508 ></TABLE
1509 ></P
1510 ></DD
1511 ><DT
1512 ><A
1513 NAME="NOTREF"
1514 ></A
1515 ><SPAN
1516 CLASS="TOKEN"
1517 >!</SPAN
1518 ></DT
1519 ><DD
1520 ><DIV
1521 CLASS="FORMALPARA"
1522 ><P
1523 ><B
1524 >reverse (or negate) the sense of
1525 a test or exit status [bang]. </B
1526 >The <SPAN
1527 CLASS="TOKEN"
1528 >!</SPAN
1529 > operator inverts the <A
1530 HREF="exit-status.html#EXITSTATUSREF"
1531 >exit status</A
1532 >
1533 of the command to which it is applied (see
1534 <A
1535 HREF="exit-status.html#NEGCOND"
1536 >Example 6-2</A
1537 >). It also inverts
1538 the meaning of a test operator. This can, for
1539 example, change the sense of <I
1540 CLASS="FIRSTTERM"
1541 >equal</I
1542 >
1543 ( <A
1544 HREF="comparison-ops.html#EQUALSIGNREF"
1545 >=</A
1546 >
1547 ) to <I
1548 CLASS="FIRSTTERM"
1549 >not-equal</I
1550 > ( != ). The
1551 <SPAN
1552 CLASS="TOKEN"
1553 >!</SPAN
1554 > operator is a Bash <A
1555 HREF="internal.html#KEYWORDREF"
1556 >keyword</A
1557 >.</P
1558 ></DIV
1559 ><P
1560 >In a different context, the <SPAN
1561 CLASS="TOKEN"
1562 >!</SPAN
1563 >
1564 also appears in <A
1565 HREF="ivr.html#IVRREF"
1566 >indirect variable
1567 references</A
1568 >.</P
1569 ><P
1570 >In yet another context, from the <I
1571 CLASS="FIRSTTERM"
1572 >command
1573 line</I
1574 >, the <SPAN
1575 CLASS="TOKEN"
1576 >!</SPAN
1577 > invokes the
1578 Bash <I
1579 CLASS="FIRSTTERM"
1580 >history mechanism</I
1581 > (see <A
1582 HREF="histcommands.html"
1583 >Appendix L</A
1584 >). Note that within a script,
1585 the history mechanism is disabled.</P
1586 ></DD
1587 ><DT
1588 ><A
1589 NAME="ASTERISKREF"
1590 ></A
1591 ><SPAN
1592 CLASS="TOKEN"
1593 >*</SPAN
1594 ></DT
1595 ><DD
1596 ><DIV
1597 CLASS="FORMALPARA"
1598 ><P
1599 ><B
1600 >wild card [asterisk]. </B
1601 >The <SPAN
1602 CLASS="TOKEN"
1603 >*</SPAN
1604 > character serves as a <SPAN
1605 CLASS="QUOTE"
1606 >"wild
1607 card"</SPAN
1608 > for filename expansion in
1609 <A
1610 HREF="globbingref.html"
1611 >globbing</A
1612 >. By itself,
1613 it matches every filename in a given directory.</P
1614 ></DIV
1615 ><P
1616 > <TABLE
1617 BORDER="0"
1618 BGCOLOR="#E0E0E0"
1619 WIDTH="90%"
1620 ><TR
1621 ><TD
1622 ><PRE
1623 CLASS="SCREEN"
1624 > <TT
1625 CLASS="PROMPT"
1626 >bash$ </TT
1627 ><TT
1628 CLASS="USERINPUT"
1629 ><B
1630 >echo *</B
1631 ></TT
1632 >
1633 <TT
1634 CLASS="COMPUTEROUTPUT"
1635 >abs-book.sgml add-drive.sh agram.sh alias.sh</TT
1636 >
1637 </PRE
1638 ></TD
1639 ></TR
1640 ></TABLE
1641 >
1642 </P
1643 ><P
1644 ><A
1645 NAME="ASTERISKREF2"
1646 ></A
1647 ></P
1648 ><P
1649 >The <SPAN
1650 CLASS="TOKEN"
1651 >*</SPAN
1652 > also represents <A
1653 HREF="regexp.html#ASTERISKREG"
1654 >any number
1655 (or zero) characters</A
1656 > in a <A
1657 HREF="regexp.html#REGEXREF"
1658 >regular expression</A
1659 >.</P
1660 ></DD
1661 ><DT
1662 ><SPAN
1663 CLASS="TOKEN"
1664 >*</SPAN
1665 ></DT
1666 ><DD
1667 ><DIV
1668 CLASS="FORMALPARA"
1669 ><P
1670 ><B
1671 ><A
1672 HREF="operations.html#AROPS1"
1673 >arithmetic operator</A
1674 >. </B
1675 >In the context of arithmetic operations, the
1676 <SPAN
1677 CLASS="TOKEN"
1678 >*</SPAN
1679 > denotes multiplication.</P
1680 ></DIV
1681 ><P
1682 ><SPAN
1683 CLASS="TOKEN"
1684 >**</SPAN
1685 > A double asterisk can represent the
1686 <A
1687 HREF="operations.html#EXPONENTIATIONREF"
1688 >exponentiation</A
1689 >
1690 operator or <A
1691 HREF="bashver4.html#GLOBSTARREF"
1692 >extended
1693 file-match</A
1694 > <I
1695 CLASS="FIRSTTERM"
1696 >globbing</I
1697 >.</P
1698 ></DD
1699 ><DT
1700 ><SPAN
1701 CLASS="TOKEN"
1702 >?</SPAN
1703 ></DT
1704 ><DD
1705 ><DIV
1706 CLASS="FORMALPARA"
1707 ><P
1708 ><B
1709 >test operator. </B
1710 >Within certain expressions, the <SPAN
1711 CLASS="TOKEN"
1712 >?</SPAN
1713 > indicates
1714 a test for a condition.</P
1715 ></DIV
1716 ><P
1717 ><A
1718 NAME="CSTRINARY"
1719 ></A
1720 ></P
1721 ><P
1722 >In a <A
1723 HREF="dblparens.html"
1724 >double-parentheses
1725 construct</A
1726 >, the <SPAN
1727 CLASS="TOKEN"
1728 >?</SPAN
1729 >
1730 can serve as an element of a C-style
1731 <I
1732 CLASS="FIRSTTERM"
1733 >trinary</I
1734 > operator.
1735 <A
1736 NAME="AEN888"
1737 HREF="#FTN.AEN888"
1738 >[2]</A
1739 >
1740 </P
1741 ><P
1742 ><TT
1743 CLASS="VARNAME"
1744 >condition</TT
1745 ><B
1746 CLASS="COMMAND"
1747 >?</B
1748 ><TT
1749 CLASS="VARNAME"
1750 >result-if-true</TT
1751 ><B
1752 CLASS="COMMAND"
1753 >:</B
1754 ><TT
1755 CLASS="VARNAME"
1756 >result-if-false</TT
1757 ></P
1758 ><P
1759 ><TABLE
1760 BORDER="0"
1761 BGCOLOR="#E0E0E0"
1762 WIDTH="90%"
1763 ><TR
1764 ><TD
1765 ><PRE
1766 CLASS="PROGRAMLISTING"
1767 > 1&nbsp;(( var0 = var1&#60;98?9:21 ))
1768 2&nbsp;# ^ ^
1769 3&nbsp;
1770 4&nbsp;# if [ "$var1" -lt 98 ]
1771 5&nbsp;# then
1772 6&nbsp;# var0=9
1773 7&nbsp;# else
1774 8&nbsp;# var0=21
1775 9&nbsp;# fi</PRE
1776 ></TD
1777 ></TR
1778 ></TABLE
1779 ></P
1780 ><P
1781 >In a <A
1782 HREF="parameter-substitution.html#PARAMSUBREF"
1783 >parameter
1784 substitution</A
1785 > expression, the <SPAN
1786 CLASS="TOKEN"
1787 >?</SPAN
1788 >
1789 <A
1790 HREF="parameter-substitution.html#QERRMSG"
1791 >tests whether a variable has been
1792 set</A
1793 >.</P
1794 ></DD
1795 ><DT
1796 ><A
1797 NAME="WILDCARDQU"
1798 ></A
1799 ><SPAN
1800 CLASS="TOKEN"
1801 >?</SPAN
1802 ></DT
1803 ><DD
1804 ><DIV
1805 CLASS="FORMALPARA"
1806 ><P
1807 ><B
1808 >wild card. </B
1809 ><A
1810 NAME="QUEXWC"
1811 ></A
1812 >The <SPAN
1813 CLASS="TOKEN"
1814 >?</SPAN
1815 > character
1816 serves as a single-character <SPAN
1817 CLASS="QUOTE"
1818 >"wild card"</SPAN
1819 >
1820 for filename expansion in <A
1821 HREF="globbingref.html"
1822 >globbing</A
1823 >, as well as <A
1824 HREF="regexp.html#QUEXREGEX"
1825 >representing one character</A
1826 >
1827 in an <A
1828 HREF="regexp.html#EXTREGEX"
1829 >extended regular
1830 expression</A
1831 >.</P
1832 ></DIV
1833 ></DD
1834 ><DT
1835 ><SPAN
1836 CLASS="TOKEN"
1837 >$</SPAN
1838 ></DT
1839 ><DD
1840 ><DIV
1841 CLASS="FORMALPARA"
1842 ><P
1843 ><B
1844 ><A
1845 HREF="variables.html#VARSUBN"
1846 >Variable
1847 substitution</A
1848 > (contents of a variable). </B
1849 > <TABLE
1850 BORDER="0"
1851 BGCOLOR="#E0E0E0"
1852 WIDTH="90%"
1853 ><TR
1854 ><TD
1855 ><PRE
1856 CLASS="PROGRAMLISTING"
1857 > 1&nbsp;var1=5
1858 2&nbsp;var2=23skidoo
1859 3&nbsp;
1860 4&nbsp;echo $var1 # 5
1861 5&nbsp;echo $var2 # 23skidoo</PRE
1862 ></TD
1863 ></TR
1864 ></TABLE
1865 >
1866 </P
1867 ></DIV
1868 ><P
1869 ><A
1870 NAME="VARPREFIXREF"
1871 ></A
1872 ></P
1873 ><P
1874 >A <SPAN
1875 CLASS="TOKEN"
1876 >$</SPAN
1877 > prefixing a variable name
1878 indicates the <I
1879 CLASS="FIRSTTERM"
1880 >value</I
1881 > the variable
1882 holds.</P
1883 ></DD
1884 ><DT
1885 ><SPAN
1886 CLASS="TOKEN"
1887 >$</SPAN
1888 ></DT
1889 ><DD
1890 ><DIV
1891 CLASS="FORMALPARA"
1892 ><P
1893 ><B
1894 >end-of-line. </B
1895 >In a <A
1896 HREF="regexp.html#REGEXREF"
1897 >regular expression</A
1898 >, a
1899 <SPAN
1900 CLASS="QUOTE"
1901 >"$"</SPAN
1902 > addresses the <A
1903 HREF="regexp.html#DOLLARSIGNREF"
1904 >end of a line</A
1905 > of
1906 text.</P
1907 ></DIV
1908 ></DD
1909 ><DT
1910 ><SPAN
1911 CLASS="TOKEN"
1912 >${}</SPAN
1913 ></DT
1914 ><DD
1915 ><DIV
1916 CLASS="FORMALPARA"
1917 ><P
1918 ><B
1919 ><A
1920 HREF="parameter-substitution.html#PARAMSUBREF"
1921 >Parameter
1922 substitution</A
1923 >. </B
1924 ></P
1925 ></DIV
1926 ></DD
1927 ><DT
1928 ><SPAN
1929 CLASS="TOKEN"
1930 >$' ... '</SPAN
1931 ></DT
1932 ><DD
1933 ><DIV
1934 CLASS="FORMALPARA"
1935 ><P
1936 ><B
1937 ><A
1938 HREF="escapingsection.html#STRQ"
1939 >Quoted string
1940 expansion</A
1941 >. </B
1942 >This construct expands single or multiple
1943 escaped octal or hex values into ASCII
1944
1945 <A
1946 NAME="AEN1001"
1947 HREF="#FTN.AEN1001"
1948 >[3]</A
1949 >
1950
1951 or <A
1952 HREF="bashver4.html#UNICODEREF"
1953 >Unicode</A
1954 >
1955 characters.</P
1956 ></DIV
1957 ></DD
1958 ><DT
1959 ><SPAN
1960 CLASS="TOKEN"
1961 >$*</SPAN
1962 >, <SPAN
1963 CLASS="TOKEN"
1964 >$@</SPAN
1965 ></DT
1966 ><DD
1967 ><DIV
1968 CLASS="FORMALPARA"
1969 ><P
1970 ><B
1971 ><A
1972 HREF="variables2.html#APPREF"
1973 >positional
1974 parameters</A
1975 >. </B
1976 ></P
1977 ></DIV
1978 ></DD
1979 ><DT
1980 ><SPAN
1981 CLASS="TOKEN"
1982 >$?</SPAN
1983 ></DT
1984 ><DD
1985 ><DIV
1986 CLASS="FORMALPARA"
1987 ><P
1988 ><B
1989 >exit status variable. </B
1990 >The <A
1991 HREF="exit-status.html#EXSREF"
1992 >$? variable</A
1993 >
1994 holds the <A
1995 HREF="exit-status.html#EXITSTATUSREF"
1996 >exit status</A
1997 >
1998 of a command, a <A
1999 HREF="functions.html#FUNCTIONREF"
2000 >function</A
2001 >,
2002 or of the script itself.</P
2003 ></DIV
2004 ></DD
2005 ><DT
2006 ><A
2007 NAME="PROCESSIDREF"
2008 ></A
2009 ><SPAN
2010 CLASS="TOKEN"
2011 >$$</SPAN
2012 ></DT
2013 ><DD
2014 ><DIV
2015 CLASS="FORMALPARA"
2016 ><P
2017 ><B
2018 >process ID variable. </B
2019 >The <A
2020 HREF="variables2.html#PROCCID"
2021 >$$ variable</A
2022 >
2023 holds the <I
2024 CLASS="FIRSTTERM"
2025 >process ID</I
2026 >
2027 <A
2028 NAME="AEN1071"
2029 HREF="#FTN.AEN1071"
2030 >[4]</A
2031 >
2032 of the script in which it appears.</P
2033 ></DIV
2034 ></DD
2035 ><DT
2036 ><A
2037 NAME="PARENSREF"
2038 ></A
2039 ><SPAN
2040 CLASS="TOKEN"
2041 >()</SPAN
2042 ></DT
2043 ><DD
2044 ><DIV
2045 CLASS="FORMALPARA"
2046 ><P
2047 ><B
2048 >command group. </B
2049 ><TABLE
2050 BORDER="0"
2051 BGCOLOR="#E0E0E0"
2052 WIDTH="90%"
2053 ><TR
2054 ><TD
2055 ><PRE
2056 CLASS="PROGRAMLISTING"
2057 > 1&nbsp;(a=hello; echo $a)</PRE
2058 ></TD
2059 ></TR
2060 ></TABLE
2061 ></P
2062 ></DIV
2063 ><DIV
2064 CLASS="IMPORTANT"
2065 ><TABLE
2066 CLASS="IMPORTANT"
2067 WIDTH="90%"
2068 BORDER="0"
2069 ><TR
2070 ><TD
2071 WIDTH="25"
2072 ALIGN="CENTER"
2073 VALIGN="TOP"
2074 ><IMG
2075 SRC="common/important.png"
2076 HSPACE="5"
2077 ALT="Important"></TD
2078 ><TD
2079 ALIGN="LEFT"
2080 VALIGN="TOP"
2081 ><P
2082 >A listing of commands within
2083 <TT
2084 CLASS="REPLACEABLE"
2085 ><I
2086 >parentheses</I
2087 ></TT
2088 > starts a <A
2089 HREF="subshells.html#SUBSHELLSREF"
2090 >subshell</A
2091 >.</P
2092 ><P
2093 >Variables inside parentheses, within the subshell, are not
2094 visible to the rest of the script. The parent process,
2095 the script, <A
2096 HREF="subshells.html#PARVIS"
2097 >cannot read variables
2098 created in the child process</A
2099 >, the subshell.
2100 <TABLE
2101 BORDER="0"
2102 BGCOLOR="#E0E0E0"
2103 WIDTH="90%"
2104 ><TR
2105 ><TD
2106 ><PRE
2107 CLASS="PROGRAMLISTING"
2108 > 1&nbsp;a=123
2109 2&nbsp;( a=321; )
2110 3&nbsp;
2111 4&nbsp;echo "a = $a" # a = 123
2112 5&nbsp;# "a" within parentheses acts like a local variable.</PRE
2113 ></TD
2114 ></TR
2115 ></TABLE
2116 ></P
2117 ></TD
2118 ></TR
2119 ></TABLE
2120 ></DIV
2121 ><DIV
2122 CLASS="FORMALPARA"
2123 ><P
2124 ><B
2125 >array initialization. </B
2126 > <A
2127 NAME="ARRAYINIT1"
2128 ></A
2129 >
2130 <TABLE
2131 BORDER="0"
2132 BGCOLOR="#E0E0E0"
2133 WIDTH="90%"
2134 ><TR
2135 ><TD
2136 ><PRE
2137 CLASS="PROGRAMLISTING"
2138 > 1&nbsp;Array=(element1 element2 element3)</PRE
2139 ></TD
2140 ></TR
2141 ></TABLE
2142 >
2143 </P
2144 ></DIV
2145 ></DD
2146 ><DT
2147 ><SPAN
2148 CLASS="TOKEN"
2149 >{xxx,yyy,zzz,...}</SPAN
2150 ></DT
2151 ><DD
2152 ><DIV
2153 CLASS="FORMALPARA"
2154 ><P
2155 ><B
2156 >Brace expansion. </B
2157 ><A
2158 NAME="BRACEEXPREF"
2159 ></A
2160 >
2161 <TABLE
2162 BORDER="0"
2163 BGCOLOR="#E0E0E0"
2164 WIDTH="90%"
2165 ><TR
2166 ><TD
2167 ><PRE
2168 CLASS="PROGRAMLISTING"
2169 > 1&nbsp;echo \"{These,words,are,quoted}\" # " prefix and suffix
2170 2&nbsp;# "These" "words" "are" "quoted"
2171 3&nbsp;
2172 4&nbsp;
2173 5&nbsp;cat {file1,file2,file3} &#62; combined_file
2174 6&nbsp;# Concatenates the files file1, file2, and file3 into combined_file.
2175 7&nbsp;
2176 8&nbsp;cp file22.{txt,backup}
2177 9&nbsp;# Copies "file22.txt" to "file22.backup"</PRE
2178 ></TD
2179 ></TR
2180 ></TABLE
2181 ></P
2182 ></DIV
2183 ><P
2184 >A command may act upon a comma-separated list of file specs within
2185 <TT
2186 CLASS="REPLACEABLE"
2187 ><I
2188 >braces</I
2189 ></TT
2190 >.
2191
2192 <A
2193 NAME="AEN1124"
2194 HREF="#FTN.AEN1124"
2195 >[5]</A
2196 >
2197
2198 Filename expansion (<A
2199 HREF="globbingref.html"
2200 >globbing</A
2201 >)
2202 applies to the file specs between the braces.</P
2203 ><DIV
2204 CLASS="CAUTION"
2205 ><TABLE
2206 CLASS="CAUTION"
2207 WIDTH="90%"
2208 BORDER="0"
2209 ><TR
2210 ><TD
2211 WIDTH="25"
2212 ALIGN="CENTER"
2213 VALIGN="TOP"
2214 ><IMG
2215 SRC="common/caution.png"
2216 HSPACE="5"
2217 ALT="Caution"></TD
2218 ><TD
2219 ALIGN="LEFT"
2220 VALIGN="TOP"
2221 ><P
2222 >No spaces allowed within the braces
2223 <SPAN
2224 CLASS="emphasis"
2225 ><I
2226 CLASS="EMPHASIS"
2227 >unless</I
2228 ></SPAN
2229 > the spaces are quoted or escaped.</P
2230 ><P
2231 ><TT
2232 CLASS="USERINPUT"
2233 ><B
2234 >echo {file1,file2}\ :{\ A," B",' C'}</B
2235 ></TT
2236 ></P
2237 ><P
2238 ><TT
2239 CLASS="COMPUTEROUTPUT"
2240 >file1 : A file1 : B file1 : C file2 : A file2 : B file2 : C</TT
2241 ></P
2242 ></TD
2243 ></TR
2244 ></TABLE
2245 ></DIV
2246 ></DD
2247 ><DT
2248 ><A
2249 NAME="BRACEEXPREF33"
2250 ></A
2251 ><SPAN
2252 CLASS="TOKEN"
2253 >{a..z}</SPAN
2254 ></DT
2255 ><DD
2256 ><DIV
2257 CLASS="FORMALPARA"
2258 ><P
2259 ><B
2260 >Extended Brace expansion. </B
2261 ><TABLE
2262 BORDER="0"
2263 BGCOLOR="#E0E0E0"
2264 WIDTH="90%"
2265 ><TR
2266 ><TD
2267 ><PRE
2268 CLASS="PROGRAMLISTING"
2269 > 1&nbsp;echo {a..z} # a b c d e f g h i j k l m n o p q r s t u v w x y z
2270 2&nbsp;# Echoes characters between a and z.
2271 3&nbsp;
2272 4&nbsp;echo {0..3} # 0 1 2 3
2273 5&nbsp;# Echoes characters between 0 and 3.
2274 6&nbsp;
2275 7&nbsp;
2276 8&nbsp;base64_charset=( {A..Z} {a..z} {0..9} + / = )
2277 9&nbsp;# Initializing an array, using extended brace expansion.
2278 10&nbsp;# From vladz's "base64.sh" example script.</PRE
2279 ></TD
2280 ></TR
2281 ></TABLE
2282 >
2283 </P
2284 ></DIV
2285 ><P
2286 >The <I
2287 CLASS="FIRSTTERM"
2288 >{a..z}</I
2289 >
2290 <A
2291 HREF="bashver3.html#BRACEEXPREF3"
2292 >extended brace
2293 expansion</A
2294 > construction is a feature introduced
2295 in <A
2296 HREF="bashver3.html#BASH3REF"
2297 >version 3</A
2298 > of
2299 <I
2300 CLASS="FIRSTTERM"
2301 >Bash</I
2302 >.</P
2303 ></DD
2304 ><DT
2305 ><A
2306 NAME="CODEBLOCKREF"
2307 ></A
2308 ><SPAN
2309 CLASS="TOKEN"
2310 >{}</SPAN
2311 ></DT
2312 ><DD
2313 ><DIV
2314 CLASS="FORMALPARA"
2315 ><P
2316 ><B
2317 >Block of code [curly brackets]. </B
2318 >Also referred to as an <I
2319 CLASS="FIRSTTERM"
2320 >inline group</I
2321 >,
2322 this construct, in effect, creates an <I
2323 CLASS="FIRSTTERM"
2324 >anonymous
2325 function</I
2326 > (a function without a
2327 name). However, unlike in a <SPAN
2328 CLASS="QUOTE"
2329 >"standard"</SPAN
2330 > <A
2331 HREF="functions.html#FUNCTIONREF"
2332 >function</A
2333 >, the variables
2334 inside a code block remain visible to the remainder of the
2335 script.</P
2336 ></DIV
2337 ><P
2338 > <TABLE
2339 BORDER="0"
2340 BGCOLOR="#E0E0E0"
2341 WIDTH="90%"
2342 ><TR
2343 ><TD
2344 ><PRE
2345 CLASS="SCREEN"
2346 > <TT
2347 CLASS="PROMPT"
2348 >bash$ </TT
2349 ><TT
2350 CLASS="USERINPUT"
2351 ><B
2352 >{ local a;
2353 a=123; }</B
2354 ></TT
2355 >
2356 <TT
2357 CLASS="COMPUTEROUTPUT"
2358 >bash: local: can only be used in a
2359 function</TT
2360 >
2361 </PRE
2362 ></TD
2363 ></TR
2364 ></TABLE
2365 > </P
2366 ><P
2367 ><TABLE
2368 BORDER="0"
2369 BGCOLOR="#E0E0E0"
2370 WIDTH="90%"
2371 ><TR
2372 ><TD
2373 ><PRE
2374 CLASS="PROGRAMLISTING"
2375 > 1&nbsp;a=123
2376 2&nbsp;{ a=321; }
2377 3&nbsp;echo "a = $a" # a = 321 (value inside code block)
2378 4&nbsp;
2379 5&nbsp;# Thanks, S.C.</PRE
2380 ></TD
2381 ></TR
2382 ></TABLE
2383 ></P
2384 ><P
2385 ><A
2386 NAME="BLOCKIO"
2387 ></A
2388 ></P
2389 ><P
2390 >The code block enclosed in braces may have <A
2391 HREF="io-redirection.html#IOREDIRREF"
2392 >I/O redirected</A
2393 > to and from
2394 it.</P
2395 ><DIV
2396 CLASS="EXAMPLE"
2397 ><HR><A
2398 NAME="EX8"
2399 ></A
2400 ><P
2401 ><B
2402 >Example 3-1. Code blocks and I/O redirection</B
2403 ></P
2404 ><TABLE
2405 BORDER="0"
2406 BGCOLOR="#E0E0E0"
2407 WIDTH="90%"
2408 ><TR
2409 ><TD
2410 ><PRE
2411 CLASS="PROGRAMLISTING"
2412 > 1&nbsp;#!/bin/bash
2413 2&nbsp;# Reading lines in /etc/fstab.
2414 3&nbsp;
2415 4&nbsp;File=/etc/fstab
2416 5&nbsp;
2417 6&nbsp;{
2418 7&nbsp;read line1
2419 8&nbsp;read line2
2420 9&nbsp;} &#60; $File
2421 10&nbsp;
2422 11&nbsp;echo "First line in $File is:"
2423 12&nbsp;echo "$line1"
2424 13&nbsp;echo
2425 14&nbsp;echo "Second line in $File is:"
2426 15&nbsp;echo "$line2"
2427 16&nbsp;
2428 17&nbsp;exit 0
2429 18&nbsp;
2430 19&nbsp;# Now, how do you parse the separate fields of each line?
2431 20&nbsp;# Hint: use awk, or . . .
2432 21&nbsp;# . . . Hans-Joerg Diers suggests using the "set" Bash builtin.</PRE
2433 ></TD
2434 ></TR
2435 ></TABLE
2436 ><HR></DIV
2437 ><P
2438 ><A
2439 NAME="BLOCKIO2"
2440 ></A
2441 ></P
2442 ><DIV
2443 CLASS="EXAMPLE"
2444 ><HR><A
2445 NAME="RPMCHECK"
2446 ></A
2447 ><P
2448 ><B
2449 >Example 3-2. Saving the output of a code block to a file</B
2450 ></P
2451 ><TABLE
2452 BORDER="0"
2453 BGCOLOR="#E0E0E0"
2454 WIDTH="90%"
2455 ><TR
2456 ><TD
2457 ><PRE
2458 CLASS="PROGRAMLISTING"
2459 > 1&nbsp;#!/bin/bash
2460 2&nbsp;# rpm-check.sh
2461 3&nbsp;
2462 4&nbsp;# Queries an rpm file for description, listing,
2463 5&nbsp;#+ and whether it can be installed.
2464 6&nbsp;# Saves output to a file.
2465 7&nbsp;#
2466 8&nbsp;# This script illustrates using a code block.
2467 9&nbsp;
2468 10&nbsp;SUCCESS=0
2469 11&nbsp;E_NOARGS=65
2470 12&nbsp;
2471 13&nbsp;if [ -z "$1" ]
2472 14&nbsp;then
2473 15&nbsp; echo "Usage: `basename $0` rpm-file"
2474 16&nbsp; exit $E_NOARGS
2475 17&nbsp;fi
2476 18&nbsp;
2477 19&nbsp;{ # Begin code block.
2478 20&nbsp; echo
2479 21&nbsp; echo "Archive Description:"
2480 22&nbsp; rpm -qpi $1 # Query description.
2481 23&nbsp; echo
2482 24&nbsp; echo "Archive Listing:"
2483 25&nbsp; rpm -qpl $1 # Query listing.
2484 26&nbsp; echo
2485 27&nbsp; rpm -i --test $1 # Query whether rpm file can be installed.
2486 28&nbsp; if [ "$?" -eq $SUCCESS ]
2487 29&nbsp; then
2488 30&nbsp; echo "$1 can be installed."
2489 31&nbsp; else
2490 32&nbsp; echo "$1 cannot be installed."
2491 33&nbsp; fi
2492 34&nbsp; echo # End code block.
2493 35&nbsp;} &#62; "$1.test" # Redirects output of everything in block to file.
2494 36&nbsp;
2495 37&nbsp;echo "Results of rpm test in file $1.test"
2496 38&nbsp;
2497 39&nbsp;# See rpm man page for explanation of options.
2498 40&nbsp;
2499 41&nbsp;exit 0</PRE
2500 ></TD
2501 ></TR
2502 ></TABLE
2503 ><HR></DIV
2504 ><DIV
2505 CLASS="NOTE"
2506 ><TABLE
2507 CLASS="NOTE"
2508 WIDTH="90%"
2509 BORDER="0"
2510 ><TR
2511 ><TD
2512 WIDTH="25"
2513 ALIGN="CENTER"
2514 VALIGN="TOP"
2515 ><IMG
2516 SRC="common/note.png"
2517 HSPACE="5"
2518 ALT="Note"></TD
2519 ><TD
2520 ALIGN="LEFT"
2521 VALIGN="TOP"
2522 ><P
2523 >Unlike a command group within (parentheses),
2524 as above, a code block enclosed by {braces} will
2525 <SPAN
2526 CLASS="emphasis"
2527 ><I
2528 CLASS="EMPHASIS"
2529 >not</I
2530 ></SPAN
2531 > normally launch a <A
2532 HREF="subshells.html#SUBSHELLSREF"
2533 >subshell</A
2534 >.
2535
2536 <A
2537 NAME="AEN1199"
2538 HREF="#FTN.AEN1199"
2539 >[6]</A
2540 >
2541
2542 </P
2543 ><P
2544 >It is possible to <A
2545 HREF="loops.html#ITERATIONREF"
2546 >iterate</A
2547 > a code block
2548 using a <A
2549 HREF="loops.html#NODODONE"
2550 >non-standard
2551 <I
2552 CLASS="FIRSTTERM"
2553 >for-loop</I
2554 ></A
2555 >.</P
2556 ></TD
2557 ></TR
2558 ></TABLE
2559 ></DIV
2560 ></DD
2561 ><DT
2562 ><SPAN
2563 CLASS="TOKEN"
2564 >{}</SPAN
2565 ></DT
2566 ><DD
2567 ><DIV
2568 CLASS="FORMALPARA"
2569 ><P
2570 ><B
2571 >placeholder for text. </B
2572 >Used after <A
2573 HREF="moreadv.html#XARGSCURLYREF"
2574 >xargs
2575 <TT
2576 CLASS="OPTION"
2577 >-i</TT
2578 ></A
2579 > (<I
2580 CLASS="FIRSTTERM"
2581 >replace
2582 strings</I
2583 > option). The <SPAN
2584 CLASS="TOKEN"
2585 >{}</SPAN
2586 > double
2587 curly brackets are a placeholder for output text.</P
2588 ></DIV
2589 ><P
2590 ><TABLE
2591 BORDER="0"
2592 BGCOLOR="#E0E0E0"
2593 WIDTH="90%"
2594 ><TR
2595 ><TD
2596 ><PRE
2597 CLASS="PROGRAMLISTING"
2598 > 1&nbsp;ls . | xargs -i -t cp ./{} $1
2599 2&nbsp;# ^^ ^^
2600 3&nbsp;
2601 4&nbsp;# From "ex42.sh" (copydir.sh) example.</PRE
2602 ></TD
2603 ></TR
2604 ></TABLE
2605 ></P
2606 ><P
2607 ><A
2608 NAME="SEMICOLONESC"
2609 ></A
2610 ></P
2611 ></DD
2612 ><DT
2613 ><SPAN
2614 CLASS="TOKEN"
2615 >{} \;</SPAN
2616 ></DT
2617 ><DD
2618 ><DIV
2619 CLASS="FORMALPARA"
2620 ><P
2621 ><B
2622 >pathname. </B
2623 >Mostly used in <A
2624 HREF="moreadv.html#FINDREF"
2625 >find</A
2626 >
2627 constructs. This is <SPAN
2628 CLASS="emphasis"
2629 ><I
2630 CLASS="EMPHASIS"
2631 >not</I
2632 ></SPAN
2633 > a shell
2634 <A
2635 HREF="internal.html#BUILTINREF"
2636 >builtin</A
2637 >.</P
2638 ></DIV
2639 ><TABLE
2640 CLASS="SIDEBAR"
2641 BORDER="1"
2642 CELLPADDING="5"
2643 ><TR
2644 ><TD
2645 ><DIV
2646 CLASS="SIDEBAR"
2647 ><A
2648 NAME="AEN1234"
2649 ></A
2650 ><P
2651 ><A
2652 NAME="PATHNAMEREF"
2653 ></A
2654 ></P
2655 ><P
2656 >Definition: A <I
2657 CLASS="FIRSTTERM"
2658 >pathname</I
2659 >
2660 is a <I
2661 CLASS="FIRSTTERM"
2662 >filename</I
2663 > that includes the
2664 complete <A
2665 HREF="variables2.html#PATHREF"
2666 >path</A
2667 >. As an example,
2668 <TT
2669 CLASS="FILENAME"
2670 >/home/bozo/Notes/Thursday/schedule.txt</TT
2671 >.
2672 This is sometimes referred to as the <I
2673 CLASS="FIRSTTERM"
2674 >absolute
2675 path</I
2676 >.</P
2677 ></DIV
2678 ></TD
2679 ></TR
2680 ></TABLE
2681 ><DIV
2682 CLASS="NOTE"
2683 ><TABLE
2684 CLASS="NOTE"
2685 WIDTH="90%"
2686 BORDER="0"
2687 ><TR
2688 ><TD
2689 WIDTH="25"
2690 ALIGN="CENTER"
2691 VALIGN="TOP"
2692 ><IMG
2693 SRC="common/note.png"
2694 HSPACE="5"
2695 ALT="Note"></TD
2696 ><TD
2697 ALIGN="LEFT"
2698 VALIGN="TOP"
2699 ><P
2700 >The <SPAN
2701 CLASS="QUOTE"
2702 >"<SPAN
2703 CLASS="TOKEN"
2704 >;</SPAN
2705 >"</SPAN
2706 > ends
2707 the <TT
2708 CLASS="OPTION"
2709 >-exec</TT
2710 > option of a
2711 <B
2712 CLASS="COMMAND"
2713 >find</B
2714 > command sequence. It needs
2715 to be escaped to protect it from interpretation by the
2716 shell.</P
2717 ></TD
2718 ></TR
2719 ></TABLE
2720 ></DIV
2721 ></DD
2722 ><DT
2723 ><A
2724 NAME="LEFTBRACKET"
2725 ></A
2726 ><SPAN
2727 CLASS="TOKEN"
2728 >[ ]</SPAN
2729 ></DT
2730 ><DD
2731 ><DIV
2732 CLASS="FORMALPARA"
2733 ><P
2734 ><B
2735 >test. </B
2736 ><A
2737 NAME="BRACKTEST"
2738 ></A
2739 ></P
2740 ></DIV
2741 ><P
2742 ><A
2743 HREF="tests.html#IFTHEN"
2744 >Test</A
2745 > expression between
2746 <B
2747 CLASS="COMMAND"
2748 >[ ]</B
2749 >. Note that <B
2750 CLASS="COMMAND"
2751 >[</B
2752 >
2753 is part of the shell <I
2754 CLASS="FIRSTTERM"
2755 >builtin</I
2756 > <A
2757 HREF="tests.html#TTESTREF"
2758 >test</A
2759 > (and a synonym for it),
2760 <SPAN
2761 CLASS="emphasis"
2762 ><I
2763 CLASS="EMPHASIS"
2764 >not</I
2765 ></SPAN
2766 > a link to the external command
2767 <TT
2768 CLASS="FILENAME"
2769 >/usr/bin/test</TT
2770 >.</P
2771 ></DD
2772 ><DT
2773 ><SPAN
2774 CLASS="TOKEN"
2775 >[[ ]]</SPAN
2776 ></DT
2777 ><DD
2778 ><DIV
2779 CLASS="FORMALPARA"
2780 ><P
2781 ><B
2782 >test. </B
2783 ></P
2784 ></DIV
2785 ><P
2786 >Test expression between <SPAN
2787 CLASS="TOKEN"
2788 >[[ ]]</SPAN
2789 >. More
2790 flexible than the single-bracket <SPAN
2791 CLASS="TOKEN"
2792 >[ ]</SPAN
2793 > test,
2794 this is a shell <A
2795 HREF="internal.html#KEYWORDREF"
2796 >keyword</A
2797 >.</P
2798 ><P
2799 >See the
2800 discussion on the <A
2801 HREF="tests.html#DBLBRACKETS"
2802 >[[ ... ]]
2803 construct</A
2804 >.</P
2805 ></DD
2806 ><DT
2807 ><SPAN
2808 CLASS="TOKEN"
2809 >[ ]</SPAN
2810 ></DT
2811 ><DD
2812 ><DIV
2813 CLASS="FORMALPARA"
2814 ><P
2815 ><B
2816 >array element. </B
2817 ></P
2818 ></DIV
2819 ><P
2820 >In the context of an <A
2821 HREF="arrays.html#ARRAYREF"
2822 >array</A
2823 >,
2824 brackets set off the numbering of each element of that array.
2825 <TABLE
2826 BORDER="0"
2827 BGCOLOR="#E0E0E0"
2828 WIDTH="90%"
2829 ><TR
2830 ><TD
2831 ><PRE
2832 CLASS="PROGRAMLISTING"
2833 > 1&nbsp;Array[1]=slot_1
2834 2&nbsp;echo ${Array[1]}</PRE
2835 ></TD
2836 ></TR
2837 ></TABLE
2838 ></P
2839 ></DD
2840 ><DT
2841 ><SPAN
2842 CLASS="TOKEN"
2843 >[ ]</SPAN
2844 ></DT
2845 ><DD
2846 ><DIV
2847 CLASS="FORMALPARA"
2848 ><P
2849 ><B
2850 >range of characters. </B
2851 ></P
2852 ></DIV
2853 ><P
2854 >As part of a <A
2855 HREF="regexp.html#REGEXREF"
2856 >regular
2857 expression</A
2858 >, brackets delineate a <A
2859 HREF="regexp.html#BRACKETSREF"
2860 >range of characters</A
2861 > to
2862 match.</P
2863 ></DD
2864 ><DT
2865 ><A
2866 NAME="BRACKETARITH"
2867 ></A
2868 ><SPAN
2869 CLASS="TOKEN"
2870 >$[ ... ]</SPAN
2871 ></DT
2872 ><DD
2873 ><DIV
2874 CLASS="FORMALPARA"
2875 ><P
2876 ><B
2877 >integer expansion. </B
2878 ></P
2879 ></DIV
2880 ><P
2881 >Evaluate integer expression between
2882 <SPAN
2883 CLASS="TOKEN"
2884 >$[ ]</SPAN
2885 >.
2886 <TABLE
2887 BORDER="0"
2888 BGCOLOR="#E0E0E0"
2889 WIDTH="90%"
2890 ><TR
2891 ><TD
2892 ><PRE
2893 CLASS="PROGRAMLISTING"
2894 > 1&nbsp;a=3
2895 2&nbsp;b=7
2896 3&nbsp;
2897 4&nbsp;echo $[$a+$b] # 10
2898 5&nbsp;echo $[$a*$b] # 21</PRE
2899 ></TD
2900 ></TR
2901 ></TABLE
2902 ></P
2903 ><P
2904 >Note that this usage is <SPAN
2905 CLASS="emphasis"
2906 ><I
2907 CLASS="EMPHASIS"
2908 >deprecated</I
2909 ></SPAN
2910 >,
2911 and has been replaced by the
2912 <A
2913 HREF="dblparens.html"
2914 >(( ... ))</A
2915 > construct.</P
2916 ></DD
2917 ><DT
2918 ><SPAN
2919 CLASS="TOKEN"
2920 >(( ))</SPAN
2921 ></DT
2922 ><DD
2923 ><DIV
2924 CLASS="FORMALPARA"
2925 ><P
2926 ><B
2927 >integer expansion. </B
2928 ></P
2929 ></DIV
2930 ><P
2931 >Expand and evaluate integer expression between
2932 <SPAN
2933 CLASS="TOKEN"
2934 >(( ))</SPAN
2935 >.</P
2936 ><P
2937 >See the discussion on the <A
2938 HREF="dblparens.html"
2939 >(( ... )) construct</A
2940 >.</P
2941 ></DD
2942 ><DT
2943 ><SPAN
2944 CLASS="TOKEN"
2945 >&#62;</SPAN
2946 > <SPAN
2947 CLASS="TOKEN"
2948 >&#38;&#62;</SPAN
2949 > <SPAN
2950 CLASS="TOKEN"
2951 >&#62;&#38;</SPAN
2952 > <SPAN
2953 CLASS="TOKEN"
2954 >&#62;&#62;</SPAN
2955 > <SPAN
2956 CLASS="TOKEN"
2957 >&#60;</SPAN
2958 > <SPAN
2959 CLASS="TOKEN"
2960 >&#60;&#62;</SPAN
2961 ></DT
2962 ><DD
2963 ><DIV
2964 CLASS="FORMALPARA"
2965 ><P
2966 ><B
2967 ><A
2968 HREF="io-redirection.html#IOREDIRREF"
2969 >redirection</A
2970 >. </B
2971 ></P
2972 ></DIV
2973 ><P
2974 ><TT
2975 CLASS="USERINPUT"
2976 ><B
2977 >scriptname &#62;filename</B
2978 ></TT
2979 > redirects the output of
2980 <TT
2981 CLASS="FILENAME"
2982 >scriptname</TT
2983 > to file
2984 <TT
2985 CLASS="FILENAME"
2986 >filename</TT
2987 >. Overwrite
2988 <TT
2989 CLASS="FILENAME"
2990 >filename</TT
2991 > if it already exists.</P
2992 ><P
2993 ><A
2994 NAME="REDIROUTERROR"
2995 ></A
2996 ></P
2997 ><P
2998 ><TT
2999 CLASS="USERINPUT"
3000 ><B
3001 >command &#38;&#62;filename</B
3002 ></TT
3003 > redirects
3004 both the <A
3005 HREF="ioredirintro.html#STDINOUTDEF"
3006 ><TT
3007 CLASS="FILENAME"
3008 >stdout</TT
3009 ></A
3010 >
3011 and the
3012 <TT
3013 CLASS="FILENAME"
3014 >stderr</TT
3015 > of <TT
3016 CLASS="FILENAME"
3017 >command</TT
3018 >
3019 to <TT
3020 CLASS="FILENAME"
3021 >filename</TT
3022 >.</P
3023 ><DIV
3024 CLASS="NOTE"
3025 ><TABLE
3026 CLASS="NOTE"
3027 WIDTH="90%"
3028 BORDER="0"
3029 ><TR
3030 ><TD
3031 WIDTH="25"
3032 ALIGN="CENTER"
3033 VALIGN="TOP"
3034 ><IMG
3035 SRC="common/note.png"
3036 HSPACE="5"
3037 ALT="Note"></TD
3038 ><TD
3039 ALIGN="LEFT"
3040 VALIGN="TOP"
3041 ><P
3042 > <A
3043 NAME="DEVNULLREDIRECT"
3044 ></A
3045 >
3046 This is useful for suppressing output when
3047 testing for a condition. For example, let us
3048 test whether a certain command exists.
3049 </P
3050 ><P
3051 > <TABLE
3052 BORDER="0"
3053 BGCOLOR="#E0E0E0"
3054 WIDTH="90%"
3055 ><TR
3056 ><TD
3057 ><PRE
3058 CLASS="SCREEN"
3059 > <TT
3060 CLASS="PROMPT"
3061 >bash$ </TT
3062 ><TT
3063 CLASS="USERINPUT"
3064 ><B
3065 >type bogus_command &#38;&#62;/dev/null</B
3066 ></TT
3067 >
3068 <TT
3069 CLASS="COMPUTEROUTPUT"
3070 ></TT
3071 >
3072
3073
3074 <TT
3075 CLASS="PROMPT"
3076 >bash$ </TT
3077 ><TT
3078 CLASS="USERINPUT"
3079 ><B
3080 >echo $?</B
3081 ></TT
3082 >
3083 <TT
3084 CLASS="COMPUTEROUTPUT"
3085 >1</TT
3086 >
3087 </PRE
3088 ></TD
3089 ></TR
3090 ></TABLE
3091 >
3092 </P
3093 ><P
3094 >Or in a script:</P
3095 ><P
3096 ><TABLE
3097 BORDER="0"
3098 BGCOLOR="#E0E0E0"
3099 WIDTH="90%"
3100 ><TR
3101 ><TD
3102 ><PRE
3103 CLASS="PROGRAMLISTING"
3104 > 1&nbsp;command_test () { type "$1" &#38;&#62;/dev/null; }
3105 2&nbsp;# ^
3106 3&nbsp;
3107 4&nbsp;cmd=rmdir # Legitimate command.
3108 5&nbsp;command_test $cmd; echo $? # 0
3109 6&nbsp;
3110 7&nbsp;
3111 8&nbsp;cmd=bogus_command # Illegitimate command
3112 9&nbsp;command_test $cmd; echo $? # 1</PRE
3113 ></TD
3114 ></TR
3115 ></TABLE
3116 ></P
3117 ></TD
3118 ></TR
3119 ></TABLE
3120 ></DIV
3121 ><P
3122 ><A
3123 NAME="REDIROUTERROR2"
3124 ></A
3125 ></P
3126 ><P
3127 ><TT
3128 CLASS="USERINPUT"
3129 ><B
3130 >command &#62;&#38;2</B
3131 ></TT
3132 > redirects
3133 <TT
3134 CLASS="FILENAME"
3135 >stdout</TT
3136 > of <TT
3137 CLASS="FILENAME"
3138 >command</TT
3139 >
3140 to <TT
3141 CLASS="FILENAME"
3142 >stderr</TT
3143 >.</P
3144 ><P
3145 ><TT
3146 CLASS="USERINPUT"
3147 ><B
3148 >scriptname &#62;&#62;filename</B
3149 ></TT
3150 > appends
3151 the output of <TT
3152 CLASS="FILENAME"
3153 >scriptname</TT
3154 >
3155 to file <TT
3156 CLASS="FILENAME"
3157 >filename</TT
3158 >. If
3159 <TT
3160 CLASS="FILENAME"
3161 >filename</TT
3162 > does not already exist,
3163 it is created.</P
3164 ><P
3165 ><A
3166 NAME="REDIRRW"
3167 ></A
3168 ></P
3169 ><P
3170 ><TT
3171 CLASS="USERINPUT"
3172 ><B
3173 >[i]&#60;&#62;filename</B
3174 ></TT
3175 >
3176 opens file <TT
3177 CLASS="FILENAME"
3178 >filename</TT
3179 > for reading
3180 and writing, and assigns <A
3181 HREF="io-redirection.html#FDREF"
3182 >file
3183 descriptor</A
3184 > <SPAN
3185 CLASS="TOKEN"
3186 >i</SPAN
3187 > to it. If
3188 <TT
3189 CLASS="FILENAME"
3190 >filename</TT
3191 > does not exist, it is
3192 created.</P
3193 ><DIV
3194 CLASS="FORMALPARA"
3195 ><P
3196 ><B
3197 ><A
3198 HREF="process-sub.html#PROCESSSUBREF"
3199 >process substitution</A
3200 >. </B
3201 ></P
3202 ></DIV
3203 ><P
3204 ><TT
3205 CLASS="USERINPUT"
3206 ><B
3207 >(command)&#62;</B
3208 ></TT
3209 ></P
3210 ><P
3211 ><TT
3212 CLASS="USERINPUT"
3213 ><B
3214 >&#60;(command)</B
3215 ></TT
3216 ></P
3217 ><P
3218 ><A
3219 HREF="comparison-ops.html#LTREF"
3220 >In a different context</A
3221 >,
3222 the <SPAN
3223 CLASS="QUOTE"
3224 >"<SPAN
3225 CLASS="TOKEN"
3226 >&#60;</SPAN
3227 >"</SPAN
3228 > and
3229 <SPAN
3230 CLASS="QUOTE"
3231 >"<SPAN
3232 CLASS="TOKEN"
3233 >&#62;</SPAN
3234 >"</SPAN
3235 > characters act
3236 as <A
3237 HREF="comparison-ops.html#SCOMPARISON1"
3238 >string comparison
3239 operators</A
3240 >.</P
3241 ><P
3242 ><A
3243 HREF="comparison-ops.html#INTLT"
3244 >In yet another context</A
3245 >,
3246 the <SPAN
3247 CLASS="QUOTE"
3248 >"<SPAN
3249 CLASS="TOKEN"
3250 >&#60;</SPAN
3251 >"</SPAN
3252 > and
3253 <SPAN
3254 CLASS="QUOTE"
3255 >"<SPAN
3256 CLASS="TOKEN"
3257 >&#62;</SPAN
3258 >"</SPAN
3259 > characters act
3260 as <A
3261 HREF="comparison-ops.html#ICOMPARISON1"
3262 >integer comparison
3263 operators</A
3264 >. See also <A
3265 HREF="moreadv.html#EX45"
3266 >Example 16-9</A
3267 >.</P
3268 ></DD
3269 ><DT
3270 ><A
3271 NAME="HEREDOCRRREF"
3272 ></A
3273 ><SPAN
3274 CLASS="TOKEN"
3275 >&#60;&#60;</SPAN
3276 ></DT
3277 ><DD
3278 ><DIV
3279 CLASS="FORMALPARA"
3280 ><P
3281 ><B
3282 >redirection used in a <A
3283 HREF="here-docs.html#HEREDOCREF"
3284 >here document</A
3285 >. </B
3286 ></P
3287 ></DIV
3288 ></DD
3289 ><DT
3290 ><A
3291 NAME="HERESTRINGREF"
3292 ></A
3293 ><SPAN
3294 CLASS="TOKEN"
3295 >&#60;&#60;&#60;</SPAN
3296 ></DT
3297 ><DD
3298 ><DIV
3299 CLASS="FORMALPARA"
3300 ><P
3301 ><B
3302 >redirection used in a <A
3303 HREF="here-docs.html#HERESTRINGSREF"
3304 >here string</A
3305 >. </B
3306 ></P
3307 ></DIV
3308 ></DD
3309 ><DT
3310 ><SPAN
3311 CLASS="TOKEN"
3312 >&#60;</SPAN
3313 >, <SPAN
3314 CLASS="TOKEN"
3315 >&#62;</SPAN
3316 ></DT
3317 ><DD
3318 ><DIV
3319 CLASS="FORMALPARA"
3320 ><P
3321 ><B
3322 ><A
3323 HREF="comparison-ops.html#LTREF"
3324 >ASCII
3325 comparison</A
3326 >. </B
3327 ><TABLE
3328 BORDER="0"
3329 BGCOLOR="#E0E0E0"
3330 WIDTH="90%"
3331 ><TR
3332 ><TD
3333 ><PRE
3334 CLASS="PROGRAMLISTING"
3335 > 1&nbsp;veg1=carrots
3336 2&nbsp;veg2=tomatoes
3337 3&nbsp;
3338 4&nbsp;if [[ "$veg1" &#60; "$veg2" ]]
3339 5&nbsp;then
3340 6&nbsp; echo "Although $veg1 precede $veg2 in the dictionary,"
3341 7&nbsp; echo -n "this does not necessarily imply anything "
3342 8&nbsp; echo "about my culinary preferences."
3343 9&nbsp;else
3344 10&nbsp; echo "What kind of dictionary are you using, anyhow?"
3345 11&nbsp;fi</PRE
3346 ></TD
3347 ></TR
3348 ></TABLE
3349 ></P
3350 ></DIV
3351 ></DD
3352 ><DT
3353 ><SPAN
3354 CLASS="TOKEN"
3355 >\&#60;</SPAN
3356 >, <SPAN
3357 CLASS="TOKEN"
3358 >\&#62;</SPAN
3359 ></DT
3360 ><DD
3361 ><DIV
3362 CLASS="FORMALPARA"
3363 ><P
3364 ><B
3365 ><A
3366 HREF="regexp.html#ANGLEBRAC"
3367 >word
3368 boundary</A
3369 > in a <A
3370 HREF="regexp.html#REGEXREF"
3371 >regular
3372 expression</A
3373 >. </B
3374 ></P
3375 ></DIV
3376 ><P
3377 ><TT
3378 CLASS="PROMPT"
3379 >bash$ </TT
3380 ><TT
3381 CLASS="USERINPUT"
3382 ><B
3383 >grep '\&#60;the\&#62;' textfile</B
3384 ></TT
3385 ></P
3386 ></DD
3387 ><DT
3388 ><SPAN
3389 CLASS="TOKEN"
3390 >|</SPAN
3391 ></DT
3392 ><DD
3393 ><P
3394 ><A
3395 NAME="PIPEREF"
3396 ></A
3397 ></P
3398 ><DIV
3399 CLASS="FORMALPARA"
3400 ><P
3401 ><B
3402 >pipe. </B
3403 >Passes the output (<TT
3404 CLASS="FILENAME"
3405 >stdout</TT
3406 >)
3407 of a previous command to the input
3408 (<TT
3409 CLASS="FILENAME"
3410 >stdin</TT
3411 >) of the next one, or
3412 to the shell. This is a method of chaining commands
3413 together.</P
3414 ></DIV
3415 ><P
3416 > <TABLE
3417 BORDER="0"
3418 BGCOLOR="#E0E0E0"
3419 WIDTH="90%"
3420 ><TR
3421 ><TD
3422 ><PRE
3423 CLASS="PROGRAMLISTING"
3424 > 1&nbsp;echo ls -l | sh
3425 2&nbsp;# Passes the output of "echo ls -l" to the shell,
3426 3&nbsp;#+ with the same result as a simple "ls -l".
3427 4&nbsp;
3428 5&nbsp;
3429 6&nbsp;cat *.lst | sort | uniq
3430 7&nbsp;# Merges and sorts all ".lst" files, then deletes duplicate lines.</PRE
3431 ></TD
3432 ></TR
3433 ></TABLE
3434 >
3435 </P
3436 ><TABLE
3437 CLASS="SIDEBAR"
3438 BORDER="1"
3439 CELLPADDING="5"
3440 ><TR
3441 ><TD
3442 ><DIV
3443 CLASS="SIDEBAR"
3444 ><A
3445 NAME="AEN1555"
3446 ></A
3447 ><P
3448 > A pipe, as a classic method of interprocess
3449 communication, sends the <TT
3450 CLASS="FILENAME"
3451 >stdout</TT
3452 >
3453 of one <A
3454 HREF="special-chars.html#PROCESSREF"
3455 >process</A
3456 > to the
3457 <TT
3458 CLASS="FILENAME"
3459 >stdin</TT
3460 > of another. In a typical case,
3461 a command, such as <A
3462 HREF="external.html#CATREF"
3463 >cat</A
3464 > or
3465 <A
3466 HREF="internal.html#ECHOREF"
3467 >echo</A
3468 >, pipes a stream of
3469 data to a
3470 <A
3471 NAME="FILTERDEF"
3472 ></A
3473 >
3474 <I
3475 CLASS="FIRSTTERM"
3476 >filter</I
3477 >, a command that
3478 transforms its input for processing.
3479 <A
3480 NAME="AEN1564"
3481 HREF="#FTN.AEN1564"
3482 >[7]</A
3483 >
3484 </P
3485 ><P
3486 >
3487 <TT
3488 CLASS="USERINPUT"
3489 ><B
3490 >cat $filename1 $filename2 | grep $search_word</B
3491 ></TT
3492 >
3493 </P
3494 ><P
3495 >For an interesting note on the complexity of using UNIX
3496 pipes, see <A
3497 HREF="http://www.faqs.org/faqs/unix-faq/faq/part3/"
3498 TARGET="_top"
3499 >the UNIX FAQ,
3500 Part 3</A
3501 >.</P
3502 ></DIV
3503 ></TD
3504 ></TR
3505 ></TABLE
3506 ><P
3507 ><A
3508 NAME="UCREF"
3509 ></A
3510 >The output of a command or commands
3511 may be piped to a script.
3512
3513 <TABLE
3514 BORDER="0"
3515 BGCOLOR="#E0E0E0"
3516 WIDTH="90%"
3517 ><TR
3518 ><TD
3519 ><PRE
3520 CLASS="PROGRAMLISTING"
3521 > 1&nbsp;#!/bin/bash
3522 2&nbsp;# uppercase.sh : Changes input to uppercase.
3523 3&nbsp;
3524 4&nbsp;tr 'a-z' 'A-Z'
3525 5&nbsp;# Letter ranges must be quoted
3526 6&nbsp;#+ to prevent filename generation from single-letter filenames.
3527 7&nbsp;
3528 8&nbsp;exit 0</PRE
3529 ></TD
3530 ></TR
3531 ></TABLE
3532 >
3533 Now, let us pipe the output of <B
3534 CLASS="COMMAND"
3535 >ls -l</B
3536 > to this
3537 script.
3538
3539 <TABLE
3540 BORDER="0"
3541 BGCOLOR="#E0E0E0"
3542 WIDTH="90%"
3543 ><TR
3544 ><TD
3545 ><PRE
3546 CLASS="SCREEN"
3547 > <TT
3548 CLASS="PROMPT"
3549 >bash$ </TT
3550 ><TT
3551 CLASS="USERINPUT"
3552 ><B
3553 >ls -l | ./uppercase.sh</B
3554 ></TT
3555 >
3556 <TT
3557 CLASS="COMPUTEROUTPUT"
3558 >-RW-RW-R-- 1 BOZO BOZO 109 APR 7 19:49 1.TXT
3559 -RW-RW-R-- 1 BOZO BOZO 109 APR 14 16:48 2.TXT
3560 -RW-R--R-- 1 BOZO BOZO 725 APR 20 20:56 DATA-FILE</TT
3561 >
3562 </PRE
3563 ></TD
3564 ></TR
3565 ></TABLE
3566 >
3567 </P
3568 ><DIV
3569 CLASS="NOTE"
3570 ><TABLE
3571 CLASS="NOTE"
3572 WIDTH="90%"
3573 BORDER="0"
3574 ><TR
3575 ><TD
3576 WIDTH="25"
3577 ALIGN="CENTER"
3578 VALIGN="TOP"
3579 ><IMG
3580 SRC="common/note.png"
3581 HSPACE="5"
3582 ALT="Note"></TD
3583 ><TD
3584 ALIGN="LEFT"
3585 VALIGN="TOP"
3586 ><P
3587 >The <TT
3588 CLASS="FILENAME"
3589 >stdout</TT
3590 > of each process in
3591 a pipe must be read as the <TT
3592 CLASS="FILENAME"
3593 >stdin</TT
3594 >
3595 of the next. If this is not the case, the data stream
3596 will <I
3597 CLASS="FIRSTTERM"
3598 >block</I
3599 >, and the pipe will not
3600 behave as expected.
3601 <TABLE
3602 BORDER="0"
3603 BGCOLOR="#E0E0E0"
3604 WIDTH="90%"
3605 ><TR
3606 ><TD
3607 ><PRE
3608 CLASS="PROGRAMLISTING"
3609 > 1&nbsp;cat file1 file2 | ls -l | sort
3610 2&nbsp;# The output from "cat file1 file2" disappears.</PRE
3611 ></TD
3612 ></TR
3613 ></TABLE
3614 >
3615 </P
3616 ><P
3617 >A pipe runs as a <A
3618 HREF="othertypesv.html#CHILDREF"
3619 >child
3620 process</A
3621 >, and therefore cannot alter script
3622 variables.
3623 <TABLE
3624 BORDER="0"
3625 BGCOLOR="#E0E0E0"
3626 WIDTH="90%"
3627 ><TR
3628 ><TD
3629 ><PRE
3630 CLASS="PROGRAMLISTING"
3631 > 1&nbsp;variable="initial_value"
3632 2&nbsp;echo "new_value" | read variable
3633 3&nbsp;echo "variable = $variable" # variable = initial_value</PRE
3634 ></TD
3635 ></TR
3636 ></TABLE
3637 >
3638 </P
3639 ><P
3640 >If one of the commands in the pipe
3641 aborts, this prematurely terminates execution of the
3642 pipe. Called a <I
3643 CLASS="FIRSTTERM"
3644 >broken pipe</I
3645 >, this
3646 condition sends a <TT
3647 CLASS="REPLACEABLE"
3648 ><I
3649 >SIGPIPE</I
3650 ></TT
3651 > <A
3652 HREF="debugging.html#SIGNALD"
3653 >signal</A
3654 >.</P
3655 ></TD
3656 ></TR
3657 ></TABLE
3658 ></DIV
3659 ></DD
3660 ><DT
3661 ><SPAN
3662 CLASS="TOKEN"
3663 >&#62;|</SPAN
3664 ></DT
3665 ><DD
3666 ><DIV
3667 CLASS="FORMALPARA"
3668 ><P
3669 ><B
3670 >force redirection (even if
3671 the <A
3672 HREF="options.html#NOCLOBBERREF"
3673 >noclobber option</A
3674 >
3675 is set). </B
3676 >This will forcibly overwrite an existing file.</P
3677 ></DIV
3678 ></DD
3679 ><DT
3680 ><SPAN
3681 CLASS="TOKEN"
3682 >||</SPAN
3683 ></DT
3684 ><DD
3685 ><DIV
3686 CLASS="FORMALPARA"
3687 ><P
3688 ><B
3689 ><A
3690 HREF="operations.html#ORREF"
3691 >OR logical operator</A
3692 >. </B
3693 >In a <A
3694 HREF="tests.html#TESTCONSTRUCTS1"
3695 >test
3696 construct</A
3697 >, the <SPAN
3698 CLASS="TOKEN"
3699 >||</SPAN
3700 > operator causes
3701 a return of <SPAN
3702 CLASS="RETURNVALUE"
3703 >0</SPAN
3704 > (success) if
3705 <SPAN
3706 CLASS="emphasis"
3707 ><I
3708 CLASS="EMPHASIS"
3709 >either</I
3710 ></SPAN
3711 > of the linked test conditions
3712 is true.</P
3713 ></DIV
3714 ></DD
3715 ><DT
3716 ><A
3717 NAME="BGJOB"
3718 ></A
3719 ><SPAN
3720 CLASS="TOKEN"
3721 >&#38;</SPAN
3722 ></DT
3723 ><DD
3724 ><DIV
3725 CLASS="FORMALPARA"
3726 ><P
3727 ><B
3728 >Run job in background. </B
3729 >A command followed by an <SPAN
3730 CLASS="TOKEN"
3731 >&#38;</SPAN
3732 >
3733 will run in the background.</P
3734 ></DIV
3735 ><P
3736 > <TABLE
3737 BORDER="0"
3738 BGCOLOR="#E0E0E0"
3739 WIDTH="90%"
3740 ><TR
3741 ><TD
3742 ><PRE
3743 CLASS="SCREEN"
3744 > <TT
3745 CLASS="PROMPT"
3746 >bash$ </TT
3747 ><TT
3748 CLASS="USERINPUT"
3749 ><B
3750 >sleep 10 &#38;</B
3751 ></TT
3752 >
3753 <TT
3754 CLASS="COMPUTEROUTPUT"
3755 >[1] 850</TT
3756 >
3757 <TT
3758 CLASS="COMPUTEROUTPUT"
3759 >[1]+ Done sleep 10</TT
3760 >
3761 </PRE
3762 ></TD
3763 ></TR
3764 ></TABLE
3765 >
3766 </P
3767 ><P
3768 >Within a script, commands and even <A
3769 HREF="loops.html#FORLOOPREF1"
3770 >loops</A
3771 > may run in the
3772 background.</P
3773 ><P
3774 ><A
3775 NAME="BGLOOP0"
3776 ></A
3777 ></P
3778 ><DIV
3779 CLASS="EXAMPLE"
3780 ><HR><A
3781 NAME="BGLOOP"
3782 ></A
3783 ><P
3784 ><B
3785 >Example 3-3. Running a loop in the background</B
3786 ></P
3787 ><TABLE
3788 BORDER="0"
3789 BGCOLOR="#E0E0E0"
3790 WIDTH="90%"
3791 ><TR
3792 ><TD
3793 ><PRE
3794 CLASS="PROGRAMLISTING"
3795 > 1&nbsp;#!/bin/bash
3796 2&nbsp;# background-loop.sh
3797 3&nbsp;
3798 4&nbsp;for i in 1 2 3 4 5 6 7 8 9 10 # First loop.
3799 5&nbsp;do
3800 6&nbsp; echo -n "$i "
3801 7&nbsp;done &#38; # Run this loop in background.
3802 8&nbsp; # Will sometimes execute after second loop.
3803 9&nbsp;
3804 10&nbsp;echo # This 'echo' sometimes will not display.
3805 11&nbsp;
3806 12&nbsp;for i in 11 12 13 14 15 16 17 18 19 20 # Second loop.
3807 13&nbsp;do
3808 14&nbsp; echo -n "$i "
3809 15&nbsp;done
3810 16&nbsp;
3811 17&nbsp;echo # This 'echo' sometimes will not display.
3812 18&nbsp;
3813 19&nbsp;# ======================================================
3814 20&nbsp;
3815 21&nbsp;# The expected output from the script:
3816 22&nbsp;# 1 2 3 4 5 6 7 8 9 10
3817 23&nbsp;# 11 12 13 14 15 16 17 18 19 20
3818 24&nbsp;
3819 25&nbsp;# Sometimes, though, you get:
3820 26&nbsp;# 11 12 13 14 15 16 17 18 19 20
3821 27&nbsp;# 1 2 3 4 5 6 7 8 9 10 bozo $
3822 28&nbsp;# (The second 'echo' doesn't execute. Why?)
3823 29&nbsp;
3824 30&nbsp;# Occasionally also:
3825 31&nbsp;# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
3826 32&nbsp;# (The first 'echo' doesn't execute. Why?)
3827 33&nbsp;
3828 34&nbsp;# Very rarely something like:
3829 35&nbsp;# 11 12 13 1 2 3 4 5 6 7 8 9 10 14 15 16 17 18 19 20
3830 36&nbsp;# The foreground loop preempts the background one.
3831 37&nbsp;
3832 38&nbsp;exit 0
3833 39&nbsp;
3834 40&nbsp;# Nasimuddin Ansari suggests adding sleep 1
3835 41&nbsp;#+ after the echo -n "$i" in lines 6 and 14,
3836 42&nbsp;#+ for some real fun.</PRE
3837 ></TD
3838 ></TR
3839 ></TABLE
3840 ><HR></DIV
3841 ><DIV
3842 CLASS="CAUTION"
3843 ><TABLE
3844 CLASS="CAUTION"
3845 WIDTH="90%"
3846 BORDER="0"
3847 ><TR
3848 ><TD
3849 WIDTH="25"
3850 ALIGN="CENTER"
3851 VALIGN="TOP"
3852 ><IMG
3853 SRC="common/caution.png"
3854 HSPACE="5"
3855 ALT="Caution"></TD
3856 ><TD
3857 ALIGN="LEFT"
3858 VALIGN="TOP"
3859 ><P
3860 >A command run in the background within a
3861 script may cause the script to hang, waiting
3862 for a keystroke. Fortunately, there is a <A
3863 HREF="internal.html#WAITHANG"
3864 >remedy</A
3865 > for this.</P
3866 ></TD
3867 ></TR
3868 ></TABLE
3869 ></DIV
3870 ></DD
3871 ><DT
3872 ><A
3873 NAME="LOGICALAND"
3874 ></A
3875 ><SPAN
3876 CLASS="TOKEN"
3877 >&#38;&#38;</SPAN
3878 ></DT
3879 ><DD
3880 ><DIV
3881 CLASS="FORMALPARA"
3882 ><P
3883 ><B
3884 ><A
3885 HREF="operations.html#LOGOPS1"
3886 >AND logical
3887 operator</A
3888 >. </B
3889 >In a <A
3890 HREF="tests.html#TESTCONSTRUCTS1"
3891 >test
3892 construct</A
3893 >, the <SPAN
3894 CLASS="TOKEN"
3895 >&#38;&#38;</SPAN
3896 > operator causes
3897 a return of <SPAN
3898 CLASS="RETURNVALUE"
3899 >0</SPAN
3900 > (success) only if
3901 <SPAN
3902 CLASS="emphasis"
3903 ><I
3904 CLASS="EMPHASIS"
3905 >both</I
3906 ></SPAN
3907 > the linked test conditions
3908 are true.</P
3909 ></DIV
3910 ></DD
3911 ><DT
3912 ><A
3913 NAME="DASHREF"
3914 ></A
3915 ><SPAN
3916 CLASS="TOKEN"
3917 >-</SPAN
3918 ></DT
3919 ><DD
3920 ><DIV
3921 CLASS="FORMALPARA"
3922 ><P
3923 ><B
3924 >option, prefix. </B
3925 >Option flag for a command or filter. Prefix for
3926 an operator. Prefix for a <A
3927 HREF="parameter-substitution.html#DEFPARAM1"
3928 >default parameter</A
3929 >
3930 in <A
3931 HREF="parameter-substitution.html#PARAMSUBREF"
3932 >parameter
3933 substitution</A
3934 >.</P
3935 ></DIV
3936 ><P
3937 ><TT
3938 CLASS="USERINPUT"
3939 ><B
3940 >COMMAND -[Option1][Option2][...]</B
3941 ></TT
3942 ></P
3943 ><P
3944 ><TT
3945 CLASS="USERINPUT"
3946 ><B
3947 >ls -al</B
3948 ></TT
3949 ></P
3950 ><P
3951 ><TT
3952 CLASS="USERINPUT"
3953 ><B
3954 >sort -dfu $filename</B
3955 ></TT
3956 ></P
3957 ><P
3958 > <TABLE
3959 BORDER="0"
3960 BGCOLOR="#E0E0E0"
3961 WIDTH="90%"
3962 ><TR
3963 ><TD
3964 ><PRE
3965 CLASS="PROGRAMLISTING"
3966 > 1&nbsp;if [ $file1 -ot $file2 ]
3967 2&nbsp;then # ^
3968 3&nbsp; echo "File $file1 is older than $file2."
3969 4&nbsp;fi
3970 5&nbsp;
3971 6&nbsp;if [ "$a" -eq "$b" ]
3972 7&nbsp;then # ^
3973 8&nbsp; echo "$a is equal to $b."
3974 9&nbsp;fi
3975 10&nbsp;
3976 11&nbsp;if [ "$c" -eq 24 -a "$d" -eq 47 ]
3977 12&nbsp;then # ^ ^
3978 13&nbsp; echo "$c equals 24 and $d equals 47."
3979 14&nbsp;fi
3980 15&nbsp;
3981 16&nbsp;
3982 17&nbsp;param2=${param1:-$DEFAULTVAL}
3983 18&nbsp;# ^</PRE
3984 ></TD
3985 ></TR
3986 ></TABLE
3987 >
3988 </P
3989 ><P
3990 ><A
3991 NAME="DOUBLEDASHREF"
3992 ></A
3993 ></P
3994 ><P
3995 ><B
3996 CLASS="COMMAND"
3997 >--</B
3998 ></P
3999 ><P
4000 >The <I
4001 CLASS="FIRSTTERM"
4002 >double-dash</I
4003 >
4004 <TT
4005 CLASS="OPTION"
4006 >--</TT
4007 > prefixes <I
4008 CLASS="FIRSTTERM"
4009 >long</I
4010 >
4011 (verbatim) options to commands.</P
4012 ><P
4013 ><TT
4014 CLASS="USERINPUT"
4015 ><B
4016 >sort --ignore-leading-blanks</B
4017 ></TT
4018 ></P
4019 ><P
4020 >Used with a <A
4021 HREF="internal.html#BUILTINREF"
4022 >Bash
4023 builtin</A
4024 >, it means the <I
4025 CLASS="FIRSTTERM"
4026 >end of
4027 options</I
4028 > to that particular command.</P
4029 ><DIV
4030 CLASS="TIP"
4031 ><TABLE
4032 CLASS="TIP"
4033 WIDTH="90%"
4034 BORDER="0"
4035 ><TR
4036 ><TD
4037 WIDTH="25"
4038 ALIGN="CENTER"
4039 VALIGN="TOP"
4040 ><IMG
4041 SRC="common/tip.png"
4042 HSPACE="5"
4043 ALT="Tip"></TD
4044 ><TD
4045 ALIGN="LEFT"
4046 VALIGN="TOP"
4047 ><P
4048 >This provides a handy means of removing
4049 files whose <SPAN
4050 CLASS="emphasis"
4051 ><I
4052 CLASS="EMPHASIS"
4053 >names begin with a dash</I
4054 ></SPAN
4055 >.
4056 <TABLE
4057 BORDER="0"
4058 BGCOLOR="#E0E0E0"
4059 WIDTH="90%"
4060 ><TR
4061 ><TD
4062 ><PRE
4063 CLASS="SCREEN"
4064 > <TT
4065 CLASS="PROMPT"
4066 >bash$ </TT
4067 ><TT
4068 CLASS="USERINPUT"
4069 ><B
4070 >ls -l</B
4071 ></TT
4072 >
4073 <TT
4074 CLASS="COMPUTEROUTPUT"
4075 >-rw-r--r-- 1 bozo bozo 0 Nov 25 12:29 -badname</TT
4076 >
4077
4078
4079 <TT
4080 CLASS="PROMPT"
4081 >bash$ </TT
4082 ><TT
4083 CLASS="USERINPUT"
4084 ><B
4085 >rm -- -badname</B
4086 ></TT
4087 >
4088
4089 <TT
4090 CLASS="PROMPT"
4091 >bash$ </TT
4092 ><TT
4093 CLASS="USERINPUT"
4094 ><B
4095 >ls -l</B
4096 ></TT
4097 >
4098 <TT
4099 CLASS="COMPUTEROUTPUT"
4100 >total 0</TT
4101 ></PRE
4102 ></TD
4103 ></TR
4104 ></TABLE
4105 >
4106 </P
4107 ></TD
4108 ></TR
4109 ></TABLE
4110 ></DIV
4111 ><P
4112 >The <I
4113 CLASS="FIRSTTERM"
4114 >double-dash</I
4115 > is also used in
4116 conjunction with <A
4117 HREF="internal.html#SETREF"
4118 >set</A
4119 >.</P
4120 ><P
4121 ><TT
4122 CLASS="USERINPUT"
4123 ><B
4124 >set -- $variable</B
4125 ></TT
4126 > (as in <A
4127 HREF="internal.html#SETPOS"
4128 >Example 15-18</A
4129 >)</P
4130 ></DD
4131 ><DT
4132 ><A
4133 NAME="DASHREF2"
4134 ></A
4135 ><SPAN
4136 CLASS="TOKEN"
4137 >-</SPAN
4138 ></DT
4139 ><DD
4140 ><DIV
4141 CLASS="FORMALPARA"
4142 ><P
4143 ><B
4144 >redirection from/to <TT
4145 CLASS="FILENAME"
4146 >stdin</TT
4147 > or <TT
4148 CLASS="FILENAME"
4149 >stdout</TT
4150 > [dash]. </B
4151 ><A
4152 NAME="COXEX"
4153 ></A
4154 ></P
4155 ></DIV
4156 ><P
4157 > <TABLE
4158 BORDER="0"
4159 BGCOLOR="#E0E0E0"
4160 WIDTH="90%"
4161 ><TR
4162 ><TD
4163 ><PRE
4164 CLASS="SCREEN"
4165 > <TT
4166 CLASS="PROMPT"
4167 >bash$ </TT
4168 ><TT
4169 CLASS="USERINPUT"
4170 ><B
4171 >cat -</B
4172 ></TT
4173 >
4174 <TT
4175 CLASS="USERINPUT"
4176 ><B
4177 >abc</B
4178 ></TT
4179 >
4180 <TT
4181 CLASS="COMPUTEROUTPUT"
4182 >abc</TT
4183 >
4184
4185 <TT
4186 CLASS="COMPUTEROUTPUT"
4187 >...</TT
4188 >
4189
4190 <TT
4191 CLASS="USERINPUT"
4192 ><B
4193 >Ctl-D</B
4194 ></TT
4195 ></PRE
4196 ></TD
4197 ></TR
4198 ></TABLE
4199 >
4200 </P
4201 ><P
4202 >As expected, <TT
4203 CLASS="USERINPUT"
4204 ><B
4205 >cat -</B
4206 ></TT
4207 > echoes
4208 <TT
4209 CLASS="FILENAME"
4210 >stdin</TT
4211 >, in this case keyboarded user input,
4212 to <TT
4213 CLASS="FILENAME"
4214 >stdout</TT
4215 >. But, does I/O redirection using
4216 <B
4217 CLASS="COMMAND"
4218 >-</B
4219 > have real-world applications?</P
4220 ><P
4221 ><TABLE
4222 BORDER="0"
4223 BGCOLOR="#E0E0E0"
4224 WIDTH="90%"
4225 ><TR
4226 ><TD
4227 ><PRE
4228 CLASS="PROGRAMLISTING"
4229 > 1&nbsp;(cd /source/directory &#38;&#38; tar cf - . ) | (cd /dest/directory &#38;&#38; tar xpvf -)
4230 2&nbsp;# Move entire file tree from one directory to another
4231 3&nbsp;# [courtesy Alan Cox &#60;[email protected]&#62;, with a minor change]
4232 4&nbsp;
4233 5&nbsp;# 1) cd /source/directory
4234 6&nbsp;# Source directory, where the files to be moved are.
4235 7&nbsp;# 2) &#38;&#38;
4236 8&nbsp;# "And-list": if the 'cd' operation successful,
4237 9&nbsp;# then execute the next command.
4238 10&nbsp;# 3) tar cf - .
4239 11&nbsp;# The 'c' option 'tar' archiving command creates a new archive,
4240 12&nbsp;# the 'f' (file) option, followed by '-' designates the target file
4241 13&nbsp;# as stdout, and do it in current directory tree ('.').
4242 14&nbsp;# 4) |
4243 15&nbsp;# Piped to ...
4244 16&nbsp;# 5) ( ... )
4245 17&nbsp;# a subshell
4246 18&nbsp;# 6) cd /dest/directory
4247 19&nbsp;# Change to the destination directory.
4248 20&nbsp;# 7) &#38;&#38;
4249 21&nbsp;# "And-list", as above
4250 22&nbsp;# 8) tar xpvf -
4251 23&nbsp;# Unarchive ('x'), preserve ownership and file permissions ('p'),
4252 24&nbsp;# and send verbose messages to stdout ('v'),
4253 25&nbsp;# reading data from stdin ('f' followed by '-').
4254 26&nbsp;#
4255 27&nbsp;# Note that 'x' is a command, and 'p', 'v', 'f' are options.
4256 28&nbsp;#
4257 29&nbsp;# Whew!
4258 30&nbsp;
4259 31&nbsp;
4260 32&nbsp;
4261 33&nbsp;# More elegant than, but equivalent to:
4262 34&nbsp;# cd source/directory
4263 35&nbsp;# tar cf - . | (cd ../dest/directory; tar xpvf -)
4264 36&nbsp;#
4265 37&nbsp;# Also having same effect:
4266 38&nbsp;# cp -a /source/directory/* /dest/directory
4267 39&nbsp;# Or:
4268 40&nbsp;# cp -a /source/directory/* /source/directory/.[^.]* /dest/directory
4269 41&nbsp;# If there are hidden files in /source/directory.</PRE
4270 ></TD
4271 ></TR
4272 ></TABLE
4273 ></P
4274 ><P
4275 ><TABLE
4276 BORDER="0"
4277 BGCOLOR="#E0E0E0"
4278 WIDTH="90%"
4279 ><TR
4280 ><TD
4281 ><PRE
4282 CLASS="PROGRAMLISTING"
4283 > 1&nbsp;bunzip2 -c linux-2.6.16.tar.bz2 | tar xvf -
4284 2&nbsp;# --uncompress tar file-- | --then pass it to "tar"--
4285 3&nbsp;# If "tar" has not been patched to handle "bunzip2",
4286 4&nbsp;#+ this needs to be done in two discrete steps, using a pipe.
4287 5&nbsp;# The purpose of the exercise is to unarchive "bzipped" kernel source.</PRE
4288 ></TD
4289 ></TR
4290 ></TABLE
4291 ></P
4292 ><P
4293 >Note that in this context the <SPAN
4294 CLASS="QUOTE"
4295 >"-"</SPAN
4296 > is not
4297 itself a Bash operator, but rather an option recognized by
4298 certain UNIX utilities that write to
4299 <TT
4300 CLASS="FILENAME"
4301 >stdout</TT
4302 >, such as <B
4303 CLASS="COMMAND"
4304 >tar</B
4305 >,
4306 <B
4307 CLASS="COMMAND"
4308 >cat</B
4309 >, etc.</P
4310 ><P
4311 > <TABLE
4312 BORDER="0"
4313 BGCOLOR="#E0E0E0"
4314 WIDTH="90%"
4315 ><TR
4316 ><TD
4317 ><PRE
4318 CLASS="SCREEN"
4319 > <TT
4320 CLASS="PROMPT"
4321 >bash$ </TT
4322 ><TT
4323 CLASS="USERINPUT"
4324 ><B
4325 >echo "whatever" | cat -</B
4326 ></TT
4327 >
4328 <TT
4329 CLASS="COMPUTEROUTPUT"
4330 >whatever</TT
4331 > </PRE
4332 ></TD
4333 ></TR
4334 ></TABLE
4335 >
4336 </P
4337 ><P
4338 >Where a filename is expected,
4339 <TT
4340 CLASS="REPLACEABLE"
4341 ><I
4342 >-</I
4343 ></TT
4344 > redirects output to
4345 <TT
4346 CLASS="FILENAME"
4347 >stdout</TT
4348 > (sometimes seen with
4349 <TT
4350 CLASS="USERINPUT"
4351 ><B
4352 >tar cf</B
4353 ></TT
4354 >), or accepts input from
4355 <TT
4356 CLASS="FILENAME"
4357 >stdin</TT
4358 >, rather than from a file.
4359 <A
4360 NAME="FILTERDASH"
4361 ></A
4362 >
4363 This is a method of using a file-oriented utility as a
4364 filter in a pipe.</P
4365 ><P
4366 > <TABLE
4367 BORDER="0"
4368 BGCOLOR="#E0E0E0"
4369 WIDTH="90%"
4370 ><TR
4371 ><TD
4372 ><PRE
4373 CLASS="SCREEN"
4374 > <TT
4375 CLASS="PROMPT"
4376 >bash$ </TT
4377 ><TT
4378 CLASS="USERINPUT"
4379 ><B
4380 >file</B
4381 ></TT
4382 >
4383 <TT
4384 CLASS="COMPUTEROUTPUT"
4385 >Usage: file [-bciknvzL] [-f namefile] [-m magicfiles] file...</TT
4386 >
4387 </PRE
4388 ></TD
4389 ></TR
4390 ></TABLE
4391 >
4392
4393 By itself on the command-line, <A
4394 HREF="filearchiv.html#FILEREF"
4395 >file</A
4396 > fails with an error message.
4397 </P
4398 ><P
4399 > Add a <SPAN
4400 CLASS="QUOTE"
4401 >"-"</SPAN
4402 > for a more useful result. This causes the
4403 shell to await user input.
4404
4405 <TABLE
4406 BORDER="0"
4407 BGCOLOR="#E0E0E0"
4408 WIDTH="90%"
4409 ><TR
4410 ><TD
4411 ><PRE
4412 CLASS="SCREEN"
4413 > <TT
4414 CLASS="PROMPT"
4415 >bash$ </TT
4416 ><TT
4417 CLASS="USERINPUT"
4418 ><B
4419 >file -</B
4420 ></TT
4421 >
4422 <TT
4423 CLASS="USERINPUT"
4424 ><B
4425 >abc</B
4426 ></TT
4427 >
4428 <TT
4429 CLASS="COMPUTEROUTPUT"
4430 >standard input: ASCII text</TT
4431 >
4432
4433
4434
4435 <TT
4436 CLASS="PROMPT"
4437 >bash$ </TT
4438 ><TT
4439 CLASS="USERINPUT"
4440 ><B
4441 >file -</B
4442 ></TT
4443 >
4444 <TT
4445 CLASS="USERINPUT"
4446 ><B
4447 >#!/bin/bash</B
4448 ></TT
4449 >
4450 <TT
4451 CLASS="COMPUTEROUTPUT"
4452 >standard input: Bourne-Again shell script text executable</TT
4453 >
4454 </PRE
4455 ></TD
4456 ></TR
4457 ></TABLE
4458 >
4459
4460 Now the command accepts input from <TT
4461 CLASS="FILENAME"
4462 >stdin</TT
4463 >
4464 and analyzes it.
4465 </P
4466 ><P
4467 >The <SPAN
4468 CLASS="QUOTE"
4469 >"-"</SPAN
4470 > can be used to pipe
4471 <TT
4472 CLASS="FILENAME"
4473 >stdout</TT
4474 > to other commands. This permits
4475 such stunts as <A
4476 HREF="assortedtips.html#PREPENDREF"
4477 >prepending lines
4478 to a file</A
4479 >.</P
4480 ><P
4481 >Using <A
4482 HREF="filearchiv.html#DIFFREF"
4483 >diff</A
4484 > to
4485 compare a file with a <SPAN
4486 CLASS="emphasis"
4487 ><I
4488 CLASS="EMPHASIS"
4489 >section</I
4490 ></SPAN
4491 >
4492 of another:</P
4493 ><P
4494 ><TT
4495 CLASS="USERINPUT"
4496 ><B
4497 >grep Linux file1 | diff file2 -</B
4498 ></TT
4499 ></P
4500 ><P
4501 >Finally, a real-world example using
4502 <TT
4503 CLASS="REPLACEABLE"
4504 ><I
4505 >-</I
4506 ></TT
4507 > with <A
4508 HREF="filearchiv.html#TARREF"
4509 >tar</A
4510 >.</P
4511 ><DIV
4512 CLASS="EXAMPLE"
4513 ><HR><A
4514 NAME="EX58"
4515 ></A
4516 ><P
4517 ><B
4518 >Example 3-4. Backup of all files changed in last day</B
4519 ></P
4520 ><TABLE
4521 BORDER="0"
4522 BGCOLOR="#E0E0E0"
4523 WIDTH="90%"
4524 ><TR
4525 ><TD
4526 ><PRE
4527 CLASS="PROGRAMLISTING"
4528 > 1&nbsp;#!/bin/bash
4529 2&nbsp;
4530 3&nbsp;# Backs up all files in current directory modified within last 24 hours
4531 4&nbsp;#+ in a "tarball" (tarred and gzipped file).
4532 5&nbsp;
4533 6&nbsp;BACKUPFILE=backup-$(date +%m-%d-%Y)
4534 7&nbsp;# Embeds date in backup filename.
4535 8&nbsp;# Thanks, Joshua Tschida, for the idea.
4536 9&nbsp;archive=${1:-$BACKUPFILE}
4537 10&nbsp;# If no backup-archive filename specified on command-line,
4538 11&nbsp;#+ it will default to "backup-MM-DD-YYYY.tar.gz."
4539 12&nbsp;
4540 13&nbsp;tar cvf - `find . -mtime -1 -type f -print` &#62; $archive.tar
4541 14&nbsp;gzip $archive.tar
4542 15&nbsp;echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."
4543 16&nbsp;
4544 17&nbsp;
4545 18&nbsp;# Stephane Chazelas points out that the above code will fail
4546 19&nbsp;#+ if there are too many files found
4547 20&nbsp;#+ or if any filenames contain blank characters.
4548 21&nbsp;
4549 22&nbsp;# He suggests the following alternatives:
4550 23&nbsp;# -------------------------------------------------------------------
4551 24&nbsp;# find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar"
4552 25&nbsp;# using the GNU version of "find".
4553 26&nbsp;
4554 27&nbsp;
4555 28&nbsp;# find . -mtime -1 -type f -exec tar rvf "$archive.tar" '{}' \;
4556 29&nbsp;# portable to other UNIX flavors, but much slower.
4557 30&nbsp;# -------------------------------------------------------------------
4558 31&nbsp;
4559 32&nbsp;
4560 33&nbsp;exit 0</PRE
4561 ></TD
4562 ></TR
4563 ></TABLE
4564 ><HR></DIV
4565 ><DIV
4566 CLASS="CAUTION"
4567 ><TABLE
4568 CLASS="CAUTION"
4569 WIDTH="90%"
4570 BORDER="0"
4571 ><TR
4572 ><TD
4573 WIDTH="25"
4574 ALIGN="CENTER"
4575 VALIGN="TOP"
4576 ><IMG
4577 SRC="common/caution.png"
4578 HSPACE="5"
4579 ALT="Caution"></TD
4580 ><TD
4581 ALIGN="LEFT"
4582 VALIGN="TOP"
4583 ><P
4584 >Filenames beginning with
4585 <SPAN
4586 CLASS="QUOTE"
4587 >"-"</SPAN
4588 > may cause problems when coupled with the
4589 <SPAN
4590 CLASS="QUOTE"
4591 >"-"</SPAN
4592 > redirection operator. A script should
4593 check for this and add an appropriate prefix to such
4594 filenames, for example <TT
4595 CLASS="FILENAME"
4596 >./-FILENAME</TT
4597 >,
4598 <TT
4599 CLASS="FILENAME"
4600 >$PWD/-FILENAME</TT
4601 >, or
4602 <TT
4603 CLASS="FILENAME"
4604 >$PATHNAME/-FILENAME</TT
4605 >.</P
4606 ><P
4607 >If the value of a variable begins with a
4608 <TT
4609 CLASS="REPLACEABLE"
4610 ><I
4611 >-</I
4612 ></TT
4613 >, this may likewise create
4614 problems.
4615 <TABLE
4616 BORDER="0"
4617 BGCOLOR="#E0E0E0"
4618 WIDTH="90%"
4619 ><TR
4620 ><TD
4621 ><PRE
4622 CLASS="PROGRAMLISTING"
4623 > 1&nbsp;var="-n"
4624 2&nbsp;echo $var
4625 3&nbsp;# Has the effect of "echo -n", and outputs nothing.</PRE
4626 ></TD
4627 ></TR
4628 ></TABLE
4629 >
4630 </P
4631 ></TD
4632 ></TR
4633 ></TABLE
4634 ></DIV
4635 ></DD
4636 ><DT
4637 ><SPAN
4638 CLASS="TOKEN"
4639 >-</SPAN
4640 ></DT
4641 ><DD
4642 ><DIV
4643 CLASS="FORMALPARA"
4644 ><P
4645 ><B
4646 >previous working directory. </B
4647 >A <B
4648 CLASS="COMMAND"
4649 >cd -</B
4650 > command changes to the
4651 previous working directory. This uses the
4652 <A
4653 HREF="variables2.html#OLDPWD"
4654 >$OLDPWD</A
4655 > <A
4656 HREF="othertypesv.html#ENVREF"
4657 >environmental variable</A
4658 >.</P
4659 ></DIV
4660 ><DIV
4661 CLASS="CAUTION"
4662 ><TABLE
4663 CLASS="CAUTION"
4664 WIDTH="90%"
4665 BORDER="0"
4666 ><TR
4667 ><TD
4668 WIDTH="25"
4669 ALIGN="CENTER"
4670 VALIGN="TOP"
4671 ><IMG
4672 SRC="common/caution.png"
4673 HSPACE="5"
4674 ALT="Caution"></TD
4675 ><TD
4676 ALIGN="LEFT"
4677 VALIGN="TOP"
4678 ><P
4679 >Do not confuse the <SPAN
4680 CLASS="QUOTE"
4681 >"-"</SPAN
4682 > used in this
4683 sense with the <SPAN
4684 CLASS="QUOTE"
4685 >"-"</SPAN
4686 > redirection
4687 operator just discussed. The interpretation of the
4688 <SPAN
4689 CLASS="QUOTE"
4690 >"-"</SPAN
4691 > depends on the context in which it
4692 appears.</P
4693 ></TD
4694 ></TR
4695 ></TABLE
4696 ></DIV
4697 ></DD
4698 ><DT
4699 ><SPAN
4700 CLASS="TOKEN"
4701 >-</SPAN
4702 ></DT
4703 ><DD
4704 ><DIV
4705 CLASS="FORMALPARA"
4706 ><P
4707 ><B
4708 >Minus. </B
4709 >Minus sign in an <A
4710 HREF="operations.html#AROPS1"
4711 >arithmetic
4712 operation</A
4713 >.</P
4714 ></DIV
4715 ></DD
4716 ><DT
4717 ><SPAN
4718 CLASS="TOKEN"
4719 >=</SPAN
4720 ></DT
4721 ><DD
4722 ><DIV
4723 CLASS="FORMALPARA"
4724 ><P
4725 ><B
4726 >Equals. </B
4727 ><A
4728 HREF="varassignment.html#EQREF"
4729 >Assignment operator</A
4730 >
4731 <TABLE
4732 BORDER="0"
4733 BGCOLOR="#E0E0E0"
4734 WIDTH="90%"
4735 ><TR
4736 ><TD
4737 ><PRE
4738 CLASS="PROGRAMLISTING"
4739 > 1&nbsp;a=28
4740 2&nbsp;echo $a # 28</PRE
4741 ></TD
4742 ></TR
4743 ></TABLE
4744 ></P
4745 ></DIV
4746 ><P
4747 >In a <A
4748 HREF="comparison-ops.html#EQUALSIGNREF"
4749 >different context</A
4750 >,
4751 the <SPAN
4752 CLASS="QUOTE"
4753 >"<SPAN
4754 CLASS="TOKEN"
4755 >=</SPAN
4756 >"</SPAN
4757 > is a <A
4758 HREF="comparison-ops.html#SCOMPARISON1"
4759 >string comparison</A
4760 >
4761 operator.</P
4762 ></DD
4763 ><DT
4764 ><SPAN
4765 CLASS="TOKEN"
4766 >+</SPAN
4767 ></DT
4768 ><DD
4769 ><DIV
4770 CLASS="FORMALPARA"
4771 ><P
4772 ><B
4773 >Plus. </B
4774 >Addition <A
4775 HREF="operations.html#AROPS1"
4776 >arithmetic
4777 operator</A
4778 >.</P
4779 ></DIV
4780 ><P
4781 >In a <A
4782 HREF="regexp.html#PLUSREF"
4783 >different context</A
4784 >,
4785 the <SPAN
4786 CLASS="TOKEN"
4787 >+</SPAN
4788 > is a <A
4789 HREF="regexp.html"
4790 >Regular
4791 Expression</A
4792 > operator.</P
4793 ></DD
4794 ><DT
4795 ><SPAN
4796 CLASS="TOKEN"
4797 >+</SPAN
4798 ></DT
4799 ><DD
4800 ><DIV
4801 CLASS="FORMALPARA"
4802 ><P
4803 ><B
4804 >Option. </B
4805 >Option flag for a command or filter.</P
4806 ></DIV
4807 ><P
4808 >Certain commands and <A
4809 HREF="internal.html#BUILTINREF"
4810 >builtins</A
4811 > use the
4812 <TT
4813 CLASS="OPTION"
4814 >+</TT
4815 > to enable certain options and the
4816 <TT
4817 CLASS="OPTION"
4818 >-</TT
4819 > to disable them. In <A
4820 HREF="parameter-substitution.html#PARAMSUBREF"
4821 >parameter substitution</A
4822 >,
4823 the <TT
4824 CLASS="OPTION"
4825 >+</TT
4826 > prefixes an <A
4827 HREF="parameter-substitution.html#PARAMALTV"
4828 > alternate value</A
4829 > that a variable expands to.</P
4830 ></DD
4831 ><DT
4832 ><A
4833 NAME="MODULO00"
4834 ></A
4835 ><SPAN
4836 CLASS="TOKEN"
4837 >%</SPAN
4838 ></DT
4839 ><DD
4840 ><DIV
4841 CLASS="FORMALPARA"
4842 ><P
4843 ><B
4844 ><A
4845 HREF="operations.html#MODULOREF"
4846 >modulo</A
4847 >. </B
4848 >Modulo (remainder of a division) <A
4849 HREF="operations.html#AROPS1"
4850 >arithmetic
4851 operation</A
4852 >.</P
4853 ></DIV
4854 ><P
4855 ><TABLE
4856 BORDER="0"
4857 BGCOLOR="#E0E0E0"
4858 WIDTH="90%"
4859 ><TR
4860 ><TD
4861 ><PRE
4862 CLASS="PROGRAMLISTING"
4863 > 1&nbsp;let "z = 5 % 3"
4864 2&nbsp;echo $z # 2</PRE
4865 ></TD
4866 ></TR
4867 ></TABLE
4868 ></P
4869 ><P
4870 >In a <A
4871 HREF="parameter-substitution.html#PCTPATREF"
4872 >different context</A
4873 >,
4874 the <SPAN
4875 CLASS="TOKEN"
4876 >%</SPAN
4877 > is a <A
4878 HREF="parameter-substitution.html#PSUB2"
4879 >pattern
4880 matching</A
4881 > operator.</P
4882 ></DD
4883 ><DT
4884 ><A
4885 NAME="TILDEREF"
4886 ></A
4887 ><SPAN
4888 CLASS="TOKEN"
4889 >~</SPAN
4890 ></DT
4891 ><DD
4892 ><DIV
4893 CLASS="FORMALPARA"
4894 ><P
4895 ><B
4896 >home directory [tilde]. </B
4897 >This corresponds to the <A
4898 HREF="variables2.html#HOMEDIRREF"
4899 >$HOME</A
4900 > internal variable.
4901
4902 <TT
4903 CLASS="FILENAME"
4904 >~bozo</TT
4905 > is bozo's home directory,
4906 and <B
4907 CLASS="COMMAND"
4908 >ls ~bozo</B
4909 > lists the contents of it.
4910 <SPAN
4911 CLASS="TOKEN"
4912 >~/</SPAN
4913 > is the current user's home directory,
4914 and <B
4915 CLASS="COMMAND"
4916 >ls ~/</B
4917 > lists the contents of it.
4918
4919 <TABLE
4920 BORDER="0"
4921 BGCOLOR="#E0E0E0"
4922 WIDTH="90%"
4923 ><TR
4924 ><TD
4925 ><PRE
4926 CLASS="SCREEN"
4927 > <TT
4928 CLASS="PROMPT"
4929 >bash$ </TT
4930 ><TT
4931 CLASS="USERINPUT"
4932 ><B
4933 >echo ~bozo</B
4934 ></TT
4935 >
4936 <TT
4937 CLASS="COMPUTEROUTPUT"
4938 >/home/bozo</TT
4939 >
4940
4941 <TT
4942 CLASS="PROMPT"
4943 >bash$ </TT
4944 ><TT
4945 CLASS="USERINPUT"
4946 ><B
4947 >echo ~</B
4948 ></TT
4949 >
4950 <TT
4951 CLASS="COMPUTEROUTPUT"
4952 >/home/bozo</TT
4953 >
4954
4955 <TT
4956 CLASS="PROMPT"
4957 >bash$ </TT
4958 ><TT
4959 CLASS="USERINPUT"
4960 ><B
4961 >echo ~/</B
4962 ></TT
4963 >
4964 <TT
4965 CLASS="COMPUTEROUTPUT"
4966 >/home/bozo/</TT
4967 >
4968
4969 <TT
4970 CLASS="PROMPT"
4971 >bash$ </TT
4972 ><TT
4973 CLASS="USERINPUT"
4974 ><B
4975 >echo ~:</B
4976 ></TT
4977 >
4978 <TT
4979 CLASS="COMPUTEROUTPUT"
4980 >/home/bozo:</TT
4981 >
4982
4983 <TT
4984 CLASS="PROMPT"
4985 >bash$ </TT
4986 ><TT
4987 CLASS="USERINPUT"
4988 ><B
4989 >echo ~nonexistent-user</B
4990 ></TT
4991 >
4992 <TT
4993 CLASS="COMPUTEROUTPUT"
4994 >~nonexistent-user</TT
4995 >
4996 </PRE
4997 ></TD
4998 ></TR
4999 ></TABLE
5000 >
5001 </P
5002 ></DIV
5003 ></DD
5004 ><DT
5005 ><A
5006 NAME="WORKINGDIRREF"
5007 ></A
5008 ><SPAN
5009 CLASS="TOKEN"
5010 >~+</SPAN
5011 ></DT
5012 ><DD
5013 ><DIV
5014 CLASS="FORMALPARA"
5015 ><P
5016 ><B
5017 >current working directory. </B
5018 >This corresponds to the <A
5019 HREF="variables2.html#PWDREF"
5020 >$PWD</A
5021 > internal variable.</P
5022 ></DIV
5023 ></DD
5024 ><DT
5025 ><A
5026 NAME="PREVWORKINGDIR"
5027 ></A
5028 ><SPAN
5029 CLASS="TOKEN"
5030 >~-</SPAN
5031 ></DT
5032 ><DD
5033 ><DIV
5034 CLASS="FORMALPARA"
5035 ><P
5036 ><B
5037 >previous working directory. </B
5038 >This corresponds to the <A
5039 HREF="variables2.html#OLDPWD"
5040 >$OLDPWD</A
5041 > internal variable.</P
5042 ></DIV
5043 ></DD
5044 ><DT
5045 ><SPAN
5046 CLASS="TOKEN"
5047 >=~</SPAN
5048 ></DT
5049 ><DD
5050 ><DIV
5051 CLASS="FORMALPARA"
5052 ><P
5053 ><B
5054 ><A
5055 HREF="bashver3.html#REGEXMATCHREF"
5056 >regular
5057 expression match</A
5058 >. </B
5059 >This operator was introduced with <A
5060 HREF="bashver3.html#BASH3REF"
5061 >version 3</A
5062 > of Bash.</P
5063 ></DIV
5064 ></DD
5065 ><DT
5066 ><A
5067 NAME="BEGLINEREF"
5068 ></A
5069 ><SPAN
5070 CLASS="TOKEN"
5071 >^</SPAN
5072 ></DT
5073 ><DD
5074 ><DIV
5075 CLASS="FORMALPARA"
5076 ><P
5077 ><B
5078 >beginning-of-line. </B
5079 >In a <A
5080 HREF="regexp.html#REGEXREF"
5081 >regular expression</A
5082 >, a
5083 <SPAN
5084 CLASS="QUOTE"
5085 >"^"</SPAN
5086 > addresses the <A
5087 HREF="regexp.html#CARETREF"
5088 >beginning of a line</A
5089 > of text.</P
5090 ></DIV
5091 ></DD
5092 ><DT
5093 ><SPAN
5094 CLASS="TOKEN"
5095 >^</SPAN
5096 >, <SPAN
5097 CLASS="TOKEN"
5098 >^^</SPAN
5099 ></DT
5100 ><DD
5101 ><DIV
5102 CLASS="FORMALPARA"
5103 ><P
5104 ><B
5105 ><A
5106 HREF="bashver4.html#CASEMODPARAMSUB"
5107 >Uppercase
5108 conversion</A
5109 > in <I
5110 CLASS="FIRSTTERM"
5111 >parameter substitution</I
5112 >
5113 (added in <A
5114 HREF="bashver4.html#BASH4REF"
5115 >version 4</A
5116 > of Bash). </B
5117 ></P
5118 ></DIV
5119 ></DD
5120 ><DT
5121 ><A
5122 NAME="CONTROLCHARREF"
5123 ></A
5124 >Control Characters</DT
5125 ><DD
5126 ><DIV
5127 CLASS="FORMALPARA"
5128 ><P
5129 ><B
5130 > change the behavior of the
5131 terminal or text display. </B
5132 >A control character is a <B
5133 CLASS="KEYCAP"
5134 >CONTROL</B
5135 >
5136 + <B
5137 CLASS="KEYCAP"
5138 >key</B
5139 > combination (pressed
5140 simultaneously).
5141
5142 A control character may also
5143 be written in <I
5144 CLASS="FIRSTTERM"
5145 >octal</I
5146 > or
5147 <I
5148 CLASS="FIRSTTERM"
5149 >hexadecimal</I
5150 > notation,
5151 following an <I
5152 CLASS="FIRSTTERM"
5153 >escape</I
5154 >.</P
5155 ></DIV
5156 ><P
5157 >Control characters are not normally useful inside a
5158 script.</P
5159 ><UL
5160 ><LI
5161 ><P
5162 ><TT
5163 CLASS="USERINPUT"
5164 ><B
5165 >Ctl-A</B
5166 ></TT
5167 ></P
5168 ><P
5169 >Moves cursor to beginning of line of text
5170 (on the command-line).</P
5171 ></LI
5172 ><LI
5173 ><P
5174 ><TT
5175 CLASS="USERINPUT"
5176 ><B
5177 >Ctl-B</B
5178 ></TT
5179 ></P
5180 ><P
5181 ><TT
5182 CLASS="USERINPUT"
5183 ><B
5184 >Backspace</B
5185 ></TT
5186 >
5187 (nondestructive).</P
5188 ></LI
5189 ><LI
5190 ><P
5191 ><A
5192 NAME="CTLCREF"
5193 ></A
5194 ></P
5195 ><P
5196 ><TT
5197 CLASS="USERINPUT"
5198 ><B
5199 >Ctl-C</B
5200 ></TT
5201 ></P
5202 ><P
5203 ><TT
5204 CLASS="USERINPUT"
5205 ><B
5206 >Break</B
5207 ></TT
5208 >.
5209 Terminate a foreground job.</P
5210 ></LI
5211 ><LI
5212 ><P
5213 ><A
5214 NAME="CTLDREF"
5215 ></A
5216 ></P
5217 ><P
5218 ><TT
5219 CLASS="USERINPUT"
5220 ><B
5221 >Ctl-D</B
5222 ></TT
5223 ></P
5224 ><P
5225 ><I
5226 CLASS="FIRSTTERM"
5227 >Log out</I
5228 > from a shell (similar to
5229 <A
5230 HREF="exit-status.html#EXITCOMMANDREF"
5231 >exit</A
5232 >).</P
5233 ><P
5234 ><TT
5235 CLASS="USERINPUT"
5236 ><B
5237 >EOF</B
5238 ></TT
5239 > (end-of-file). This also
5240 terminates input from <TT
5241 CLASS="FILENAME"
5242 >stdin</TT
5243 >.</P
5244 ><P
5245 >When typing text on the console or in an
5246 <I
5247 CLASS="FIRSTTERM"
5248 >xterm</I
5249 > window,
5250 <TT
5251 CLASS="USERINPUT"
5252 ><B
5253 >Ctl-D</B
5254 ></TT
5255 > erases the character under the
5256 cursor. When there are no characters present,
5257 <TT
5258 CLASS="USERINPUT"
5259 ><B
5260 >Ctl-D</B
5261 ></TT
5262 > logs out of the session, as
5263 expected. In an <I
5264 CLASS="FIRSTTERM"
5265 >xterm</I
5266 > window,
5267 this has the effect of closing the window.</P
5268 ></LI
5269 ><LI
5270 ><P
5271 ><TT
5272 CLASS="USERINPUT"
5273 ><B
5274 >Ctl-E</B
5275 ></TT
5276 ></P
5277 ><P
5278 >Moves cursor to end of line of text
5279 (on the command-line).</P
5280 ></LI
5281 ><LI
5282 ><P
5283 ><TT
5284 CLASS="USERINPUT"
5285 ><B
5286 >Ctl-F</B
5287 ></TT
5288 ></P
5289 ><P
5290 >Moves cursor forward one character position
5291 (on the command-line).</P
5292 ></LI
5293 ><LI
5294 ><P
5295 ><A
5296 NAME="CTLGREF"
5297 ></A
5298 ></P
5299 ><P
5300 ><TT
5301 CLASS="USERINPUT"
5302 ><B
5303 >Ctl-G</B
5304 ></TT
5305 ></P
5306 ><P
5307 ><TT
5308 CLASS="USERINPUT"
5309 ><B
5310 >BEL</B
5311 ></TT
5312 >. On some
5313 old-time teletype terminals, this would actually ring
5314 a bell. In an <I
5315 CLASS="FIRSTTERM"
5316 >xterm</I
5317 > it might
5318 beep.</P
5319 ></LI
5320 ><LI
5321 ><P
5322 ><A
5323 NAME="CTLHREF"
5324 ></A
5325 ></P
5326 ><P
5327 ><TT
5328 CLASS="USERINPUT"
5329 ><B
5330 >Ctl-H</B
5331 ></TT
5332 ></P
5333 ><P
5334 ><TT
5335 CLASS="USERINPUT"
5336 ><B
5337 >Rubout</B
5338 ></TT
5339 > (destructive backspace).
5340 Erases characters the cursor backs over while
5341 backspacing.</P
5342 ><P
5343 > <TABLE
5344 BORDER="0"
5345 BGCOLOR="#E0E0E0"
5346 WIDTH="90%"
5347 ><TR
5348 ><TD
5349 ><PRE
5350 CLASS="PROGRAMLISTING"
5351 > 1&nbsp;#!/bin/bash
5352 2&nbsp;# Embedding Ctl-H in a string.
5353 3&nbsp;
5354 4&nbsp;a="^H^H" # Two Ctl-H's -- backspaces
5355 5&nbsp; # ctl-V ctl-H, using vi/vim
5356 6&nbsp;echo "abcdef" # abcdef
5357 7&nbsp;echo
5358 8&nbsp;echo -n "abcdef$a " # abcd f
5359 9&nbsp;# Space at end ^ ^ Backspaces twice.
5360 10&nbsp;echo
5361 11&nbsp;echo -n "abcdef$a" # abcdef
5362 12&nbsp;# No space at end ^ Doesn't backspace (why?).
5363 13&nbsp; # Results may not be quite as expected.
5364 14&nbsp;echo; echo
5365 15&nbsp;
5366 16&nbsp;# Constantin Hagemeier suggests trying:
5367 17&nbsp;# a=$'\010\010'
5368 18&nbsp;# a=$'\b\b'
5369 19&nbsp;# a=$'\x08\x08'
5370 20&nbsp;# But, this does not change the results.
5371 21&nbsp;
5372 22&nbsp;########################################
5373 23&nbsp;
5374 24&nbsp;# Now, try this.
5375 25&nbsp;
5376 26&nbsp;rubout="^H^H^H^H^H" # 5 x Ctl-H.
5377 27&nbsp;
5378 28&nbsp;echo -n "12345678"
5379 29&nbsp;sleep 2
5380 30&nbsp;echo -n "$rubout"
5381 31&nbsp;sleep 2</PRE
5382 ></TD
5383 ></TR
5384 ></TABLE
5385 >
5386 </P
5387 ></LI
5388 ><LI
5389 ><P
5390 ><TT
5391 CLASS="USERINPUT"
5392 ><B
5393 >Ctl-I</B
5394 ></TT
5395 ></P
5396 ><P
5397 ><TT
5398 CLASS="USERINPUT"
5399 ><B
5400 >Horizontal tab</B
5401 ></TT
5402 >.</P
5403 ></LI
5404 ><LI
5405 ><P
5406 ><A
5407 NAME="CTLJREF"
5408 ></A
5409 ></P
5410 ><P
5411 ><TT
5412 CLASS="USERINPUT"
5413 ><B
5414 >Ctl-J</B
5415 ></TT
5416 ></P
5417 ><P
5418 ><TT
5419 CLASS="USERINPUT"
5420 ><B
5421 >Newline</B
5422 ></TT
5423 > (line feed).
5424 In a script, may also be expressed in octal notation --
5425 '\012' or in hexadecimal -- '\x0a'.</P
5426 ></LI
5427 ><LI
5428 ><P
5429 ><TT
5430 CLASS="USERINPUT"
5431 ><B
5432 >Ctl-K</B
5433 ></TT
5434 ></P
5435 ><P
5436 ><TT
5437 CLASS="USERINPUT"
5438 ><B
5439 >Vertical tab</B
5440 ></TT
5441 >.</P
5442 ><P
5443 >When typing text on the console or in an
5444 <I
5445 CLASS="FIRSTTERM"
5446 >xterm</I
5447 > window,
5448 <TT
5449 CLASS="USERINPUT"
5450 ><B
5451 >Ctl-K</B
5452 ></TT
5453 > erases from the character
5454 under the cursor to end of line. Within a script,
5455 <TT
5456 CLASS="USERINPUT"
5457 ><B
5458 >Ctl-K</B
5459 ></TT
5460 > may behave differently,
5461 as in Lee Lee Maschmeyer's example, below.</P
5462 ></LI
5463 ><LI
5464 ><P
5465 ><TT
5466 CLASS="USERINPUT"
5467 ><B
5468 >Ctl-L</B
5469 ></TT
5470 ></P
5471 ><P
5472 ><TT
5473 CLASS="USERINPUT"
5474 ><B
5475 >Formfeed</B
5476 ></TT
5477 > (clear the terminal
5478 screen). In a terminal, this has the same effect as the
5479 <A
5480 HREF="terminalccmds.html#CLEARREF"
5481 >clear</A
5482 > command. When sent
5483 to a printer, a <TT
5484 CLASS="USERINPUT"
5485 ><B
5486 >Ctl-L</B
5487 ></TT
5488 > causes
5489 an advance to end of the paper sheet.</P
5490 ></LI
5491 ><LI
5492 ><P
5493 ><A
5494 NAME="CTLMREF"
5495 ></A
5496 ></P
5497 ><P
5498 ><TT
5499 CLASS="USERINPUT"
5500 ><B
5501 >Ctl-M</B
5502 ></TT
5503 ></P
5504 ><P
5505 ><TT
5506 CLASS="USERINPUT"
5507 ><B
5508 >Carriage return</B
5509 ></TT
5510 >.</P
5511 ><P
5512 > <TABLE
5513 BORDER="0"
5514 BGCOLOR="#E0E0E0"
5515 WIDTH="90%"
5516 ><TR
5517 ><TD
5518 ><PRE
5519 CLASS="PROGRAMLISTING"
5520 > 1&nbsp;#!/bin/bash
5521 2&nbsp;# Thank you, Lee Maschmeyer, for this example.
5522 3&nbsp;
5523 4&nbsp;read -n 1 -s -p \
5524 5&nbsp;$'Control-M leaves cursor at beginning of this line. Press Enter. \x0d'
5525 6&nbsp; # Of course, '0d' is the hex equivalent of Control-M.
5526 7&nbsp;echo &#62;&#38;2 # The '-s' makes anything typed silent,
5527 8&nbsp; #+ so it is necessary to go to new line explicitly.
5528 9&nbsp;
5529 10&nbsp;read -n 1 -s -p $'Control-J leaves cursor on next line. \x0a'
5530 11&nbsp; # '0a' is the hex equivalent of Control-J, linefeed.
5531 12&nbsp;echo &#62;&#38;2
5532 13&nbsp;
5533 14&nbsp;###
5534 15&nbsp;
5535 16&nbsp;read -n 1 -s -p $'And Control-K\x0bgoes straight down.'
5536 17&nbsp;echo &#62;&#38;2 # Control-K is vertical tab.
5537 18&nbsp;
5538 19&nbsp;# A better example of the effect of a vertical tab is:
5539 20&nbsp;
5540 21&nbsp;var=$'\x0aThis is the bottom line\x0bThis is the top line\x0a'
5541 22&nbsp;echo "$var"
5542 23&nbsp;# This works the same way as the above example. However:
5543 24&nbsp;echo "$var" | col
5544 25&nbsp;# This causes the right end of the line to be higher than the left end.
5545 26&nbsp;# It also explains why we started and ended with a line feed --
5546 27&nbsp;#+ to avoid a garbled screen.
5547 28&nbsp;
5548 29&nbsp;# As Lee Maschmeyer explains:
5549 30&nbsp;# --------------------------
5550 31&nbsp;# In the [first vertical tab example] . . . the vertical tab
5551 32&nbsp;#+ makes the printing go straight down without a carriage return.
5552 33&nbsp;# This is true only on devices, such as the Linux console,
5553 34&nbsp;#+ that can't go "backward."
5554 35&nbsp;# The real purpose of VT is to go straight UP, not down.
5555 36&nbsp;# It can be used to print superscripts on a printer.
5556 37&nbsp;# The col utility can be used to emulate the proper behavior of VT.
5557 38&nbsp;
5558 39&nbsp;exit 0</PRE
5559 ></TD
5560 ></TR
5561 ></TABLE
5562 >
5563 </P
5564 ></LI
5565 ><LI
5566 ><P
5567 ><TT
5568 CLASS="USERINPUT"
5569 ><B
5570 >Ctl-N</B
5571 ></TT
5572 ></P
5573 ><P
5574 >Erases a line of text recalled from
5575 <I
5576 CLASS="FIRSTTERM"
5577 >history buffer</I
5578 >
5579 <A
5580 NAME="AEN2107"
5581 HREF="#FTN.AEN2107"
5582 >[8]</A
5583 > (on the
5584 command-line).</P
5585 ></LI
5586 ><LI
5587 ><P
5588 ><TT
5589 CLASS="USERINPUT"
5590 ><B
5591 >Ctl-O</B
5592 ></TT
5593 ></P
5594 ><P
5595 >Issues a <I
5596 CLASS="FIRSTTERM"
5597 >newline</I
5598 >
5599 (on the command-line).</P
5600 ></LI
5601 ><LI
5602 ><P
5603 ><TT
5604 CLASS="USERINPUT"
5605 ><B
5606 >Ctl-P</B
5607 ></TT
5608 ></P
5609 ><P
5610 >Recalls last command from <I
5611 CLASS="FIRSTTERM"
5612 >history
5613 buffer</I
5614 > (on the command-line).</P
5615 ></LI
5616 ><LI
5617 ><P
5618 ><TT
5619 CLASS="USERINPUT"
5620 ><B
5621 >Ctl-Q</B
5622 ></TT
5623 ></P
5624 ><P
5625 >Resume (<TT
5626 CLASS="USERINPUT"
5627 ><B
5628 >XON</B
5629 ></TT
5630 >).</P
5631 ><P
5632 >This resumes <TT
5633 CLASS="FILENAME"
5634 >stdin</TT
5635 > in a terminal.</P
5636 ></LI
5637 ><LI
5638 ><P
5639 ><TT
5640 CLASS="USERINPUT"
5641 ><B
5642 >Ctl-R</B
5643 ></TT
5644 ></P
5645 ><P
5646 >Backwards search for text in <I
5647 CLASS="FIRSTTERM"
5648 >history
5649 buffer</I
5650 >
5651 (on the command-line).</P
5652 ></LI
5653 ><LI
5654 ><P
5655 ><TT
5656 CLASS="USERINPUT"
5657 ><B
5658 >Ctl-S</B
5659 ></TT
5660 ></P
5661 ><P
5662 >Suspend (<TT
5663 CLASS="USERINPUT"
5664 ><B
5665 >XOFF</B
5666 ></TT
5667 >).</P
5668 ><P
5669 >This freezes <TT
5670 CLASS="FILENAME"
5671 >stdin</TT
5672 > in a terminal.
5673 (Use Ctl-Q to restore input.)</P
5674 ></LI
5675 ><LI
5676 ><P
5677 ><TT
5678 CLASS="USERINPUT"
5679 ><B
5680 >Ctl-T</B
5681 ></TT
5682 ></P
5683 ><P
5684 >Reverses the position of the character the cursor
5685 is on with the previous character (on the
5686 command-line).</P
5687 ></LI
5688 ><LI
5689 ><P
5690 ><TT
5691 CLASS="USERINPUT"
5692 ><B
5693 >Ctl-U</B
5694 ></TT
5695 ></P
5696 ><P
5697 >Erase a line of input, from the cursor backward to
5698 beginning of line. In some settings,
5699 <TT
5700 CLASS="USERINPUT"
5701 ><B
5702 >Ctl-U</B
5703 ></TT
5704 > erases the entire
5705 line of input, <SPAN
5706 CLASS="emphasis"
5707 ><I
5708 CLASS="EMPHASIS"
5709 >regardless of cursor
5710 position</I
5711 ></SPAN
5712 >.</P
5713 ></LI
5714 ><LI
5715 ><P
5716 ><TT
5717 CLASS="USERINPUT"
5718 ><B
5719 >Ctl-V</B
5720 ></TT
5721 ></P
5722 ><P
5723 >When inputting text, <TT
5724 CLASS="USERINPUT"
5725 ><B
5726 >Ctl-V</B
5727 ></TT
5728 >
5729 permits inserting control characters. For example, the
5730 following two are equivalent:
5731 <TABLE
5732 BORDER="0"
5733 BGCOLOR="#E0E0E0"
5734 WIDTH="90%"
5735 ><TR
5736 ><TD
5737 ><PRE
5738 CLASS="PROGRAMLISTING"
5739 > 1&nbsp;echo -e '\x0a'
5740 2&nbsp;echo &#60;Ctl-V&#62;&#60;Ctl-J&#62;</PRE
5741 ></TD
5742 ></TR
5743 ></TABLE
5744 ></P
5745 ><P
5746 ><TT
5747 CLASS="USERINPUT"
5748 ><B
5749 >Ctl-V</B
5750 ></TT
5751 > is primarily useful from
5752 within a text editor.</P
5753 ></LI
5754 ><LI
5755 ><P
5756 ><TT
5757 CLASS="USERINPUT"
5758 ><B
5759 >Ctl-W</B
5760 ></TT
5761 ></P
5762 ><P
5763 >When typing text on the console or in an xterm window,
5764 <TT
5765 CLASS="USERINPUT"
5766 ><B
5767 >Ctl-W</B
5768 ></TT
5769 > erases from the character
5770 under the cursor backwards to the first instance of
5771 <A
5772 HREF="special-chars.html#WHITESPACEREF"
5773 >whitespace</A
5774 >. In
5775 some settings, <TT
5776 CLASS="USERINPUT"
5777 ><B
5778 >Ctl-W</B
5779 ></TT
5780 > erases
5781 backwards to first non-alphanumeric character.</P
5782 ></LI
5783 ><LI
5784 ><P
5785 ><TT
5786 CLASS="USERINPUT"
5787 ><B
5788 >Ctl-X</B
5789 ></TT
5790 ></P
5791 ><P
5792 >In certain word processing programs,
5793 <I
5794 CLASS="FIRSTTERM"
5795 >Cuts</I
5796 > highlighted text
5797 and copies to <I
5798 CLASS="FIRSTTERM"
5799 >clipboard</I
5800 >.</P
5801 ></LI
5802 ><LI
5803 ><P
5804 ><TT
5805 CLASS="USERINPUT"
5806 ><B
5807 >Ctl-Y</B
5808 ></TT
5809 ></P
5810 ><P
5811 ><I
5812 CLASS="FIRSTTERM"
5813 >Pastes</I
5814 > back text previously
5815 erased (with <TT
5816 CLASS="USERINPUT"
5817 ><B
5818 >Ctl-U</B
5819 ></TT
5820 > or
5821 <TT
5822 CLASS="USERINPUT"
5823 ><B
5824 >Ctl-W</B
5825 ></TT
5826 >).</P
5827 ></LI
5828 ><LI
5829 ><P
5830 ><TT
5831 CLASS="USERINPUT"
5832 ><B
5833 >Ctl-Z</B
5834 ></TT
5835 ></P
5836 ><P
5837 ><I
5838 CLASS="FIRSTTERM"
5839 >Pauses</I
5840 > a foreground job.</P
5841 ><P
5842 ><I
5843 CLASS="FIRSTTERM"
5844 >Substitute</I
5845 > operation in certain
5846 word processing applications.</P
5847 ><P
5848 ><TT
5849 CLASS="USERINPUT"
5850 ><B
5851 >EOF</B
5852 ></TT
5853 > (end-of-file) character
5854 in the MSDOS filesystem.</P
5855 ></LI
5856 ></UL
5857 ></DD
5858 ><DT
5859 ><A
5860 NAME="WHITESPACEREF"
5861 ></A
5862 >Whitespace</DT
5863 ><DD
5864 ><DIV
5865 CLASS="FORMALPARA"
5866 ><P
5867 ><B
5868 >functions as a separator between commands and/or
5869 variables. </B
5870 >Whitespace consists of either
5871 <I
5872 CLASS="FIRSTTERM"
5873 >spaces</I
5874 >,
5875 <I
5876 CLASS="FIRSTTERM"
5877 >tabs</I
5878 >, <I
5879 CLASS="FIRSTTERM"
5880 >blank
5881 lines</I
5882 >, or any combination thereof.
5883
5884 <A
5885 NAME="AEN2198"
5886 HREF="#FTN.AEN2198"
5887 >[9]</A
5888 >
5889
5890 In some contexts, such as <A
5891 HREF="gotchas.html#WSBAD"
5892 >variable
5893 assignment</A
5894 >, whitespace is not permitted, and
5895 results in a syntax error.</P
5896 ></DIV
5897 ><P
5898 >Blank lines have no effect on the action of a script,
5899 and are therefore useful for visually separating functional
5900 sections.</P
5901 ><P
5902 ><A
5903 HREF="variables2.html#IFSREF"
5904 >$IFS</A
5905 >, the special variable
5906 separating <I
5907 CLASS="FIRSTTERM"
5908 >fields</I
5909 > of input to certain
5910 commands. It defaults to whitespace.</P
5911 ><TABLE
5912 CLASS="SIDEBAR"
5913 BORDER="1"
5914 CELLPADDING="5"
5915 ><TR
5916 ><TD
5917 ><DIV
5918 CLASS="SIDEBAR"
5919 ><A
5920 NAME="AEN2207"
5921 ></A
5922 ><P
5923 > <A
5924 NAME="FIELDREF"
5925 ></A
5926 ><TT
5927 CLASS="USERINPUT"
5928 ><B
5929 >Definition:</B
5930 ></TT
5931 >
5932 A <I
5933 CLASS="FIRSTTERM"
5934 >field</I
5935 > is a discrete chunk of data
5936 expressed as a string of consecutive characters.
5937 Separating each field from adjacent fields is either
5938 <I
5939 CLASS="FIRSTTERM"
5940 >whitespace</I
5941 > or some other designated
5942 character (often determined by the <SPAN
5943 CLASS="TOKEN"
5944 >$IFS</SPAN
5945 >).
5946 In some contexts, a field may be called a
5947 <I
5948 CLASS="FIRSTTERM"
5949 >record</I
5950 >.
5951 </P
5952 ></DIV
5953 ></TD
5954 ></TR
5955 ></TABLE
5956 ><P
5957 ><A
5958 NAME="QUOTINGWS"
5959 ></A
5960 ></P
5961 ><P
5962 >To preserve <I
5963 CLASS="FIRSTTERM"
5964 >whitespace</I
5965 >
5966 within a string or in a variable, use <A
5967 HREF="quoting.html#QUOTINGREF"
5968 >quoting</A
5969 >.</P
5970 ><P
5971 >UNIX <A
5972 HREF="special-chars.html#FILTERDEF"
5973 >filters</A
5974 >
5975 can target and operate on <I
5976 CLASS="FIRSTTERM"
5977 >whitespace</I
5978 >
5979 using the <A
5980 HREF="regexp.html#POSIXREF"
5981 >POSIX</A
5982 > character class
5983 <A
5984 HREF="regexp.html#WSPOSIX"
5985 >[:space:]</A
5986 >.</P
5987 ></DD
5988 ></DL
5989 ></DIV
5990 ></DIV
5991 ><H3
5992 CLASS="FOOTNOTES"
5993 >Notes</H3
5994 ><TABLE
5995 BORDER="0"
5996 CLASS="FOOTNOTES"
5997 WIDTH="100%"
5998 ><TR
5999 ><TD
6000 ALIGN="LEFT"
6001 VALIGN="TOP"
6002 WIDTH="5%"
6003 ><A
6004 NAME="FTN.AEN612"
6005 HREF="special-chars.html#AEN612"
6006 >[1]</A
6007 ></TD
6008 ><TD
6009 ALIGN="LEFT"
6010 VALIGN="TOP"
6011 WIDTH="95%"
6012 ><P
6013 ><A
6014 NAME="OPERATORDEF"
6015 ></A
6016 >An
6017 <I
6018 CLASS="FIRSTTERM"
6019 >operator</I
6020 > is an agent that carries
6021 out an <I
6022 CLASS="FIRSTTERM"
6023 >operation</I
6024 >. Some examples
6025 are the common <A
6026 HREF="operations.html#AROPS1"
6027 >arithmetic
6028 operators</A
6029 >, <B
6030 CLASS="COMMAND"
6031 >+ - * /</B
6032 >. In
6033 Bash, there is some overlap between the concepts
6034 of <I
6035 CLASS="FIRSTTERM"
6036 >operator</I
6037 > and <A
6038 HREF="internal.html#KEYWORDREF"
6039 >keyword</A
6040 >.</P
6041 ></TD
6042 ></TR
6043 ><TR
6044 ><TD
6045 ALIGN="LEFT"
6046 VALIGN="TOP"
6047 WIDTH="5%"
6048 ><A
6049 NAME="FTN.AEN888"
6050 HREF="special-chars.html#AEN888"
6051 >[2]</A
6052 ></TD
6053 ><TD
6054 ALIGN="LEFT"
6055 VALIGN="TOP"
6056 WIDTH="95%"
6057 ><P
6058 >This is more commonly known
6059 as the <I
6060 CLASS="FIRSTTERM"
6061 >ternary</I
6062 >
6063 operator. Unfortunately, <I
6064 CLASS="FIRSTTERM"
6065 >ternary</I
6066 >
6067 is an ugly word. It doesn't roll off
6068 the tongue, and it doesn't elucidate. It
6069 obfuscates. <I
6070 CLASS="FIRSTTERM"
6071 >Trinary</I
6072 > is by far
6073 the more elegant usage.</P
6074 ></TD
6075 ></TR
6076 ><TR
6077 ><TD
6078 ALIGN="LEFT"
6079 VALIGN="TOP"
6080 WIDTH="5%"
6081 ><A
6082 NAME="FTN.AEN1001"
6083 HREF="special-chars.html#AEN1001"
6084 >[3]</A
6085 ></TD
6086 ><TD
6087 ALIGN="LEFT"
6088 VALIGN="TOP"
6089 WIDTH="95%"
6090 ><P
6091 ><A
6092 NAME="ASCIIDEF"
6093 ></A
6094 ></P
6095 ><P
6096 ><B
6097 CLASS="COMMAND"
6098 >A</B
6099 >merican
6100 <B
6101 CLASS="COMMAND"
6102 >S</B
6103 >tandard
6104 <B
6105 CLASS="COMMAND"
6106 >C</B
6107 >ode
6108 for
6109 <B
6110 CLASS="COMMAND"
6111 >I</B
6112 >nformation
6113 <B
6114 CLASS="COMMAND"
6115 >I</B
6116 >nterchange.
6117 This is a system for encoding text characters
6118 (alphabetic, numeric, and a limited set of symbols)
6119 as 7-bit numbers that can be stored and manipulated by
6120 computers. Many of the ASCII characters are
6121 represented on a standard keyboard.</P
6122 ></TD
6123 ></TR
6124 ><TR
6125 ><TD
6126 ALIGN="LEFT"
6127 VALIGN="TOP"
6128 WIDTH="5%"
6129 ><A
6130 NAME="FTN.AEN1071"
6131 HREF="special-chars.html#AEN1071"
6132 >[4]</A
6133 ></TD
6134 ><TD
6135 ALIGN="LEFT"
6136 VALIGN="TOP"
6137 WIDTH="95%"
6138 ><P
6139 ><A
6140 NAME="PROCESSIDDEF"
6141 ></A
6142 ></P
6143 ><P
6144 >A <I
6145 CLASS="FIRSTTERM"
6146 >PID</I
6147 >, or
6148 <I
6149 CLASS="FIRSTTERM"
6150 >process ID</I
6151 >, is a number assigned
6152 to a running process. The <I
6153 CLASS="FIRSTTERM"
6154 >PID</I
6155 >s
6156 of running processes may be viewed with a <A
6157 HREF="system.html#PPSSREF"
6158 >ps</A
6159 > command.
6160 </P
6161 ><P
6162 ><A
6163 NAME="PROCESSREF"
6164 ></A
6165 ></P
6166 ><P
6167 > <TT
6168 CLASS="USERINPUT"
6169 ><B
6170 >Definition:</B
6171 ></TT
6172 > A
6173 <I
6174 CLASS="FIRSTTERM"
6175 >process</I
6176 > is a currently
6177 executing command (or program), sometimes referred
6178 to as a <I
6179 CLASS="FIRSTTERM"
6180 >job</I
6181 >. </P
6182 ></TD
6183 ></TR
6184 ><TR
6185 ><TD
6186 ALIGN="LEFT"
6187 VALIGN="TOP"
6188 WIDTH="5%"
6189 ><A
6190 NAME="FTN.AEN1124"
6191 HREF="special-chars.html#AEN1124"
6192 >[5]</A
6193 ></TD
6194 ><TD
6195 ALIGN="LEFT"
6196 VALIGN="TOP"
6197 WIDTH="95%"
6198 ><P
6199 >The shell does the <I
6200 CLASS="FIRSTTERM"
6201 >brace
6202 expansion</I
6203 >. The command itself acts upon the
6204 <SPAN
6205 CLASS="emphasis"
6206 ><I
6207 CLASS="EMPHASIS"
6208 >result</I
6209 ></SPAN
6210 > of the expansion.</P
6211 ></TD
6212 ></TR
6213 ><TR
6214 ><TD
6215 ALIGN="LEFT"
6216 VALIGN="TOP"
6217 WIDTH="5%"
6218 ><A
6219 NAME="FTN.AEN1199"
6220 HREF="special-chars.html#AEN1199"
6221 >[6]</A
6222 ></TD
6223 ><TD
6224 ALIGN="LEFT"
6225 VALIGN="TOP"
6226 WIDTH="95%"
6227 ><P
6228 >Exception: a code block in braces as
6229 part of a pipe <SPAN
6230 CLASS="emphasis"
6231 ><I
6232 CLASS="EMPHASIS"
6233 >may</I
6234 ></SPAN
6235 > run as a
6236 <A
6237 HREF="subshells.html#SUBSHELLSREF"
6238 >subshell</A
6239 >.</P
6240 ><P
6241 ><TABLE
6242 BORDER="0"
6243 BGCOLOR="#E0E0E0"
6244 WIDTH="90%"
6245 ><TR
6246 ><TD
6247 ><PRE
6248 CLASS="PROGRAMLISTING"
6249 > 1&nbsp;ls | { read firstline; read secondline; }
6250 2&nbsp;# Error. The code block in braces runs as a subshell,
6251 3&nbsp;#+ so the output of "ls" cannot be passed to variables within the block.
6252 4&nbsp;echo "First line is $firstline; second line is $secondline" # Won't work.
6253 5&nbsp;
6254 6&nbsp;# Thanks, S.C.</PRE
6255 ></TD
6256 ></TR
6257 ></TABLE
6258 ></P
6259 ></TD
6260 ></TR
6261 ><TR
6262 ><TD
6263 ALIGN="LEFT"
6264 VALIGN="TOP"
6265 WIDTH="5%"
6266 ><A
6267 NAME="FTN.AEN1564"
6268 HREF="special-chars.html#AEN1564"
6269 >[7]</A
6270 ></TD
6271 ><TD
6272 ALIGN="LEFT"
6273 VALIGN="TOP"
6274 WIDTH="95%"
6275 ><P
6276 > Even as in olden times a
6277 <I
6278 CLASS="FIRSTTERM"
6279 >philtre</I
6280 > denoted a potion alleged
6281 to have magical transformative powers, so does a UNIX
6282 <I
6283 CLASS="FIRSTTERM"
6284 >filter</I
6285 > transform its target in
6286 (roughly) analogous fashion. (The coder who comes up with a
6287 <SPAN
6288 CLASS="QUOTE"
6289 >"love philtre"</SPAN
6290 > that runs on a Linux machine
6291 will likely win accolades and honors.)</P
6292 ></TD
6293 ></TR
6294 ><TR
6295 ><TD
6296 ALIGN="LEFT"
6297 VALIGN="TOP"
6298 WIDTH="5%"
6299 ><A
6300 NAME="FTN.AEN2107"
6301 HREF="special-chars.html#AEN2107"
6302 >[8]</A
6303 ></TD
6304 ><TD
6305 ALIGN="LEFT"
6306 VALIGN="TOP"
6307 WIDTH="95%"
6308 ><P
6309 >Bash stores a list of commands
6310 previously issued from the command-line
6311 in a <I
6312 CLASS="FIRSTTERM"
6313 >buffer</I
6314 >, or
6315 memory space, for recall with the <A
6316 HREF="internal.html#BUILTINREF"
6317 >builtin</A
6318 >
6319 <I
6320 CLASS="FIRSTTERM"
6321 >history</I
6322 >
6323 commands.</P
6324 ></TD
6325 ></TR
6326 ><TR
6327 ><TD
6328 ALIGN="LEFT"
6329 VALIGN="TOP"
6330 WIDTH="5%"
6331 ><A
6332 NAME="FTN.AEN2198"
6333 HREF="special-chars.html#AEN2198"
6334 >[9]</A
6335 ></TD
6336 ><TD
6337 ALIGN="LEFT"
6338 VALIGN="TOP"
6339 WIDTH="95%"
6340 ><P
6341 >A linefeed (<I
6342 CLASS="FIRSTTERM"
6343 >newline</I
6344 >)
6345 is also a whitespace character. This explains
6346 why a <I
6347 CLASS="FIRSTTERM"
6348 >blank line</I
6349 >,
6350 consisting only of a linefeed, is considered
6351 whitespace.</P
6352 ></TD
6353 ></TR
6354 ></TABLE
6355 ><DIV
6356 CLASS="NAVFOOTER"
6357 ><HR
6358 ALIGN="LEFT"
6359 WIDTH="100%"><TABLE
6360 SUMMARY="Footer navigation table"
6361 WIDTH="100%"
6362 BORDER="0"
6363 CELLPADDING="0"
6364 CELLSPACING="0"
6365 ><TR
6366 ><TD
6367 WIDTH="33%"
6368 ALIGN="left"
6369 VALIGN="top"
6370 ><A
6371 HREF="part2.html"
6372 ACCESSKEY="P"
6373 >Prev</A
6374 ></TD
6375 ><TD
6376 WIDTH="34%"
6377 ALIGN="center"
6378 VALIGN="top"
6379 ><A
6380 HREF="index.html"
6381 ACCESSKEY="H"
6382 >Home</A
6383 ></TD
6384 ><TD
6385 WIDTH="33%"
6386 ALIGN="right"
6387 VALIGN="top"
6388 ><A
6389 HREF="variables.html"
6390 ACCESSKEY="N"
6391 >Next</A
6392 ></TD
6393 ></TR
6394 ><TR
6395 ><TD
6396 WIDTH="33%"
6397 ALIGN="left"
6398 VALIGN="top"
6399 >Basics</TD
6400 ><TD
6401 WIDTH="34%"
6402 ALIGN="center"
6403 VALIGN="top"
6404 ><A
6405 HREF="part2.html"
6406 ACCESSKEY="U"
6407 >Up</A
6408 ></TD
6409 ><TD
6410 WIDTH="33%"
6411 ALIGN="right"
6412 VALIGN="top"
6413 >Introduction to Variables and Parameters</TD
6414 ></TR
6415 ></TABLE
6416 ></DIV
6417 ></BODY
6418 ></HTML
6419 >