index.fm Page 1003 Thursday, September 12, 2002 12:26 PM

INDEX

A integer (int) function, 184–85 variables, using as array indexes, a command, , 79–80 rand function, 185 171–72 Actions, , 107–08 random number generator, 185–86 Korn shell, 555 Addressing, and sed, 66 srand function, 185–86 Asterisk (*), 35 Algol, 3 shell: awk, 109 command evaluating expressions, 740 Bash shell, 650–51 bash, 646 arithmetic expressions, 689 Bourne shell, 223 tcsh, 876–77 floating point, 733 and filename substitution, 224 Aliases: integer, 729–33 C shell, 351, 352 bash, 646–47 Bourne shell, 257–59 egrep, 59 C shell, 2–4, 6, 345–47 command, 257–58 Korn shell, 457, 459–60 alias loop, 347 floating point, 258–59 metacharacter, 885–86 sed, 69 creating, 346 integer, 257–58 &T shell . See Bourne shell. deleting, 346–47 C shell, 389–91 at command, 953 listing, 345–46 floating point arithmetic, 390–91 autolist variable, tcsh, 863–64 creating, 646–47, 876–77 operators, 389–90 awk, 1, 31, 38, 93–211, 954 defined, 646, 875 shortcut operations, 389 actions, 107–08, 113–16 deleting, 647, 877–78 Korn shell, 508–13 arithmetic functions, 184–86 Korn shell, 2, 4, 6, 453–55, 491–92 integer , 509 arithmetic operators, 135–38 creating, 454 let command, 511–13 integer (int) function, 184–85 listing, 453–54 listing integers, 511 rand function, 185 typeset command, 508 removing, 455 random number generator, 185–86 using different bases, 510–11 tracked aliases, 453, 455 srand function, 185–86 Arithmetic operators, awk, 135–38 listing, 646, 875–76 arrays, 171–80 Arrays: looping, 878 assignment operators, 139 tcsh, 875–78, 939 awk, 171–77 associative arrays, 171–77 Alias loop, 878 Bash shell, 691–93 multidimensional arrays, 176–77 allexport option, set command, 435–38 C shell, 370–73 special for loop, 172–73 Ampersand (&): creating from a string, 373 function, 175–76 awk, 109 shift command, 371–72 subscripts for, 171–77 Bash shell, 627–28 Korn shell, 554–56 using field values as array Bourne shell, 223 creating with the set command, 556 subscripts, 174–75 C shell, 351 TC shell, 910–14 using as array subscripts, Korn shell, 457 Assignment operators, awk, 139 173–74 and quotes, 240 Associative arrays: using variables as array indexes, sed, 70 awk, 171–80 171–72 and tcsh , 879–80 field values, using as array built-in functions, 180–84 –a option, set command, 323 subscripts, 174–75 arithmetic functions, 184–86 ARGC variable: multidimensional arrays (nawk), string functions, 180–84 awk, 144 176–77 user-defined functions (nawk), nawk, 177–80 special for loop, 172–73 186–88 argv, 394–95 split function, 175–76 command line arguments (nawk), ARGV array, 177 strings, using as array subscripts, 177–80, 206–07 ARGV variable, awk, 144 173–74 ARGC, 177–80 Arithmetic: subscripts for, 171–77 ARGV, 177 awk, 135–38, 184–86

1003 index.fm Page 1004 Thursday, September 12, 2002 12:26 PM

1004 Index

awk (cont.): review, 112–22, 131–39, 188–92, Backslash (\): commands: 202–10 Bash shell, 683–84 from within a , 101–02 scripting, 122 Bourne shell, 240–41 in a script file, 111 string functions, 180–84, 202–06 C shell, 379 comparison expressions, 125–30 gsub function, 180–81 Korn shell, 457, 485–86 compound patterns, 128–29 index function, 181 in metacharacter, 654–55 computation, 127–28 length function, 181 and quotes, 240–41, 683–84, 921–22 conditional expressions, 126–27 match function, 182–83 backslash_quote variable, tcsh, 921–22 data validation program, 129–30 split function, 183 Bang, 638, 851–54, 923 range patterns, 129 sprintf function, 183–84 banner command, 954 relational operators, 125–26 sub function, 180–81 command, 954–55 conditional operator, 138–39 substr function, 182 bash, 599–600 conditional statements, 165–67 user-defined functions (nawk), 186–88, BASH_ENV (ENV) variable, 723, 996 if/else else if statements, 166–67 210 .bash_history file, 632, 633 if/else statements, 165–66 versions of, 93 .bash_login file, 602–603 if statements, 165 awk arrays: .bash_logout file, 610 control functions, 209 associative arrays, 171–79 .bash_profile file, 601–02, 663, 693 defined, 93 subscripts for, 171–77 .bashrc file, 603, 605–07, 646 equality testing, 131–32 multidimensional arrays (nawk), 176–77 BASH_VERSION variable, 599 statement, 170 special for loop, 172–73 batch command, 953 split function, 175–76 fields, 104–06 bc command, 955 using field values as array subscripts, separators, 105–06 bdiff command, 955 174–75 fixed fields, 194–96 beepcmd alias, tcsh, 875 using strings as array subscripts, 173–74 bundling/unbundling files, 196–97 BEGIN patterns, 145–46, 157–60 using variables as array indexes, 171–72 empty fields, 194–95 bg command, 349–50, 881–82 awk programming, 141–211 generating form letters, 198–201 bgnice option, set command, 438 awk script with BEGIN and END, multiline records, 197–98 Binary numbers, and bash, 729 159–60 /bin/csh, 5, 332 numbers with $/commas/other BEGIN variables, 145–46, 157–58 Binding keys characters, 195–96 END patterns, 146 and bash, 610 –f option, 101 files, closing, 150–51 keybinding characters, 859–60 format of, 94–96 numeric and string constants, 141–42 and tcsh, 858–62 input from commands, 95–96 initialization and type coercion, bindkey command, tcsh, 855, 858–62 input from files, 94–95 141–42 /bin/ksh, 5, 434 formatting output, 96–101 pipes, 149–51, 162–63 /bin/login, 5, 11–12, 16, 332, 601, 830 OFMT variable, 98 closing, 150–51, 163 /bin/sh, 5 function, 98–101, 161–62 redirection, 146–49, 162 Bash shell, 599–827 print function, 96–98 input redirection, 147–49 aliases, 646–47 form letters, generating, 198–201 output redirection, 146–47 arrays, 691–93 FS variable, 105 system function, 150–51 command line: function of, 93 user-defined variables, 142–45 components of, 626 getline function, 147–49, 207–08 assignment operators, 142 editing, 641–45 input field separators, 119–22 at the command line, 143 and eval command, 810–12 interaction with the shell, 201–02 built-in variables, 144–45, 153–57 exit status, 625–26 logical NOT operator, 135 decrement operators, 143 and getopts command, 804–10 logical operators, 134 said, 151–52 order of processing, 622 loops, 168–69 fields variables, 143–44 parsing, 810–12 break statement, 169 increment operators, 143, 151–52 shortcuts, 631–58 continue statement, 169 post-increment operator, 143 substitution, 686–89 for loop, 168–69 pre-increment operator, 143 commands. See also specific commands. loop control, 169 –v option (nawk), 143 auto-completion of, 631–32 while loop, 168 variables, 141–46 background vs. foreground, 627–28 match operator (tilde), 110 Awk Programming Language, The built-in, 623, 624, 714–16, 818–21 next statement, 170 (Aho/Kernighan/Weinberger), conditional, 626–27, 739–63 NF variable, 104 129–30, 196, 198 editing, 638, 641–45 patterns, 106–07, 112–13 exit status, 625–26, 739–40 program control statements, 170 B grouped, 626 range operator, 138 Background command, tcsh, 881–82 history file, 632–45 records, 102–03 Background jobs, 339 order of processing, 622 $0 variable, 102–03 and ampersand, 348 reexecuting, 638 NR variable, 103 bash, 627–28, 786 contrasted with other shells, 599, 989–98 record separator, 102 and loops, 786 debugging, 802–04 regular expressions, 108–10 and suspend key sequence, 348 and directory stack, 647–49 metacharacters, 109 tcsh, 845, 879–81 editors, 641–45 in pattern and action combinations, Backquotes, and tcsh command substitution, environment, 602–10 116–19 918–21 environment variables, 663–81 relational operators, 132–34 index.fm Page 1005 Thursday, September 12, 2002 12:26 PM

Index 1005

Bash shell (cont.): wildcards, 649–50, 656–57, 760 continue command, 292–93 evaluating expressions: Bourne shell, 2–4, 213–330 exec command, 298–300 arithmetic expressions, 689 arithmetic, 257–59 for command, 280–83 command, 740–46 expr command, 257–58 IFS and loops, 300–01 filename substitution, 650–58 floating point arithmetic, 258–59 I/O redirection and subshells, file test operators, 756 integers, 257–58 295–97 floating point arithmetic, 733 built-in commands, 323–24 looping control commands, 289–95 functions, 693–97, 788–96 case command, 277–80 nested loops, 294–95 and globbing, 650–58 command line, 220–23 piping loop output to a help feature, 714, 715 arguments, 259–64 command, 297–98 history of, 599–600 commands in the background, shift command, 289–91 initialization files, 602–10 222–23 until command, 287–89 input, 697–703, 726–29 conditional execution of commands, while command, 284–87 integers, 729–33 222 metacharacters, 223 invocation options, 707–09 exit status, 221 parsing the command line, 320–21 I/O redirection: grouping commands at, 222 and pipes, 250–51 exec command and, 699–703 multiple commands at, 221 positional parameters, 259–64 here document and, 706–707 substitution, 243 how $* and $@ differ, 262–64 subshells and, 784–86 conditional expressions, 264–77 set command, 260–62 job control, 628–30 checking for null values, 270–71 programming with, 253–330 loops: exit command and the ? variable, basic types, 763–73 268–70 quoting, 240–42 break command, 780–81 file testing, 274–75 backslash, 240–41 IFS and loops, 787–88 if command, 266–68 double quotes, 242 I/O redirection and subshells, if/elif/else command, 273–74 single quotes, 241–42 784–86 if/else command, 271–73 special metacharacters requiring for menu creation, 763–68 null command, 275–77 quotes, 240 nested loops, 782–84 test command, 265–66 set command, 322–23 running in background, 786 testing exit status, 264–65 shell invocation options, 321 select command, 773–77 environment, 214–20 shell script creation, 253–55 metacharacters, 649–50 dot command, 220 comments, 254 options: /etc/profile file, 214–16 executable statements and Bourne debugging, 803 hash command, 219–20 shell constructs, 254 processing command line, 804–10 initialization files, 214 first line, 253 set command, 610–13, 709–11, primary prompt, 217 making the script executable, 254 815–16 .profile file, 216–17 read command, 255–57 shell invocation, 707–09, 812–14 prompts, 217–18 scripting session, 254–55 shopt command, 613–15, 711–13, search path, 218–19 starting, 213–14 817–18 secondary prompt, 217–18 trapping signals, 308–14 output, 697–703, 784–86 environment variables, 229–31 debugging, 312–14 and pipes, 704–05, 786 eval command, 320–21 ignoring signals, 310 and POSIX standards, 599 filename substitution, 224–27 listing traps, 310–11 and printf command, 670–72 asterisk, 224 resetting signals, 309 positional parameters, 678–80 escaping metacharacters, 226–27 traps in functions, 311–12 prompts, 600, 615–18, 773–75 square brackets, 225–26 variables, 227–39 quoting, 681–86 functions, 6, 243–45, 301–07 environment variables, 229–31 backslash, 683–84 defining, 243–45 local variables, 227–29 double quotes, 685–86 and dot command, 305–07 wildcards, 223 single quotes, 684–85 function arguments, and return Bourne, Stephen, 3 special metacharacters requiring value, 303–04 Brackets. See Square brackets ([ ]). quotes, 682 listing/unsetting, 245 break command: shell script creation, 723–25 storing, 305–07 Bash shell, 780–81 file testing, 756–58 traps in, 311–12 Bourne shell, 291–92 starting, 600–01, 812 unsetting, 302 trapping signals, 797–802 getopts function, 314–20 Korn shell, 546–47 variables: here document: and loops, 417–19 environment variables, 663–81, 723 and creating menus, 279–80 break statement, awk, 169 local variables, 660–62 and redirecting input, 252–53 Built-in commands, 6 modifying, 672–76 history of, 3–4 Bash shell, 623, 624, 714–16, 818–21 naming conventions, 659 I/O redirection, 245–50 Bourne shell, 323–24 null values in, 750–51 exec command and, 247–50 C shell, 423–27 printing values of, 669–70 operators, 245 Korn shell, 582–86 read-only, 662 local variables, 227–29 TC shell, 928–48 setting, 659–60, 663 loops, 280–301 Built-in variables, tcsh, 940–48 special, 678–81 $* and $@ variables in wordlists, builtin command, bash, 623, 624 unsetting, 669 283–84 builtins command, tcsh, 928–29 versions, 599–600 break command, 291–92 Bundling and unbundling files, 196–97 index.fm Page 1006 Thursday, September 12, 2002 12:26 PM

1006 Index

C Korn shell, 441–53 null command, 275–77 , 955–56 commands in the background, 444 test command, 265–66 Calculations. See Arithmetic. command line editing, 447–49 testing exit status, 264–65 Caret (^), 32, 33 conditional execution of commands, C shell, 339, 395–412 awk, 109 443–44 Korn shell, 443–44 in bash history command, 638 exit status, 442–43 TC shell, 844–45 egrep, 58 multiple commands and command Conditional operator, awk, 138–39 sed, 69 grouping, 443 Conditionals, evaluating commands within, Caret inside square brackets, 37 order of processing commands, 404–05 egrep, 59 441–42 Conditional statements, awk, 165–67 sed, 69 TC shell, 842–75 if/else else if statements, 166–67 case command: arguments/switches, 947–48 if/else statements, 165–66 Bash shell, 760–63 components of, 842 if statements, 165 here document and, 762–63 editing, 855–62 continue command: Bourne shell, 277–80 exit status, 842–43 awk, 169 here document and, 279–80 shortcuts, 846–75 Bash shell, 781–82 Korn shell, 532–34 Command line arguments: Bourne shell, 292–93 here document, 533–34 Bash shell, 709, 734–39 C shell, 420–21 Case modifiers, tcsh, 917–18 Bourne shell, 259–64 Korn shell, 547–48 command, 706–07, 956 C shell, 394–95 and loops, 420–21 command, 15 Korn shell, 513–16 Coprocesses, Korn shell, 570–72 CDPATH variable, Korn shell, 469 Command line history: correct variable, editor, 874–75 Child shell, 663 Bash shell, 641, 710 command, 958 command, 724, 956–57 C shell, 340–45 cpio command, 958–59 changing permissions with, 13–14 displaying, 341–42 command, 959 command, 215–21, 957 reexecuting commands, 343–45 crypt command, 959 file descriptors, 16 saving, 341 csh command, options to, 391–94 home directory, 15 setting, 340–41 .cshdirs file, 831 pipes, 19–21 Korn shell, 444–51 .cshrc file, 831 redirection, 16–18 Command substitution: C shell, 2, 3, 331–432 variables, 16 Bash shell, 686–89 aliases, 6, 345–47 chsh command, 3 Bourne shell, 243 alias loop, 347 clear command, 436, 957 C shell, 375–78 creating, 346 command, 957 and wordlists, 376–78 deleting, 346–47 COLUMNS variable: Korn shell, 487–89 listing, 345–46 bash, 773 TC shell, 918–21 arithmetic, 389–91 Korn shell, 469 Commands. See also specific commands. floating point arithmetic, 390–91 Comma, in sed, 76–77 Bash shell, 714–16, 815–21 operators, 389 command command, bash, 623 emacs editor, 643–44, 857 shortcut operations, 389 Command grouping, C shell, 338–39 nesting arrays, 370–73 Command line: in bash, 686, 751, 782–84 creating from a string, 373 Bash shell: TC shell, 928–48 shift command, 371–72 components of, 621–28 vi editor, 642–43, 856 built-in commands, 423–27 editing, 641–44 Comments, script: command line, 337–45 and eval command, 810–12 purpose of, 724 command grouping, 338–39 exit status, 625–26 use of pound sign (#) in, 723 commands in the background, and getopts command, 804–10 Comparison expressions, awk, 125–30 339–40 order of processing, 622–24 complete command, tcsh, 866–71 conditional execution of commands, parsing, 810–12 complete variable, tcsh, 865–66 339 shortcuts, 631–58 Completion, tcsh: exit status, 337–38 substitution, 686–89 mechanism, 862–71 command line arguments, 394–95 Bourne shell, 220–23 word types, 868–69 positional parameters and argv, commands in the background, Compound patterns, awk, 128–29 394–95 222–23 compress command, 957–58 command line history, 340–45 conditional execution of commands, Computation. See Arithmetic. displaying, 341–42 222 Computation within patterns, awk, 127–28 reexecuting commands, 343–45 exit status, 221, 264–65 Conditional commands: saving, 341 grouping commands, 222 awk, 126–27, 165–67 setting, 340–41 multiple commands at, 221 Bash shell, 626–27, 739–63 command substitution, 375–78 parsing, 320–21 Bourne shell, 264–77 and wordlists, 376–78 C shell, 337–45 checking for null values, 270–71 csh command, options to, 391–94 command grouping, 338–39 exit command and the ? variable, debugging scripts, 391–94 commands in the background, 268–70 environment, 332–37 339–40 file testing, 274–75 .cshrc file, 332–33 conditional execution of commands, if command, 266–68 hashstat command, 335 339 if/elif/else command, 273–74 initialization files, 332 exit status, 337–38 if/else command, 271–73 .login file, 333–34 index.fm Page 1007 Thursday, September 12, 2002 12:26 PM

Index 1007

C shell, environment (cont.): with the :q modifier, 382–84 options, 660 primary prompt, 336–37 single quotes, 379–80 and read-only variables, 662 rehash command, 335 steps to successful quoting, 381–82 DEC PDP-10, 829 search path, 335 variables, 382 Decrement operators, awk, 143, 151–52 secondary prompt, 336–37 with the :x modifier, 384 Defining functions, Korn shell, 490–91 shell prompts, 336–37 reading user input, 387–88 command, 960 source command, 336 creating a wordlist from the input Directory stack: filename substitution, 351–52 string, 388 and bash, 647–49 shell metacharacters and, 352 $< variable, 387–88 manipulating, 647–49, 871–73 flow control and conditional constructs, redirection, 356–65 and tcsh, 871–73 395–412 appending output to an existing file, variables, 872 associativity, 396–98 360 dirs command, bash, 647 comparison operators, 396 here document, 358–60 disown command, bash, 630 debugging expressions, 400–01 noclobber variable, 363–65 Division. See Arithmetic. evaluating commands within redirecting input, 357–58 Dollar sign ($), 34 conditionals, 404–05 redirecting output, 360 awk, 109 exiting from a shell script, 403 redirecting output and error, 361–62 Bash shell, 601, 615–16 exit status and the status variable, redirection metacharacters, 357 Bourne shell, 223 402–03 separating output and errors, 362–63 C shell, 350 file testing, 406–08 setuid scripts, 422 egrep, 58 goto, 405–06 shell script creation, 385–87 Korn shell, 457 if/else if statements, 401–02 comments, 385 as metacharacter, 899 if/else statements, 399–400 example scripting session, 386–87 prompt, 615–16 if statement, 398, 401 first line, 385 and quotes, 240 logical operators, 396 making the script executable, sed, 69 nesting conditionals, 408–09 385–86 in tcsh array names, 910 nesting switches, 411–12 special variables, 373–75 in tcsh variables, 899, 912 precedence, 396–98 pathname variable modifiers, Dot (.), 34 switch command, 409–11 374–75 awk, 109 testing expressions, 396 starting, 331–32 sed, 69 using the status variable in a script, storing scripts, 423 dot command: 403–04 variables, 365–73 Bash shell, 621, 789, 793–96 history of, 3 arrays, 370–73 Bourne shell, 220 interrupt handling, 421–22 built-in local variables, 368 and functions, 305–07 job control, 347–50 curly braces, 366 Korn shell, 440–41 ampersand and background jobs, environment variables, 368–70 Double quotes: 348 local variables, 366–67 Bash shell, 685–86 bg command, 349–50 set command, 367–68 Bourne shell, 242 fg command, 349–50 shift command, 371–72 C shell, 380–81 jobs command, 349 See also special variables. Korn shell, 475 suspend key sequence and C shell script, 23–25 TC shell, 924–25 background jobs, 348 .cshrc file, 332–33 command, 961 loops, 412–21 Curly braces ({ }): dup system call, 21 break command, 417–19 in bash commands, 653–54 continue command, 420–21 C shell, 351, 354, 366 E foreach loop, 412–15 in tcsh commands, 887–88, 904–05 command, 233–34, 961 nested loops, 419–20 command, 959–60 bash, 669–70 repeat command, 416–17, 419–20 cwdcmd alias, tcsh, 875 tcsh, 900–02 shift command, 417 Echoing, 391–94, 400–01 while loop, 415–16 D echo_style variable, tcsh, 900, 901–02 metacharacters, 337, 350–56, 378 Dash, 36 e command, sed, 77–78 asterisk, 352 Data-validation program, awk, 129–30 Editing commands, and Korn shell, 450–51 curly braces, 354 date command, 960 editor, 4 escaping, 354–55 d command, sed, 72–73 Editors: expanding, 352–56 Debugging: bash built-in, 641 filec variable, 355–56 Bash shell, 802–04 emacs: filename substitution, 351–52 Bourne shell, 312–14 and bash, 641, 643–44 question mark, 352–53 C shell, 391–94 commands, 643–44, 857 square brackets, 353–54 Korn shell, 573–75 and spelling correction, 874–75 tilde expansion, 355 TC shell, 948 and tcsh, 855, 857 turning off with noglob, 356 declare command, bash: tcsh built-in, 855–62 pipes, 356–65 and arrays, 691–92 vi: programming with, 385–427 contrasted with typeset command, and bash, 641, 642–43 quoting, 378–84 659–60 commands, 642–43, 856 backslash, 379 and environment variables, 663–65 and spelling correction, 874–75 double quotes, 380–81 and functions, 697, 788 and tcsh, 855–56 quoting game, 381 and integer arithmetic, 729–33 index.fm Page 1008 Thursday, September 12, 2002 12:26 PM

1008 Index

EDITOR variable: TC shell, in history command, 851, Korn shell, 459–65 Bash shell, 644 854–55, 923, 924 asterisk, 459–60 Korn shell, 436, 469 exec command: escaping, 462 Effective group identification (EGID), 12 and loops: new ksh metacharacters, 463–64 Effective user identification (EUID), 12 Bourne shell, 298–300 noglob variable, 465 egrep, 31, 38, 58–62, 961–62 Korn shell, 552–53 question mark, 460–61 examples, 59–61 and redirection: regular expression wildcards, 464 regular expression metacharacters, Bash shell, 699–703 square brackets, 461–62 58–59 Bourne shell, 247–50 tilde and hyphen expansion, 462–63 asterisk, 59 Korn shell, 495 TC shell, 885–89 caret, 58 exec system calls, 9, 15 FILENAME variable, awk, 144 caret with square brackets, 59 Executable programs, 6 Files. See also specific files. dollar sign, 58 exit command: and directory stack, 647–49, 871–73 square brackets, 59 Bash shell, 748–50, 788 shell initialization review of, 61–62 Bourne shell, 268–70 bash, 602 elif command, bash, 753–55, 760 Korn shell, 529–31 tcsh, 832–36 else command, bash, 753–55, 760 exit statement, awk, 170 File testing, 406–08 emacs built-in editor: Exit status: Bash shell, 756–58 Bash shell, 641, 643–44 Bash shell, 625–26, 739–40 Bourne shell, 274–75 commands, 643–44, 857 Bourne shell, 221, 264–65 C shell, 406–08 Korn shell, 447, 449–50 C shell, 337–38 Korn shell, 521, 522–23 and spelling correction, 874–75 and , 47–48 test command and, 407–08 TC shell, 855, 857 Korn shell, 442–43, 516–18 command, 963–64 emacs option, set command, 438 TC shell, 842–43 finger command, 964 Empty fields, 194–95 exit system call, 9–10 fi statement, bash, 745–48, 751 enable command, bash, 623, 624 Expansion order, bash, 690 fix command, bash, 634–37 enchance setting, tcsh complete variable, export command, bash, 663, 694–95, 788, Fixed (fast) grep, 62 865–66 789 Fixed fields, awk, 194–96 END patterns, 146, 158–60 expr command, 962 Flag arguments, tcsh, 947–48 env command, tcsh, 909 Bourne shell, 257–58 Floating point arithmetic: ENV file, 435, 436–37 Bash shell, 733 Environment: F Bourne shell, 258–59 Bourne shell, 214–20 fast grep, 62 C shell, 390–91 C shell, 332–37 fc command, 451, 634–37, 644–45 Flow control: Korn shell, 434–38 FCEDIT variable: C shell, 395–412 Environment variables: Bash shell, 644–45 Korn shell, 518–32 Bash shell, 602, 663–81 Korn shell, 450–51, 469 fmt command, 964–65 Bourne shell, 229–33 fg command, 349–50, 881–82 FNR variable, awk, 144 echo command, 233–34 fgrep, 962–63 command, 965 listing set variables, 231–32 Fields, 104–06 –f option, set command, 323 positional parameters, 237–38 awk, 104–06 for command: setting, 229 field separators, 105–06 Bash shell, 763–68 unsetting variables, 233 changing at the command line, Bourne shell, 280–83 variable expansion modifiers, 105 Korn shell, 534–36 234–37 input field separator, 105 foreach loop, 412–15 C shell, 368–70 output field separator, 96, 106 Foreground command, tcsh, 881–82 printing, 369–70 using than one, 105 Foreground processing, bash, 627–28 Korn shell, 468–71 and bash loops, 787–88 fork system calls, 8–9, 15 setting, 468–69 Field values, using as array subscripts, for loop, awk, 168–69 special, 469–71 174–75 Format specifiers, printf command: TC shell, 837, 907–10 Field variables, awk, 143–44 bash, 671 ENV variable, Korn shell, 436–37, 469 fignore variable, tcsh, 864–65 tcsh, 903 –e option, set command, 323 file, 963 Form letters, generating with awk, 198–201 ERRNO variable, Korn shell, 469 File creation mask, 12–13 Fox, Brian, 599 Error handling, for tcsh, 894–97 filec variable, 355–56 FPATH variable, Korn shell, 470 Error messages, sed, 68–70 File descriptors, 16 FS variable, awk, 105, 144 esac command, bash, 760 Filename expansion, Korn shell, 452–53 ftp, 965 /etc/motd file, 434 Filename substitution: function keyword, bash, 693–96 /etc/passwd, 12 Bash shell, 650–58 Functions, 6 /etc/profile file, 12–13, 214–16, 434–35 Bourne shell, 224–27 awk: eval command: asterisk, 224 arithmetic functions, 184–86 Bash shell, 810–12 escaping metacharacters, 226–27 built-in functions, 180–84 Bourne shell, 320–21 square brackets, 225–26 control functions, 209 , 31 C shell, 351–52 string functions, 180–84, 202–06 Exclamation point (!): shell metacharacters and, 352 user-defined functions (nawk), C shell, 350 escaping metacharacters, 226–27 186–88, 210 index.fm Page 1009 Thursday, September 12, 2002 12:26 PM

Index 1009

Functions (cont.): fixed (fast) grep, 62 if/else statements: Bash shell, 693–97, 788–96 how it works, 44–47 awk, 165–66 defining, 693, 788 input, 44 Bash shell, 739, 751–53 Bourne shell, 243–45, 301–07 meaning of, 43–44 Bourne shell, 271–73 and dot command, 305–07 options, 47, 54–58 C shell, 399–400 function arguments and return value, –c option, 56 Korn shell, 527 303–04 –i option, 55, 57 if statements, 398–99, 401 storing, 305–07 variable, 57 IFS variable, 230 traps in, 311–12 –l option, 56, 58 Korn shell, 470 unsetting, 245, 302 –n option, 55, 58 and loops, 787–88 exporting, 789 –s option, 57 ignoreeof option, set command, 438 Korn shell, 6, 489–93, 556–63 –v option, 55, 57 Increment operators, awk, 143, 151–52 and aliases, 491–92 –w option, 56, 57 Inheritance, 11–22 autoloaded functions, 561–63 with pipes, 54 chmod, 13–14 defining, 490–91, 557 regular expression metacharacters, 46 chown, 15–22 exported functions, 559–61 See also egrep; fgrep. file creation mask, 12–13 listing, 492, 558 Group identifications (GID), 12 ownership, 12 local variables and the return value, groups command, 966 Initialization files: 558–59 gsub function, awk, 180–81 Bash shell, 602–10 typeset command and function Bourne shell, 214–17 options, 558–59, 561–63 H C shell, 332–35 unsetting, 492–93, 558 h and g commands, sed, 83–86 Korn shell, 434–35 listing, 697 hash command: TC shell, 831–36 passing arguments to, 790 Bash shell, 620 inittab, 332, 434 recursive, 789 Bourne shell, 219–20 Input field separators, 105, 119–22 rules for using, 788–89 hashstat command: .inputrc file, bash, 610 storing, 793–96 C shell, 335 Integer arithmetic, bash, 729–33 unsetting, 697, 789 TC shell, 838 Internal field separator (IFS), and loops, using traps in, 801–02 Hash table, tcsh, 837–38 300–01, 787–88 help command, bash, 623, 714, 715 Interrupt handling, C shell, 421–22 G here document, 252–53, 279–80, 358–60, Invocation options: Bash shell, 707–09 getline function, awk, 147–49 498, 533–34 Bourne shell, 322 getopts, 965 Bash shell, 706–07 Korn shell, 587 Bash shell, 804–10 and case command, 762–63 I/O redirection, 16–18 Bourne shell, 314–20 Korn shell, 498–500 Bash shell, 697–703, 784–86 and redirecting input, 252–53 contrasted with command, 804 Bourne shell, 295–97 Korn shell, 575–81 TC shell, 891–93 Korn shell, 549 variables, 808–10 Hexadecimal numbers, and bash, 729, 731 HISTEDIT variable, 470 and loops, 784–86 getty process: TC shell, 890–99 bash, 601 HISTFILE variable, 444, 470 tcsh, 830 HISTFILESIZE variable, bash, 632, 633 Global variables, 663, 899, 907 history command, 445–51 J Globbing, 351, 650–58 bash, 632–33, 634, 638–41 Job control: defined, 650 tcsh, 846–55 Bash shell, 628–30 extended, 657–58 .history file, tcsh, 846–47, 850–55 C shell, 347–50 metacharacters used for, 650–56 history list, tcsh, 846–48 ampersand and background jobs, 348 turning off, 656 history variable, tcsh, 847–48 bg command, 349–50 gmacs option, set command, 438 HISTSIZE variable, 436, 444, 470 fg command, 349–50 gnu awk (gawk), 93 Holding buffer, 83 jobs command, 349 goto, 405–06 Home directory, 15 suspend key sequence and Greater than-ampersand (>&), C shell, 351 HOME variable, 5, 229, 230, 470, 663 background jobs, 348 Greater than-exclamation point (>!), C shell, –h option, set command, 323 Korn shell, 455–56 351 HOSTNAME variable, 436 TC shell, 878–83 Greater than sign (>): HP-UX, 829 jobs command, 349 C shell, 351 Hyphen expansion, bash, 655–56 bash, 628–30 and quotes, 240 tcsh, 880–81 grep, 1, 31, 38, 43–63, 443, 965–66 I Joy, Bill, 3 commands, review of, 57–58 i command, sed, 80 jsh command, 966 egrep, 58–62 id command, 966 examples, 59–61 if command, bash, 739, 745–51, 760 K regular expression metacharacters, if/elif/else statements: Kernel, 1 58–59 Bash shell, 753–55 system calls, 6 review of, 61–62 Bourne shell, 273–74 Key bindings: examples with regular expressions, Korn shell, 527–29 and bash, 610 48–53 if/else and elseif statements, awk, 166–67 keybinding characters, 859–60 and exit status, 47–48 and tcsh, 858–62 index.fm Page 1010 Thursday, September 12, 2002 12:26 PM

1010 Index

Keyboard, customizing, 610 escaping, 462 pipes, 497–98 commands, 22 new ksh metacharacters, 463–64 positional parameters, 513–16 and bash, 628–30, 797 noglob variable, 465 and set command, 514–16 –k option, set command, 323 question mark, 460–61 privileged scripts, 582 Korn, David, 2, 3 regular expression wildcards, 464 programming with, 501–87 Korn shell, 2, 3, 433–597 square brackets, 461–62 prompts, 439–40 aliases, 6, 453–55 tilde and hyphen expansion, 462–63 primary prompt, 439 creating, 454 flow control and conditional constructs, secondary prompt, 439 listing, 453–54 518–32 quotes, 485–87 removing, 455 exit command, 529–31 backslash, 485–86 tracked aliases, 455 file testing, 521, 522–23 double quotes, 47 arithmetic, 508–13 if command, 523–24 single quotes, 486 integer type, 509 if/elif/else command, 527–29 read command, 504–08 let command, 511–13 if/else command, 527 file descriptors, 506–07 listing integers, 511 let command and testing numbers, format, 504 and typeset command, 508 526–27 options, 505 using different bases, 510–11 logical operators, 521 reading through files, 507–08 arrays, 554–56 new-style Korn test, 525–26 redirection, 493–96 creating with the set command, 556 new test command, 519–21 and the child shell, 495–96 associative arrays, 555 new test flags, 522 and exec command, 495 built-in commands, 582–86 null command, 531–32 restricted shells, 582 case command, 532–34 old-style Bourne test, 525, 526 revisions to, 3 and here document, 533–34 old test command, 518–19 search path, 440–41 command line, 441–44 functions, 5–6, 489–93, 556–63 dot command (.), 440–41 commands in the background, 444 and aliases, 491–92 security, 582 conditional execution of commands, autoloaded functions, 561–63 starting up, 433–34 443–44 defining, 490–91, 557 command, 500 exit status, 442–43 exported functions, 559–61 TMOUT variable, 500–01 multiple commands and command listing, 492, 558 trap command, 563–69 grouping, 443 local variables and the return value, ignoring signals, 565 order of processing commands, 558–59 listing traps, 565–68 441–42 typeset command and function pseudo/fake signals, 564–65 command line arguments, 513–16 options, 561–63 resetting signals, 565 command line history, 444–51 unsetting, 492–93, 558 traps and functions, 568–69 command line editing, 447–48 getopts: variables, 465–85 emacs comands, 449–50 processing command line options environment variables, 468–71 FCEDIT and editing commands, with, 575–81 escape sequences, 475–76 450–51 sample scripts, 577–81 listing set variables, 471–73 history command/redisplay here document and redirecting input, local variables, 465–67 commands, 445–46 498–500 positional parameters, 482–84 reexecuting commands with the r history of, 3 printing the values of variables, commands, 446–47 invocation arguments, 587 474–75 vi built-in editor, 448–49 job control, 455–56 typeset command, 481–82 command substitution, 487–89 loops, 534–54 unsetting variables, 473 coprocesses, 570–72 $* and $@ variables in wordlists, variable expansion substrings, creating a shell script, 501–04 536–37 479–80 comments, 501 break command, 546–47 variable expressions and modifiers, executable statements and Korn shell continue command, 547–48 476–79 constructs, 501 exec command and, 552–53 wildcards, 459–65 first line, 501 for command, 534–36 Korn shell script, 26–27 making a script executable, 502 IFS (internal field separator) and, ksh program, 434 naming and storing scripts, 501–02 553–54 .kshrc file, 434–37 scripting session, 503–04 I/O redirection and, 549 using a script as an argument to ksh, looping commands, 545 L 503 nested loops, 548–49 length function, awk, 181 debugging, 573–75 piping loop output to a UNIX Less than sign (<): environment, 434–38 command, 551 C shell, 351 ENV file, 435, 436–37 redirecting loop output to a file, and quotes, 240 /etc/profile file, 434–35 550–51 let command: initialization files, 434 running loops in the background, contrasted with declare command, 729 .profile, 434, 435–36 551–52 contrasted with test command, 740 set –o options, 437–38 select command and menus, 541–45 and Korn shell, 511–13 exit status, testing, 516–18 shift command, 545–46 operators, 745 filename expansion, 452–53 until command, 540–41 purpose of, 732–33 filename substitution, 459–65 while command, 537–40 line command, 966 asterisk, 459–60 metacharacters, 457–59 LINENO variable, Korn shell, 470 index.fm Page 1011 Thursday, September 12, 2002 12:26 PM

Index 1011

LINES variable: foreach loop, 412–15 Nested loops: Bash shell, 773 nested loops, 419–20 Bash shell, 782–84 Korn shell, 470 repeat command, 416–17, 419–20 Bourne shell, 294–95 listjobs variable, tcsh, 880–81 shift command, 417 C shell, 419–20 local function, bash, 691, 693 while loop, 415–16 Korn shell, 548–49 Local variables: Korn shell, 534–54 Nesting conditionals, 408–09 Bash shell, 660–62 I/O redirection and, 549 Nesting switches, 411–12 Bourne shell, 227–29 lp command, 966–67 New awk, 93 listing set variables, 232–33 lpq command, 967 newgrp, 970 positional parameters, 237–38 lpr command, 967 Newline, and quotes, 240 scope of, 228–29 lpstat command, 967 news command, 970 setting read-only variables, 229 ls command, 967–68 next statement, awk, 170 unsetting variables, 233 NF variable, awk, 104, 144 variable expansion modifiers, M command, 970 234–37 Macros, 610 noclobber option, set command, 438 C shell, 366–68 Magic number, 723 noclobber variable, 363–65, 893, 897–99 echo command, 233–34 MAILCHECK variable, 230 noexec option, set command, 438 Korn shell, 465–67 Korn shell, 470 noglob variable: scope of, 466–67 mail command, 968 Bash shell, 656 setting read-only variables, 467–68 MAILPATH variable, 230 C shell, 356 setting/referencing, 465–66 Korn shell, 470 Korn shell, 465 Logical NOT operator, 135 MAIL variable, 230 TC shell, 889 Logical operators, awk, 134 Korn shell, 470 , 970–71 .login file, 332, 832, 836 mailx command, 968 nolog option, set command, 438 login program, 830 Major shells, 2 –n option: Login shell: command, 968–69 bash, 802 defined, 5 markdirs option, set command, 438 set command, 323 parsing the command line, 5–6 match function, awk, 182–83 nonomatch variable, tcsh, 888 and system startup, 5 Menus, creating, 773–77 –noprofile option, 610 types of commands, 6 , 969 notify option, set command, 438 logname command, 966 Metacharacters: nounset option, set command, 438 LOGNAME variable, 5, 229, 230, 663 awk, 109 NR variable, awk, 103, 144 Loops: Bash shell, 649–50 n-type completion, tcsh, 866, 871 alias, 878 special with quotes, 682 null command: awk, 168–69 Bourne shell, 223 Bash shell, 758–60 for loop, 168–69 C shell, 337, 350–56, 378 Bourne shell, 275–77 loop control, 169 asterisk, 352 and Korn shell, 531–32 while loop, 168 curly braces, 354 Null values, in bash variables, 750–51 Bash shell, 763–88 escaping, 354–55 Numeric and string constants, awk, 141–42 breaking out of, 778–84 expanding, 352–56 initialization and type coercion, 141–42 IFS and loops, 300–01, 787–88 filec variable, 355–56 I/O redirection and subshells, filename substitution, 351–52 784–86 O question mark, 352–53 and menu creation, 763–68 Octal numbers, and bash, 729 square brackets, 353–54 and null command, 758 command, 971 tilde expansion, 355 running in background, 786 OFMT variable, awk, 98, 144 turning off with noglob, 356 Bourne shell, 280–301 OFS variable, awk, 144 Korn shell, 457–59 $* and $@ variables in wordlists, Old awk, 93 TC shell, 884–89 283–84 OLDPWD variable, Korn shell, 470 Meta key, 874 break command, 291–92 –o option, set command, 610–13 command, 969 continue command, 292–93 OPTARG variable, getopts, 808–10 Modifiers: control commands, 289–95 OPTIND variable, getopts, 808–10 bash variable, 672 exec command, 298–300 Options: for command, 280–83 tcsh case, 914–18 bash declare command, 660 tcsh pathname, 916–17 IFS and loops, 300–01 bash set command, 815–16 I/O redirection and subshells, tcsh quoting, 926–28 bash shell invocation, 812–14 295–97 monitor option, set command, 438 bash shopt command, 711–13, 817–18 looping control commands, 289–95 more command, 969 tcsh bindkey command, 862 nested loops, 294–95 Multidimensional arrays, nawk, 176–77 tcsh echo command, 900–01 piping loop output to a UNIX Multiline records, awk, 197–98 tcsh history command, 846–47 command, 297–98 Multiplication. See Arithmetic. ORS variable, awk, 144 shift command, 289–91 command, 969 Output field separator, 96, 106 until command, 287–89 Ownership, 12 while command, 284–87 N effective group identification (EGID), 12 C shell, 412–21 nawk, 176–77, 970 effective user identification ((EUID), 12 break command, 417–19 n command, sed, 81 group identifications (GID), 12 continue command, 420–21 user identification (UID), 12 index.fm Page 1012 Thursday, September 12, 2002 12:26 PM

1012 Index

P Printer commands: single quotes, 681, 684–85 pack command, 971 bash, 670–72 Bourne shell, 240–43 Parameter expansion, variable, 672–76 tcsh, 902–04 combining quotes, 1000 Parent shell, 663 printexitvalue variable, tcsh, 842–43 C shell, 378–84 Parentheses: printf function: with the :q modifier, 382–84 C shell, 351 awk, 98–101, 161–62 with the :x modifier, 384 and quotes, 240 conversion characters, 98, 100 backslash, 379 passwd command, 971 fields, 98 double quotes, 380–81 passwd file, 5, 434 format specifiers, 98, 101 quoting game, 381 command, 971–72 printf modifiers, 98, 100 single quotes, 379–80 PATH variable: width of fields, 98 steps to successful quoting, 381–82 Bash shell, 619, 663 bash, 670–72 variables, 382 Bourne shell, 229–31 tcsh, 902–04 Korn shell, 485–87 Korn shell, 470 print function: steps for successful, 641–44, 925–26, TC shell, 837 awk, 96–98 999–1002 Pathname modifiers, tcsh, 916–17 escape sequences, 97–98 TC shell, 921–28 Patterns, awk, 106–07 privileged option, set command, 438 pcat command, 972 Privileged scripts, Korn shell, 582 R p command, sed, 71–72 Processes, 7–11 rand function, awk, 185 PDP-10 computer, 829 creating, 8–11 Ramey, Chet, 599 periodic alias, tcsh, 875 defined, 7 Random number generator, awk, 185–86 Permission modes, 13–14 exec system call, 9 rand function, 185 Permissions, testing scripts for, 756 exit system call, 9–11 srand function, 185–86 pg command, 972 fork system call, 8 RANDOM variable, Korn shell, 471 PID, 7, 628 system call, 9 Range operator, awk, 138 Pipes, 19–21 Process identification number. See PID. Range patterns, awk, 129 awk, 149–51, 162–63 .profile file, 216–17, 434, 435–36, 439, 602, r command: closing, 150–51, 163 608, 610 and Korn shell, 446–47 Bash shell, 704–05, 786 Program control statements, awk, 170 sed, 78 Bourne shell, 250–51 Prompts: rcp, 973–74 C shell, 356–65 Bash shell, 615–21, 773–75 read command: grep with, 54 Bourne shell, 217–18 Bash shell, 726–29 Korn shell, 497–98 C shell, 336–37 Bourne shell, 255–57 TC shell, 890–99 customizing, 616–17, 838–40 Korn shell, 504–08 Pipe system call, 19 Korn shell, 439–40 file descriptors, 506–07 Plus sign, awk, 109 TC shell, 831, 838–42 format, 504 popd command: PS1 variable, 230, 470, 615 options, 505 bash, 647–49 PS2 variable, 230, 439, 470, 615, 617–18 reading through files, 507–08 and directory stack, 647–49, 871–73 PS3 variable, 470, 773–75 reader command, tcsh, 890 tcsh, 871–73 PS4 variable, 470 Readline library: –p option, bash, 611 command, 973 purpose of, 610 Positional parameters: p-type completion, tcsh, 866 read-only command, bash, 691 and argv, 394–95 pushd command: Read-only variables, 906 Bash shell, 678–80 bash, 647–49 Records, awk, 102–03 purpose of, 678 and directory stack, 647–49, 871–73 $0 variable, 102–03 set command, 735–39 tcsh, 871–73 NR variable, 103 Bourne shell, 259–64 command, 973 record separator, 102 set command, 260–62 PWD variable, 230, 470 Recursive functions, 789 C shell, 394–95 Redirection, 16–18 Korn shell, 482–84, 513–16 Q awk, 146–49 set command, 514–16 q command, sed, 82 getline function, 147–49 POSIX awk, 93 :q modifier, 382–84, 926–27 input redirection, 147–49 postamble characters, bash, 653 QNX, 829 output redirection, 146–47 Post-increment operator, awk, 143 Question mark (?): Bash shell, 697–703, 784–86 Pound sign (#), in script comments, 721 awk, 109 Bourne shell, 245–50 PPID variable, Korn shell, 470 Bash shell, 651–52 exec command and, 247–50 pr, 972–73 Bourne shell, 223 operators, 245 preamble characters, bash, 653 C shell, 351, 352–53 C shell, 356–65 precomd alias, tcsh, 875 Korn shell, 457, 460–61 appending output to an existing file, Pre-increment operator, awk, 143 metacharacter, 650, 651–52, 884, 886 360 Primary prompt: prompt, 838 here document, 358–60 Bash shell, 615–16 variable, 748 noclobber variable, 363–65 Bourne shell, 217 Quoting: redirecting input, 357–58 C shell, 336 Bash shell, 681–686 redirecting output, 360 Korn shell, 439 backslash, 681, 683–84 redirecting output and error, 361–62 printenv command, tcsh, 909 double quotes, 681, 685–86 redirection metacharacters, 357 index.fm Page 1013 Thursday, September 12, 2002 12:26 PM

Index 1013

Redirection, C shell (cont.): Korn shell, 439–40 comments, 253 separating output and errors, 362–63 Security, Korn shell, 582 executable statements and Bourne Korn shell, 493–96 sed, 1, 31, 38, 65–92, 976 shell constructs, 254 and the child shell, 495–96 addressing, 66 first line, 253 and exec command, 495 appending (a command), 79–80 making the script executable, 254 TC shell, 890–99 comma, 76–77 scripting session, 254–55 Regular expression metacharacters, 31–42 commands, 66–68 C shell, 385–87 asterisk, 35 defined, 65 comments, 385 caret, 33 deleting (d command), 72–73 example scripting session, 386–87 caret inside square brackets, 37 error messages, 68–70 first line, 385 combining, 37–42 examples, 70–87 making the script executable, dash, 36 holding buffer, 83 385–86 dollar sign, 34 holding and exchanging (h and x debugging, 802–04 dot, 34 commands), 87 exiting from, 403 egrep, 58–59 holding and getting (h and g commands), file testing, 756–58 grep, 46 83–86 Korn shell, 501–04 sed, 69–70 how it works, 65–66 comments, 501 square brackets, 35–36 inserting (i command), 80 executable statements and Korn shell Regular expressions, 29–42 multiple edits (e command), 77–78 constructs, 501 awk, 108–10 next (n command), 81 first line, 501 definition of, 29–31 options, 68 making a script executable, 502 example of, 29–31 –n option, 71 naming and storing scripts, 501–02 metacharacters, 31–42 printing (p command), 71–72 scripting session, 503–04 rehash command: quit (q command), 82 using a script as an argument to ksh, C shell, 335 range of selected lines, 76–77 503 TC shell, 837–38 reading from files (r command), 78 TC shell, initialization files, 831–36 Relational operators, awk, 125–26, 132–34 regular expression metacharacters, SHELL variable, 5, 229, 230, 663 repeat command, 416–17 69–70 Korn shell, 471 REPLY variable: sed script, 87–91 Shell wildcards. See Wildcards. Bash shell, 726, 773 defined, 87–88 shift command: Korn shell, 471 examples, 88–90 Bash shell, 778–80 Restricted Korn shells, 582 review of, 90–91 Bourne shell, 289–91 return command, bash, 788, 790 substitution flags, 67 Korn shell, 545–46 RLENGTH variable, awk, 144 substitution (s command), 73–76 and loops, 417 rlogin command, 974 transform (y command), 81–82 TC shell, 912–13 command, 974 writing to files (w command), 79 shopt command, bash: command, 974 select command, 541–45, 773–77 contrasted with set command, 613 –r option, jobs command, 630 Semicolon (;): and globbing, 656 rsh command, 975 Bash shell, 626, 646 options, 613–15, 817–18 RSTART variable, awk, 144 Bourne shell, 223 Signals, 22 RS variable, awk, 144 C shell, 351 defined, 308, 797 ruptime command, 975 Korn shell, 457 ignoring, 798 rwho command, 975 and quotes, 240 numbers associated with standard, 798 set command: resetting, 800 S Bash shell, 610–13 trapping, 797–802 savehist variable, tcsh, 846, 848 and debugging, 802 Single quotes: sched command, tcsh, 882–83 options, 610–13, 709–11, 814–16 Bash shell, 684–85 s command, sed, 73–76 and positional parameters, 735–39 Bourne shell, 241–42 script command, 975–76 Bourne shell, 322–23 C shell, 379–80 Script files, 1 C shell, 367–68 Korn shell, 486 Scripting, awk, 122 Korn shell, 437–38, 556 size command, 976 Scripts, 4 and positional parameters, 514–16 command, 976–77 executing commands from, 22–27 –o options, 437–38 Solaris, 829 samples of: TC shell, 906–07 –s option, jobs command, 630 Bourne shell, 25–26 setenv command, tcsh, 909 command, 977–78 C shell, 23–25 setgid program, 12 Source code, tcsh, 829 Korn shell, 26–27 setuid program, 12 source command: Search path: setuid scripts, C shell, 422 Bash shell, 789, 793–96 Bourne shell, 218–19 Shell options command. See shopt command. Bourne shell, 621 C shell, 335 Shell prompts, C shell, 336–37 C shell, 336 Korn shell, 440–41 Shells: TC shell, 838 TC shell, 837–38 history of, 3–4 Space/tab, and quotes, 240 Search path variable, 4 responsibilities of, 4–5 Special variables: Secondary prompt: uses of, 4 Bourne shell, 240 Bash shell, 617–18 Shell scripts, 1, 4 C shell, 373–75 Bourne shell, 217–18 Bash shell, 723–25 pathname variable modifiers, 374–75 C shell, 336–37 Bourne shell, 253–55 spell command, 978 index.fm Page 1014 Thursday, September 12, 2002 12:26 PM

1014 Index

Spelling correction: switch command, 409–11 tcsh. See TC shell. emacs editor, 874 Switches, tcsh command line, 947–48 .tcshrc file, 831, 832, 834 tcsh, 838, 874–75 switch statements, nesting, 411–12 command, 981 and vi editor, 874 sync command, 979 telnet command, 981 split command, 978 System calls, 7 TENEX, 829 split function, awk, 175–76, 183 system function, awk, 150–51 test command, 981 sprintf function, 96, 183–84 System startup, and login shell, 5–6 Bash shell, 740–45 Square brackets ([ ]), 36 Bourne shell, 265–66 Bash shell, 652–53 T contrasted with let command, 740 C shell, 351, 353–54 tabs command, 979 C shell, 396, 406–08 egrep, 59 command, 979–80 Korn shell, 518–21 and filename substitution, 225–26 command, 980 new, 519–21 Korn shell, 461–62 tar command, 980 old, 518–19 and quotes, 240 TC shell (tcsh), 829–951 and null values, 750–51 sed, 69 arrays, 910–14 operators, 744 TC shell, 884, 886–87 binding keys, 858–62 purpose of, 740 srand function, awk, 185–86 built-in commands, 928–48 testing exit status with, 740–45 Stack, directory: case modifiers, 917–18 Testing exit status: and bash, 647–49 command line, 842–78 Bash shell, 740–42 manipulating, 647–49, 871–73 conditional executing, 844–45 Bourne shell, 264–65 and tcsh, 871–73 exit status, 842 C shell, 337–38, 402–03 variables, 872 grouping, 843–44 Korn shell, 516–18 Startup: running in the background, 845 Tilde (~): Bash shell, 600–02, 812 shortcuts, 846–78 awk, 110 Bourne shell, 213–14 aliases, 875–78 for bash filename expansion, 655–56 C shell, 331–32 completions, 862–71 time command, 981 Korn shell, 433–34 and directory stack, 871–75 Korn shell, 500 TC shell, 830–31 editors, 855–62 timex command, 981–82 Status variable, 403–04, 842 history list/file, 846–55 TMOUT variable, Korn shell, 471, 500–01 stderr, 5, 16, 332, 356, 434, 493, 697, 830, switches, 947–48 Tokens, 3, 5 894 command substitution, 918–21 TOP-10s, 829 stdin, 5, 16, 332, 356, 434, 493, 697, 830 completion mechanism, 862–71 –t option, set command, 323 stdout, 5, 16, 332, 356, 434, 493, 697, 830, contrasted with other shells, 989–98 command, 982 894–97 derivation of name, 829 command, 982 Storing scripts, and C shell, 423 error handling, 894–96 trackall option, set command, 438 Streams, 493 filename substitution, 885–89 Tracked aliases, and Korn shell, 455 Streamlined editor. See sed. history of, 829 trap command, 437 String functions, awk, 180–84, 202–06 initialization files, 832–36 Bash shell, 797–802 gsub function, 180–81 input, 891–93 Bourne shell, 308–14 index function, 181 job control, 878–83 Korn shell, 563–69 length function, 181 lab exercises, 948–51 command, 983 match function, 182–83 metacharacters, 884–89 true command, 983 split function, 183 operators, redirection, 890 tsort command, 984 sprintf function, 183–84 options: tty command, 984 sub function, 180–81 bindkey command, 855, 858–62 typeset command: substr function, 182 echo command, 900–02 Bash shell, 659 Strings, using as array subscripts, 173–74 output, 893–99 Korn shell, 481–82, 561–63 strings command, 978–79 pathname modifiers, 916–17 stty command, 979 pipes, 890–99 U sub function, awk, 180–81 prompts, 831, 838–42 command, 12, 984 Subscripts for associative arrays, 171–77 quoting, 921–28 unalias command: SUBSEP variable, awk, 144, 176 redirection, 890–99 bash, 647 Subshells, 11 search path, 837–38 tcsh, 877 Substitution: source code, 829 command, 984–85 command: spelling correction, 838, 874–75 uncompress command, 957, 985 bash, 686–89 starting, 830–31 command, 985 tcsh, 918–21 tutorial, 829 units command, 985–86 filename: variables, 899–910, 914–18 UNIX shells, 1–28 bash, 650–58 built-in, 940–48 and command execution, 6 tcsh, 885–89 environment, 837, 899, 907–10 definition of, 1 Substitution characters, history command, local, 899, 905–07 environment/inheritance, 11–22 638 pathname, 916–17 chmod, 13–14 substr function, awk, 182 printing values of, 900–05 chown, 13 Subtraction. See Arithmetic. quoting, 926–28 file creation mask, 12 su command, 979 read-only, 906 ownership, 12 sum command, 979 special, 914–18 function of, 1 Suspend key sequence, tcsh, 880 versions, 829–30 history of, 3–4 index.fm Page 1015 Thursday, September 12, 2002 12:26 PM

Index 1015

UNIX shells (cont.): special, 678–81 W login shell, and system startup, 5–6 Bourne shell, 227–39 wait system call, 9 major shells, 2 environment variables, 229–31 command, 987 and processes, 7–11 local variables, 227–29 w command, sed, 79 creating, 8–11 C shell, 365–73 what command, 987 defined, 7 arrays, 370–73 whereis command, 987 exec system call, 9 built-in local variables, 368 which command, 987 exit system call, 9–11 curly braces, 366 fork system call, 8 while command: environment variables, 368–70 Bash shell, 768–71 wait system call, 9 local variables, 366–67 responsibilities of, 4–5 Bourne shell, 284–87 set command, 367–68 C shell, 415–16 scripts, 1–4 shift command, 371–72 Korn shell, 537–40 Bourne shell script, 25–26 special variables, 373–75 while loop, awk, 168 comparison of, 23 global, 663, 899, 907 command, 20, 987 C shell script, 23–25 Korn shell, 465–85 defined, 22–23 Wildcards: environment variables, 468–71 executing commands from, 22–27 Bash shell, 649–50, 656–57 escape sequences, 475–76 Korn shell script, 26–27 Bourne shell, 223 listing set variables, 471–73 and signals, 22 Korn shell, 459–65 local variables, 465–67 uses of, 4 TC shell, 884 positional parameters, 482–84 UNIX toolbox, 29–42 Windows NT, 829 regular expressions, 29–37 printing the values of variables, 474–75 Wordlists, and tcsh command substitution, definition, 29–31 919–21 typeset command, 481–82 example, 29–31 Word types, tcsh completion, 868–69 metacharacters, 31–37 unsetting variables, 473 variable expansion substrings, Working directory, 15 UNIX utilities, 599 command, 987 unpack command, 986 479–80 unset command, bash, 669, 691, 696 variable expressions and modifiers, until command: 476–79 X Bash shell, 771–73 positional parameters, 237–38 command, 988 Bourne shell, 287–89 read-only, 906 :x modifier, 384, 926, 928 Korn shell, 540–41 special variables, 239 –x option: –u option, set command, 323 TC shell, 899–910 bash, 802 User-defined variables, awk, 142–45 directory stack, 872 csh command, 391–94, 400–01 User identification (UID), 12 environment varibles, 837, 907–10 set command, 323 USER variable, 5 local variables, 905–07 xtrace option, set command, 438 uucp command, 986 using as array indexes, 171–72 uuencode command, 986 variable expansion modifiers, 234–37 Y verbose option, 438, 802 y command, sed, 81–82 V –version option, bash, 600 vi command, 31 Variable expansion of substrings, bash, Z 676–78 Bash shell, 641, 642–43 Variable modifiers, bash, 672 commands, 642–43, 856 zcat command, 988 Var iables: Korn shell, 448–49 zcat compress command, 957–58 awk, 141–46 and spelling correction, 874 numeric constants, 141–42 TC shell, 855–56 string constrants, 141–42 vi option, set command, 438 user-defined variables, 142–45 VISUAL variable, Korn shell, 471 Bash shell, 659–716 –v option: environment variables, 602, 663–68 csh command, 391–94 local variables, 660–62 set command, 323, 802