From ed4a7f6e368b9ddad0e78a49398575140c7189c6 Mon Sep 17 00:00:00 2001 From: gferg <> Date: Mon, 15 Oct 2001 14:28:18 +0000 Subject: [PATCH] added --- LDP/guide/docbook/abs-guide/Change.log | 1558 ++++++++++++++++++ LDP/guide/docbook/abs-guide/assert.sh | 43 + LDP/guide/docbook/abs-guide/bashandperl.sh | 18 + LDP/guide/docbook/abs-guide/idelete.sh | 40 + LDP/guide/docbook/abs-guide/int-or-string.sh | 28 + LDP/guide/docbook/abs-guide/m4.sh | 14 + LDP/guide/docbook/abs-guide/match-string.sh | 37 + LDP/guide/docbook/abs-guide/ramdisk.sh | 51 + LDP/guide/docbook/abs-guide/recurse.sh | 24 + LDP/guide/docbook/abs-guide/redir4a.sh | 27 + LDP/guide/docbook/abs-guide/symlinks2.sh | 22 + 11 files changed, 1862 insertions(+) create mode 100644 LDP/guide/docbook/abs-guide/Change.log create mode 100644 LDP/guide/docbook/abs-guide/assert.sh create mode 100644 LDP/guide/docbook/abs-guide/bashandperl.sh create mode 100644 LDP/guide/docbook/abs-guide/idelete.sh create mode 100644 LDP/guide/docbook/abs-guide/int-or-string.sh create mode 100644 LDP/guide/docbook/abs-guide/m4.sh create mode 100644 LDP/guide/docbook/abs-guide/match-string.sh create mode 100644 LDP/guide/docbook/abs-guide/ramdisk.sh create mode 100644 LDP/guide/docbook/abs-guide/recurse.sh create mode 100644 LDP/guide/docbook/abs-guide/redir4a.sh create mode 100644 LDP/guide/docbook/abs-guide/symlinks2.sh diff --git a/LDP/guide/docbook/abs-guide/Change.log b/LDP/guide/docbook/abs-guide/Change.log new file mode 100644 index 00000000..9c542d80 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/Change.log @@ -0,0 +1,1558 @@ +RELEASE HISTORY +------- ------- +Change log + +Version 1.0 (stable!), released 10/14/01 + +1) Quoted "$LOGFILE" in in-line example in "Scripting With Style" subsection + of "Miscellany" chapter. + +2) Added missing "/" in first footnote in Chapter 2 (thanks, Stepan Kasal). + +3) Additional comments for "primes.sh" contrib script. + Fixup in "ex72.sh" contrib script. + +4) In "Job Control Commands" section of "Internal Commands and Builtins" chapter: + Additional comment for footnote to "enable -f". + Additional material on "wait" (preventing script hang after background + command). + +5) Added "Oddities" section to "Miscellany" chapter. + o Script calling itself recursively, with illustrative example + ("recurse.sh"). + o Moved "Shell Wrappers" section from "Starting Off With a Sha-Bang" + chapter to "Miscellany" chapter. + +6) In "Local Variables and Recursion" section of "Functions" chapter, defined + "recursion" in more detail. + +7) Modified in-line example in "Special Variable Types" section of + "Introduction to Variables and Parameters". Thanks, John Villalovos for + bringing a side effect of parameter substitution to my attention. + +8) In "System and Administrative Commands" chapter: + Added "setserial". + Added "MAKEDEV". + Added "mkbootdisk". + Added "tcpdump". + Added "strip". + Added "chkconfig". + Added "hdparm". + Added "badblocks". + Added "lsdev". + More info on "uname". + Added "top" to "Job Control" subsection. + Moved "mknod" to "Filesystem" subsection. + Moved "ps" and "pstree" from "Internal and Builtin" job control + commands to this chapter. + +9) In "Arrays" chapter, added "unset" for removing array elements or an + entire array. + +10) Added "Exercises" appendix. + +11) In "Special Characters" chapter: + Added "EOF" as attribute of "Ctl-D" control character. + Added "(( ))". + Added "?". + Added ";;". + Added field separator usage for ":". + Added info on pipes. + +12) In "System Commands" chapter, changed "cron" to more technically correct + "crond". + +13) In "Globbing" section of "Regular Expressions" chapter, added examples of + "echo" doing filename expansion. + +14) In "Test Constructs" section of "Tests" chapter: + Enhanced "arith-tests.sh" example. + Added "(( "$a" < "$b" ))" and "(( "$a" > "$b" ))" constructs. + Added "(( "$a" <= "$b" ))" and "(( "$a" >= "$b" ))" constructs. + Added "Testing Your Knowledge of Tests" section. + Added some material to "ex10.sh" example. + +15) In "Complex Commands" section of "External Commands" chapter: + Added material to "ex45.sh" example. + Fixed error in description of "expr index $string" + Rewrote part of "expr" discussion. + Added "idelete.sh" example at "find" listing. + +16) Added testing for condition with "assert" function in "Debugging" chapter. + Illustrative example, "assert.sh". + +17) Added prepending a line to an existing file to "Assorted Tips" section of + "Miscellany" chapter. + +18) Added "Bash Variables Are Untyped" section to "Variables" chapter. + Example "int-or-string.sh". + Slight modification of "ex9.sh" example. + Added special case of signal variables to "naked" variables. + +19) Moved "$?" and "$$" for "Positional Parameters" subsection of "Variables + Revisited" chapter to newly created "Other Special Parameter" listing, + along with "$-", "$!", and "$_". + + +20) In "Variables Revisited" chapter: + Added "Manipulating Strings" section. + Swatted a couple of bugs in the first couple of drafts of this section. + Added "$GLOBIGNORE" and "$LC_CTYPE". + Added "$BASH_VERSINFO[n]". + Added "$PIPESTATUS". + More info at non-builtin Bash variables. + +21) In "Arrays" chapter, added "${array:position}" construct in-line example. + +22) In "Time / Date" section of "External Commands" chapter: + Rewrote and corrected part of "at" entry. + Added "zdump". + +23) In "Text Processing Commands" section of "External Commands" chapter: + Added example for "cut", per idea of Oleg Philon. + Added yet another usage example for "wc". + Added "recode". + Added "zdiff" at "diff" entry. + Added "zcmp" at "cmp" entry. + Slightly revised "sort" entry. + Revisions on "grep" entry. + Added notation about "agrep". + +24) In "/dev and /proc" chapter: + Reorganization into two separate sections. + Oleg Philon suggested a simplification for the "connect-stat.sh" example. + +25) In "Miscellaneous Commands" section of "External Commands: + Added "banner". + Added "m4", with "m4.sh" illustrative example. + Added "make". + Added "hexdump". + +26) In "File and Archiving Commands" section of "External Commands: + More info on "file" entry. + Added "znew" note at "compress / uncompress" entry. + Added "zip / unzip". + Added "vdir". + Added "shred". + +27) In "Math Commands" section of "External Commands" + Corrected "EBCDCIC" to "EBCDIC". Very embarrassing. + +28) In "Regular Expression" chapter: + Added "()" and "|" to extended REs. + +29) In "Communications Commands" section of "External Commands" chapter: + Added "cu". + +30) In "Of Zeros and Nulls" chapter, added "ramdisk.sh" example. + +31) In "Appendix B", fixed error stating that "Both sed and awk use the -e + option..." Only sed does (whoops!). Thanks to Peter S Tillier for + pointing this out. + +32) Clarification of version 2 of Bash in "Bash, Version 2" and + "Gotchas" chapters. + +33) Slight change to "symlinks.sh" example script, as suggested by + Dominik 'Aeneas' Schnitzer. + +34) Added note to "numbers.sh" example, at the suggestion of Chiron. + +35) Folded "Credits" chapter into "Endnotes" chapter, as a section. It's more + logical that way. + +36) Added "Preliminary Exercises" section to Chapter 2. + +37) Added setting a variable to the contents of a file to "Command + Substitution" chapter. + +38) In Bibliography, added Rosenblatt listing. + +39) In "Command Substitution" chapter, back quotes (`...`) erroneous shown as + single quotes ('...'). Fixed. Thanks, David Lawyer. + +40) Fixed ambiguity in conditional test in "rpm-check.sh" example, in "Special + Characters" chapter. Also fixed "ex9.sh". Again, thank you, David Lawyer. + +41) Fixed "for loop" references (links led to wrong places). + +42) In "Testing and Branching" subsection of "Loops and Branches" chapter, + added "match-string.sh" example. + +43) In "Loops and Branches" chapter, + added example of "for" loop with stdout redirected to a file. + +44) In "Redirected Code Blocks" section" of "I/O Redirection" chapter, added + "redir4a.sh" example, showing redirection of both "stdin" and "stdout" of + loop. + +45) In "Shell Wrapper" section of "Starting Off With a Sha-Bang" chapter, + added "bashandperl.sh" example. + +46) Revised the introduction to the book. + +47) Last minute cleanups of various example scripts. + +48) New .bashrc from Emmanuel Rouat. + + + + + + +Version 0.5, released 09/03/01 + +1) Changed the name of this file from "NEWS" to Change.log" + +2) Reorganized subsections of the huge "Tutorial" chapter into separate + chapters. This is much more logical. + +3) Divided main section of the book into four parts. + First paragraph of chapter 1 moved to Part 1 introduction. + +4) Fixups on id tags for various subsections (Jade does not like "anchors" + nested in within certain tags). + +5) In "Tools Used" section, fixed typo in "OpenJade" URL. + +6) Changed chapter heading from "End Notes" to more grammatically correct + "Endnotes". + +7) In "Regular Expressions" chapter: + Fixed typo ("or" -> "of"). + Added subsection for POSIX character classes. + +8) Enhancements to "ex73.sh" example. + +9) In "File and Archiving Commands" section of "External Commands" chapter: + Added "de-rpm.sh" example of using "cpio". + Added "ar". + Reorganized into subsections. + +10) Added dedication. + +11) Corrected comment in "weirdvars.sh" example. Thanks, Prahad V. + +12) Cleanups on "ex2.sh", "ex39.sh", "ex41.sh", and "logevents.sh" examples. + +13) In "I/O Redirection" chapter, added cross references to "de-rpm.sh" and + "fifo.sh" examples. + +14) In "System and Administrative Commands" chapter + Added "strace". + Added "hostid". + Added "nm". + Added "vmstat". + Added "fdformat". + Added "erase.sh" example at "stty". + More info on lock files. + Reorganization of entries into logical sections. + +15) Moved "Parameter Substitution" section from "Introduction to Variables and + Parameters" chapter to "Variables Revisited". This is a fairly advanced + topic. + +16) Moved "Variable Assignment" and "Special Variable Types" information from + "Variables Revisited" chapter to "Introduction to Variables and + Parameters". These are introductory topics. + +17) In "Miscellaneous Commands" section of "External Commands" chapter: + Added "blot-out.sh" example for "dd". + Added footnote explaining "EBCDIC" at "dd" + Added "run-parts". + +18) Changed to in various places, since the + Docbook stylesheet does strange things with the former. + +19) In "Tests" chapter: + Fixup in footnote in "File Test Operators" subsection. + Added note that "&&", "||", "<", and ">" work within "[[ ]]" construct. + Rewrote "<" and ">" entries in "Comparison Operations" section. + +20) In "Internal Commands" chapter: + Added "-r" option to "read". + Added "-f" option to "enable". + Extended "ex47.sh" example at "printf" with "sprintf" simulation. + Added more info to "cd" ("-P" option and "cd -"). + Added "fg" and "bg" (how did I manage to leave these out before?). + Added "logout". + Added optional argument that "wait" may take. + Added "autoload". + Added table of "Job Identifiers". + Reorganized chapter into subsections. + +21) In "Text Processing" section of "External Commands" chapter: + Added "crypto-quote.sh" example for "tr". + Added another usage example for "wc". + Added "tsort". + Added "iconv". + Added "lex" and "yacc". + +22) More info added in "Aliases" chapter. + +23) In "Parameter Substitution" section of "Variables Revisited" chapter: + Added usage examples on "${param+alt_value}" and "${param:+alt_value}" + Added in-line usage examples for "${var#pattern}" and "${var##pattern}". + Added "${!varprefix@}" matching. + Added "${var/#patt/replacement}" and "${var/%patt/replacement}", + with illustrative example ("var-match.sh"). + +24) Dedicated section to "Globbing". + Added usage examples. + +25) In "Variables Revisited" chapter: + Added usage example of "declare -i" in "Typing Variables" section. + Added material to "am-i-root.sh" example. + Correction: "typeset" and "declare" are builtins, not keywords. + Added "declare" option ("var=$value"). + +26) Added $ LC_COLLATE, $SHLVL, and $FUNCNAME to "Variables Revisited" chapter. + Noted adding "export LC_COLLATE=C" to /etc/profile to restore customary + behavior of bracket set filename globbing. + +27) Made "bubble.sh" more pedantically correct by quoting params within tests. + +28) In "Assorted Tips" section of "Miscellany" chapter: + Added inline example of a definition and function library. + Added special-purpose comment headers. + +29) Added "About the Author" section to "Endnotes" chapter. + +30) In "Operations" section of "Operations and Related Topics" chapter: + Added "**" exponentiation operator. + Added note that Bash integers are of type 32-bit signed long, with + in-line example. + Added comma linking operator. + Fixed and enhanced "&&" and "||" entries. + +31) In "Parameter Substitution" section of "Variables Revisited" chapter, + added "${!varprefix*}" expansion. + +32) In "Communications Commands" section of "External Commands" chapter, + Added "whois". + Added "ping". + Added "finger". + Added "vacation". + Added "ftp". + Added "telnet". + Added "rsh". + Added "rlogin". + Added "ssh". + Added footnote defining "daemon". + Reorganized commands into subsections. + +33) In "Complex Commands" section of "External Commands" chapter, added + usage example of "expr $string :" operations. + +34) Clean up example scripts, and made them more stylistically consistent. + Fixed error in "ex22a.sh". + Fixed error in "arith-tests.sh". + +35) Fixed erroneous reference to "ex74.sh" in "Of Zeros and Nulls" chapter + (should be "ex57.sh"). + +36) Corrections and additions to "DOS Batch Files" appendix, sent in by + Marc-Jano Knopp. + +37) In "Functions" chapter, noted that 256 is the largest positive + integer return value, and added "return-test.sh" illustrative example. + Showed how to "evade" this restriction, with "max2.sh" example. + +38) Branched off "function redirection" into a separate sub-subsection. + +39) Added integer variable test to "Assorted Tests" section of "Miscellany" + chapter. + +40) Added "days-between.sh" example to "Contributed Scripts" appendix. + +41) Added "using same name for a function and a variable" to "Gotchas" + chapter. + +42) In "Special Characters" chapter: + Fixed "pipes" example to reflect GNU syntax of "tr" (thanks, Elias Assman). + Added note to "dot" character that in another context, it can be part of a + Regular Expression. + Added "$", variable substitution. + Added "&", run job in background. + Added "%", modulo and pattern matching operator. + Added "/", filename path separator and division operator. + Added "=", assignment and string test operator. + Added "+", arithmetic addition and Regular Expression operator. + Added "~+", print working directory. + Added "~-", print previous working directory. + Added "control characters". + Reordered listings. + +43) In "Arrays" chapter, added comment to "bubble.sh" example. + +44) Added portability note to "ex51.sh". + +45) Removed redundant and partially incorrect "relational tests" subsection + from "Operators" section of "Operations and Related Topics" chapter. + +46) In "Basic Commands" section of "External Commands" chapter: + More options to "ls". + +47) Added "Portability Issues" section to "Miscellany" chapter. + +48) In "Bibliography": + Updated Rick Hohensee assembler link. + Added Sheer book listing. + +49) Added "Effective Awk Programming", to Bibliography. + + + + + +====================================================================================== + + +Version 0.4, released 07/09/01 + +Comments: Complete revision. The document is now the equivalent of a + 300-page book. + +Changes from version 0.3: + +1) Substituted Emmanuel Rouat's new, improved Linux-specific .bashrc + file for the old one. + +2) +In "External Filters, Programs, and Commands" section: + More info on "sleep". + Added "usleep". + More info on "diff", with note about using it to recursively compare + directories. + Added "diff3". + Added "sdiff". + Added "cmp". + Added example using "cmp", and cross referenced it to "exit status". + Added "hwclock/clock". + Added "locate/slocate". + Added "whatis", with example script. + Added "whereis". + Added "od". + Added "unexpand". + Added "install". + Added "crypt". + Added "write". + Added "compress/uncompress". + Added "gettext". + Added "printenv". + Added "tput". + More info on "fold" (-s option). + More info on "patch". + More info on "join". + More info on "tar". + More info on "tr". + More info on "dd". + More info on "logger". + More options for "cat". + More options for "cp". + Added cautionary note to "tar". + Added --count and --invert-match options to "grep". + Extra options and code snippets for "find". + Using "echo" to feed a command sequence into a pipe and set a variable, + with illustrative code snippets. + Added subsection for "Terminal Control Commands" (tput, clear, reset, + script). + Added subsection for "Math Commands" (factor, bc/dc). + +3) Moved subsection on "Here Documents" to right after "I/O Redirection" (much + more logical). + +4) Added more reasons not to use shell scripts. + +5) Added info about the "widtools" (widget tools) package to "Assorted Tips" + subsection of "Miscellany". + +6) Corrected "Born-Again Shell" to "Bourne-Again Shell" (thanks to Jan + Svenungson for pointing this out). + +7) In "System and Administrative Commands" section: + Added "dumpe2fs". + Added "tune2fs". + Added "fdisk". + Added "mke2fs". + Added "fsck", "e2fsck", and "debugfs". + Added script using "fdisk" and "mke2fs". + Added "df". + Added "du". + Added "mesg". + Added tip. + Added "procinfo". + Added "ac" + Added "last" + Added "tset" + Added "getty" and "agetty". + Added "chown/chgrp". + Added "useradd/userdel". + Added "logrotate". + Added "dump/restore". + Added "stat". + Added "rdist". + Added "losetup". + Added "lastcomm". + Added "mkswap". + Added "swapon/swapoff". + Added "newgrp". + More info on "chroot". + More info on "netstat". + More info on "ifconfig". + More info on "route". + More info and example added on "mount". + Added note to "umount". + Usage example on "lsmod". + Removed inappropriate spacing in "wall" listing and added note. + +8) In "Internal Commands" section: + Added "pstree". + Added "type". + Added "help". + Added footnote on "forking". + More info on "kill". + Added example to "unset". + More options and info added to "read". + +9) Additional clarification of "for" loops. + +10) Added using C-like syntax in a "for" loop to "Loops" section, + with illustrative example. + Did the same with a "while" loop. + Cross-references to examples in "Miscellany / Assorted Tips" section. + +11) Added using command substitution to generate [list] in a "for" loop. + Same for a "case" construct. + Examples added. + +12) In "Variables Revisited" section, added C-type variable manipulation, + using the ((...)) construct [Chet Ramey's Easter Egg, actually borrowed + from ksh93]. + +13) In "Gotchas" section, + Added scripts with DOS-type newlines. + Added script invoked with "/bin/sh" maybe not fully Bash-compatible. + +14) In "Files" section, added ~/.bash_logout. + +15) In "Variables Revisited" section, + Moved note about certain variables not internal to Bash to a more logical location. + Added short note about using /dev/urandom to generate (useless) random numbers. + Added $LINENO to internal variables. + Added illustrative script ("am-i-root.sh") to "UID" discussion. + Fixed "dubugging" typo. + +16) In "Bibliography" section, + Added four sites for example shell scripts. + Added reference to Rick Hohensee's shell-scripted virtual machine + assembler. + +17) Added "mail-format.sh" to "Contributed Scripts" section. + +18) In "Tests" section: + Clearer definition of what "test" actually means. + Add info about "-g", "-u", and "-k" flags. + Clarified examples of "integer tests" (used if [ "$a" XX "$b" ] to illustrate). + +19) Fixed syntax error in "ex45.sh" (embarrassing). + +20) Added piping the output of a "for" loop to a command. + +21) Mention /usr/include/sysexits.h as an attempt at systematizing exit status + numbers. + +22) Added "string.sh", a "Contrib Script" by Noah Friedman. + +23) Alphabetized listing of internal Bash variables in "Variables Revisited" + section. It looks more professional now. + +24) Added subsection on "Nested Loops" to "Loops" section. + Added illustrative example script. + +25) Added subsection on "Nested if/then Condition Tests" to "Tests" section. + +26) In "Here Documents" section, + Added - option. + Added passing parameters to body of here document, with examples. + Added disabling parameter replacement by quoting or escaping. + +27) In "Special Characters" section, + Added info on "-" redirection operator. + Added quotes (""). + Added strong quotes (''). + Added escape (\). + Added backticks (`). + Added using ":" for comment line (not recommended). + Added "*". + Added "$*" and "$@". + Piping the output of command(s) to a script. + More info on "!" operator. + Annotated Alan Cox's one-liner script. + Added "_" (underscore). + +28) Reorganized "Loops" section; created new subsection and reshuffled. + +29) Added instance of "unset" to when a variable appears "naked" (without the + $ prefix). Thanks to Florian Wisser for pointing this out. + +30) Rewrote "Command Substitution" section (formerly named "Backticks"). + Split off "Arithmetic Expansion" as a separate section, and added + material. + +31) Added "bc" and "dc" to "External Filters" section, with elegant + illustrative script by Heiner Steven. + Added more info on "bc", with "monthlypmt.sh" illustrative example. + +32) Added new section on "/dev and /proc". + Added illustrative examples. + +33) Made a number of corrections and clarifications, as pointed out by Heiner + Steven. Thanks! + Some UNIX flavors take a 4-byte magic number... + Too many script headers on one line in "magic number" example listing. + Example "ex2.sh", added comment that "> filename" is equivalent to "cat /dev/null > filename". + Example "ex2.sh", quoted parameter. + Omitting [list] in a "for" loop assumes "$@", rather than "$*". + Clarified that a "flag" acts as a semaphore, rather than as a signal. + Added comment that {code block} does not launch a subshell to + "Special Characters" section. + At his suggestion, added a couple of more examples on "~" in + "Special Characters" section. + Added his "allprofs" script to "Subshells" section (with modifications + by HOWTO author). + Noted that some substitution operators come from ksh93. + Noted that a line of code in a script ending in a pipe character does + not require an escape to continue to the next line. + Code snippet on how to redirect "read" through an entire file, line by + line. + Added note that "declare" is Bash-specific. + Added code snippet explaining use of $IFS with "read" + Added alternate example of redirected "while" loop to "I/O Redirection" + section. + +34) Added comments to "Subshells" section. + +35) In "strip-comments.sh" example script, changed "=" to "-eq" (bugfix). + +36) Changed all instances of "white space" to "whitespace" for consistency + (picky, picky). + +37) Added pitfalls of variables in a subshell with illustrative example to + "Gotchas" section. + +38) Added using Bash-specific functionality in a Bourne shell script on a + generic UNIX machine to "Gotchas" section. + +39) Added another example to "List Constructs" section. + +40) Added using positional paramters > $9, using {bracket} notation (thanks, + Philippe Martin). + +41) Added -N and -t file tests to "Tests" section. + +42) In "Arrays" section: + Added "q-function.sh" (Hofstadter's Q-function) as an illustrative + example. + Added "twodim.sh" simulation of a two-dimensional array. + +43) Added two new entries to "Bibliography" section. + +44) Added more info in "Quoting" section. + +45) Bugfix: removed an extraneous header from "source/dot" command in "Special + Characters" section. + +46) Added a caution about confusing REs with "globbing" to "Regular + Expressions" section. + +47) In "Loops" Section: + Added filename "globbing" in for-loop [list]. + Added "break N", breaking out of multiple loop levels. + Added "continue N", continuing at a higher loop level. + Added footnote to "Loop Control Commands" subsection noting that + "break" and "continue" are shell builtins. + +48) Removed commented-out SGML code for article header. That makes it official + that this document is a book. + +49) Added new appendix on "Converting DOS Batch Files to Shell Scripts". + +50) Added "findstring.sh", illustrative example for generating [list] in a + "for" loop with command substitution and for "strings" command in + "External Filters, Programs, and Commands" section. + +51) More info on "exit status". + +52) Added appendix for "Exit Codes With Special Meanings". + +53) Added "!" to "Special Characters" section. + +54) Added "==" to "Tests" section. + +55) Added a couple of examples and more explanation to "Regular + Expressions" section. + +56) Extra notes on $BASH_VERSION. + +57) In "Functions" section: + Added directing the stdin of a function, with illustrative example. + Added footnote to "return" command, noting that it is a Bash builtin. + +58) Added "[[ ]]" construct to "Tests" section. + +59) In "bubble.sh", fixed spelling of "Zaire" and changed "Kashmir" to "Kenya" + (it was pointed out that Kashmir is not a country). + +60) Added "file-info.sh", illustrative example of a variable containing the + [list] in a "for" loop. + +61) Added a section on "Scripting With Style", stylistic guidelines. + * Script and function headers added. + * Descriptive names for variables added. + +62) Added "copy-cd.sh", a script for copying data CDs, to "Contributed + Scripts" section. + +63) In "Loops" section, separated "Loop Control Commands" ("break" and "continue") + into a separate subsection. + +64) Added note to "Tests" section that after "if", "test" or test brackets not + strictly necessary. Similarly, test brackets do not necessarily require an + "if" when used with "list constructions". + +65) Once more, checked all the examples for stylistic correctness. + +66) In "Variables Revisited" section: + Added "random-test.sh", testing the randomness of RANDOM. + Added "seeding-random.sh", reseeding the RANDOM generator. + +67) Reshuffled some commands into different subsections in "External + Filters, Programs, and Commands" section. + +68) Added "isalpha.sh" example to "case" constructs in "Loops" section. + +69) Added inline example in "Regular Expressions" section. + +70) Moved "ex50.sh" from "pr" to "fmt" in "External Filters, Programs, and + Commands" section. + +71) Added "du.sh" example to "tr" in "External Filters, Programs, and + Commands" section. + +72) Clarification on ${var#pattern}, ${var%pattern} variable substitution + in "Variables" section, and added "patt-matching.sh" example to + illustrate. + +73) Clarifications on "ex14.sh" example. + +74) In "Internal Commands and Builtins", fixed explanation on + "getopts" and associated "ex33.sh" to make usage consistent with + accepted usage. (Thanks, Ueli Strasser) + +75) Fixed typos: + ("suppress" --> "suppresses") in "Here Documents section. + ("inderect" --> "indirect") in "Variables Revisited" section. + "Option" left out in "type" discussion. + +76) More on "%" (modulo) operator in "Operations" section. + +77) Added "> &FD" and "n<>filename" to "I/O Redirection" section. + +78) Fixed bug in "ex2.sh" example (removed "or-list"), + and added cautionary not on "or lists". + +79) More explanation on meaning of "keyword". + Noted that "!" is a keyword. + +80) Moved "printf" and "eval" from "External Commands" to "Internal + Commands" section. + +81) Fixed up some cross-reference links. + +82) In "Sha-bang" section: + Added footnote with self-deleting script example. + Added footnote about invoking script with "sh scriptname" turning off + Added footnote about invoking a script with "./scriptname". + Bash-specific extensions. + Minor cleanups. + +83) Cleaned up "filename" referenced. + Made references to "stdin" and "stdout" consistent (). + +84) Added footnote about "dotfiles". + +85) Noted that "logname" is not exact equivalent to "whoami", with example. + Correction: "trap 2" changes to "trap '' 2" in "Debugging" section. + Thank you, Nick Drage. + +86) Fixed typos pointed out by Hyun Jin Chan. + Typo in "ex13.sh". + Typo in "ex41.sh". + In "Here Documents" section, changed + "feeding input into non-interactive programs" to + "feeding input into interactive programs". + +87) Added footnote about "magic numbers" used in the context hard-wired + constants in "Scripting With Style" section. + +88) Added "End Notes" chapter, which includes "Author's Note" and "Tool Used + to Produce This Book". + +89) Added footnote about shell script naming conventions to "Why Shell + Programming?" section. + +90) Changed all tags to the more appropriate . + +91) Added info about Korean translation of the document to "Copyright" + section. + +92) Added "${#variable}" construct to "Parameter Substitution" subsection in + "Introduction to Variables and Parameters" section, mentioning exceptional + cases of "${#*}" and"${#@}". + +93) Reorganized "I/O Redirection" section (subdivided into subsections). + +94) Reorganized "Functions" section (subdivided into subsections). + +95) Added example snippets to "Process Substitution" section. + +96) Added Nick Drage's comments to "online.sh" in "Debugging" section. + +97) Tidied up "Operations and Related Topics" section. + +98) Fixed typos in "ex79.sh" ("suite" -> "suit"). + +99) Fixed other minor typos in the document. + +100) Stephane Chazelas sent in long lists of corrections and suggestions. + Bug fixes, improvements, and comments on "ex2.sh" example. + Bug fixes and improvements to "ex3.sh" example. + Improvement on "ex4.sh", "ex5.sh", and "ex14.sh" examples. + Suggestion for "col-totaler.sh" example. + Code snippet on use of "case" for parsing command-line args. + In "brace expansion" discussion, pointed out that spaces permitted when + quoted or escaped. + Improved "ex8.sh" to read more than one line (more useful as an + example). + Resolve ambiguity about "-", which is not a Bash operator. + Suggested workarounds for filenames starting with "-" used with "-" + redirection operator. + Added safer alternatives to "ex58.sh". + In "Why Shell Programming?" section, modified footnote to state that + user-written scripts with ".sh" extension should be Bourne shell + compliant. + In "Command Substitution" section: + Added notes. + Added explanation in code snippet on command output. + Note that newline deletion may result from word splitting. + Added example snippets of trailing newline deletion. + In "Special Characters" section: + Fixed typo at beginning of "#" (comment) listing. + Added note about "#" not denoting a comment in certain constructs. + "${parameter?err_msg}, ${parameter:?err_msg}" + Added note that non-interactive script exits with code 127. + Added note about escaping "#" in echo statements. + Added caution about variable value starting with "-n". + More on "~" expansion. + Changed "noclobber" environmental variable (obsolete) to option. + Added "array initialization" to "()" listing. + Added notes to "brace expansion". + Added notes and made corrections to "ex6.sh" example. + Added note and example demonstrating that a code block in braces + may run as a subshell. + Clarification on "pipes". + Note on Alan Cox's directory copy method. + Noted that ":" is a shell builtin. + Noted that ": >>" applies only to regular files. + Fixed error about "code block" { ... }. + Added note about variables defined within (...) not being visible to + rest of script. + Fixed error on "{}\" construct, and added note. + Change to "uppercase.sh" in-line example. + Added "{#array}" as string length of first element of array. + Added cautionary note about reserved exit status codes to "Exit Status" section. + In "Variables" section: + Added comments and clarifications to "ex7.sh". + Added comments and clarifications to "ex9.sh". + Added info per his comments on the $'...' string expansion construct. + In "Quoting" section: + Added more examples of escaping a newline in variable assignment. + Clarified and corrected info about quoting variables "echoed", with + Added illustrative examples. + Replaced flawed example snippet ("bash$ echo [Ff]irst") + Fixed bug, changed ' to ` in referencing within double quotes. + Clarified and corrected "toggling on" special meanings of characters + by escaping. + In "Tests" section: + Added detailed explanation about "if/then" construct, "[", and "test". + Added clarification about "[", "[[" , and "test". + Added arithmetic tests using "(( ))". + Added notes to "ex10.sh" example. + Clarification on "ex12.sh", and moved it to "External Filters..." section. + Pointed out that one should always quote a string being tested. + Clarified what happens when erroneously putting a space in an + assignment statement. + Added example on using arithmetic operations (arithops.sh). + Clarification and corrections on "-t" test option. + Clarification on "-r" test option. + Clarification on "-w" test option. + Clarification on "-g" test option. + Clarification on "-u" test option. + Clarification on "-k" test option. + Clarification on "-n" test option. + Clarification on "str-test.sh" example. + Clarification and example on "==". + Clarification on pattern matching with "!=". + Clarification on "&&" and "||" comparison operators. + Fixup on "arith-tests.sh" example. + Clarification and corrections on "ex14.sh" example. + In "Operations" section: + Fixed "=" in-line example. + Fixed "+=" and "*=" example snippets. + Fixed typo: 'if "Xstring1" = "Xstring2" ] is safer,'. + Retitled subsections to avoid reader confusion. + Added example snippet on using "&&" and "||" in an arithmetic + context. + Added note to "arith-ops.sh". + Added note to "and-or.sh". + Fixed typo (lost space) in in-line "&&" example. + Clarified "numbers.sh" example. + Clarification on "&&" and "||". + In "Variables Revisited" section: + More clarifications and example snippets + "ifs.sh" example for "$IFS". + Clarified use of "$PATH" variable. + Cleared up confusion on "$PPID". + Cleared up confusion on "$@". + Added "incompat.sh" and "ifs-empty.sh" examples on inconsistent + "$*" and "$@" behavior. + Plugged a possible hole in "wipedir.sh" example script and added + comments. + Added "timeout.sh", another example of timed input. + Explanation (footnote) on environmental variables. + Explanation (footnote) on parameter $0. + Corrected "declare -f" listing. + Clarification on "ind-ref.sh" example. + Clarification on $SHELL variable. + Clarification on $HOSTNAME variable. + Added "col-totaler2.sh" as an example of indirect references. + Fixed typo "that that". + Fixup on "ex17.sh". + Fixup on "ex20.sh". + Added comment to "ex21.sh". + In "Loops" section: + Fixed error: semicolon *after* [list]. + Additional clarification in "ex22a.sh" example. + Quoted arguments in [list] in for-loop illustration. + Removed reference to REs in filename globbing. + Fixup and note added to "list-glob.sh" example. + Added note to "bin-grep.sh" example. + Added note to "ex24.sh" example. + Correction on "ex26a.sh" example. + In "case" constructs: + Noted that variable quoting not mandatory. + Corrected and clarified comment in command line parameter testing. + Changed "regular expression" filtering to "globbing" filtering. + Improved "isalpha.sh" example. + In footnote, cleared up some confusion about builtins. + Moved 'basename', 'dirname', and 'factor' from "Internal Commands" + to "External Filters, Programs, and Commands" section. + Minor clarification on "read-redir.sh" example. + Alternatives added to "realname.sh" example. + In "Internal Commands and Builtins" section: + Corrections on "ps", "suspend", "command", and "builtin". + Moved "echo", "cd", and "let" here from "External Commands" + section. + Note on "echo" deleting linefeeds in command output. + Added in-line examples for "echo". + Correction on "find" (-exec). + Added "col-totaler3.sh" as an example of using "export" to + pass a variable to an embedded awk script. + Removed "stop" (how the heck did a "csh" command sneak in?). + Removed "." from examples of builtins. + Minor fixup on "ex33.sh" example. + Added cautionary note on "eval". + Added examples ("rot13_2.sh") to "eval". + Added long note to "jobs" command clarifying difference between jobs + and processes. + Added in-line example on "printf". + Clarified "keyword" definition. + Fixed typos in "read" and "find" command subsections. + In "External Filters, Programs, and Commands" section: + Clarifications on "chmod" and "chattr". + Added alternative method in "ex57.sh" example. + Clarification on "ex42.sh" example. + Clarification on "ex44.sh" example. + Clarification on "ex45.sh" example. + Option "-c" to "uniq" discussed. + Correction on "cut". + Clarification on "colrm". + Clarification on "join". + Clarification on "head", and added example "rnd.sh". + Concise form of "lookup.sh". + Clarification on "gs". + Added notes on "wc" (and fixup of example). + At "grep": + Additional minor fixups. + Note in "grp.sh" script. + Added usage examples for "-c" and "-z" options. + Added note on "time" about it becoming a reserved word. + Clarification and corrections on "tr". + Clarification in "ex49.sh" and "rot13.sh". + Added alternative code to "lowercase.sh". + Added note to "fmt" about Kamil Toman's "par" utility. + Added note to "line-number.sh" script about '-ba' option to 'nl'. + Clarification and fixup on "pr". + Added note to "zcat". + Added alternative code to "strip-comments.sh". + Fixed "lp". + Added two usage examples for "yes". + Added altenative methods to "find" in-line example. + Fixed format in "cat/tac" in-line example. + Added long note to "xargs". + Added note to "touch", and link from ":" in "Special Characters" + section. + Fixup on "zcat" in "gzip" subsection, and fixed typo there. + At "dd": + Added usage examples". + Fixed comments "dd-keypress.sh". + Fixed typo on "grep". + Explanatory note on "-maxdepth" option for "grep". + In "System Commands" section: + Moved "shopt" to "Internal Commands and Builtins". + More info on "who". + Correction and clarification on "hostname". + More info on "env". + Added "lsof". + Clarification on "pidof". + Moved "exec" to "Internal Commands and Builtins" and made some + corrections in the commentary. + Using "stty" to detect keypress, with illustrative example. + Fixup on "chgrp". + Fixup on "nice". + Fixup on "sync". + Added "createfs" example to illustrate "losetup". + At "stty", added long sidebar explaining canonical mode in terminals. + Fixup and additional illustrations on example. + Additional commentary on "ifconfig" code snippets. + Clarifications in "Arithmetic Expansion" section. + In "I/O Redirection" section: + Added note to "redir1.sh" example. + Added note to "redir2.sh" example. + Clarifications and notes added on "redir2a.sh", "redir3.sh", + "redir4.sh", and "redir5.sh" examples. + Added ": >" file truncation note. + Added examples (programlisting) of word splitting. + Added example of newline deletion. + Fixups (removed extraneous spaces in redirection operators in example + snippets). + Added alternative forms of operators that close file descriptors. + Added note and code snippet to "Closing File Descriptors" subsection. + Added "logevents.sh" example of using redirection operations in event + logging. + Added example snippet for "[j]<>filename". + In "Gotchas" section: + Fixed errors in using bad variable names. + Stylistic notes added. + Added note about attempting to use "-" as redirection operator. + Added notes and in-line example snippets about mixing up "=" and "-eq". + Correction on making script "suid". + Corrections and explanatory notes in "Regular Expressions" section. + Notes about "+" and curly brackets in "gawk". + Note and example ("newline.sh") about using "." to match newlines. + Footnote about matching dotfiles with globbing. + In "Subshells" section: + Fixup on in-line example. + Added example of subshell redirection. + Setting up a "dedicated environment" for a command group. + Added comment to code snippet illustrating parallel processes. + Added note about I/O redirection to subshells. + In "Functions" section: + Fix up and elaborate "ex60.sh" example. + Example ("ref-params.sh") of passing reference parameters to functions. + Comments and example on recursion. + Note and example snippet on declaring functions before calling them. + Note and example snippet on nested function. + Note and example snippet on function declarations in unlikely places. + Note and example snippet on using dedicated variables for return values. + Note and example snipptets on an alternative method of redirecting + the stdin of a function. + In "List Constructs" section: + Note and example snippets on operator precedence in compound + statements. + In "Arrays" section: + Added notes to "ex67.sh". + Added alternative implementation to "ex68.sh". + Added notes and example snippet on ${xxx[@]} and ${xxx[*]} notation. + Added notes to "twodim.sh" example. + Added "{#array}" as string length of first element of array. + Added "empty-array.sh" example. + In "Files" section, clarification on "/etc/profile". + In "Exit and Exit Status" section, added clarifying notes in in-line + example. + In "Here Documents" section: + Added note to "ex71.sh". + Fixup on "ex71c.sh". + Added note and example on "anonymous here documents". + Removed caution about pagers not working in a here document. + Added note about temporary files used by here documents. + In "Zeroes and Nulls" section, added note about ": >" alternate to + "cat /dev/null >". + In "Process Substitution" section: + Fixed error in note about not leaving space between ">(command)". + Changed "(command)>" to correct ">(command)". + Added example snippets. + In "Debugging" section: + Added commentary after "test24, another buggy script". + Correction on "exit" sending signal 0. + Added note and example ("vartrace.sh") in trapping discussion. + Notes added to "online.sh". + In "Miscellany" section: + Added using "[[ ]]" and "(( ))" in comparisons. + Corrections in discussion of interactive shells, plus + illustrative example. + In "Contributed Scripts" section: + Added "primes.sh" to demonstrate that arrays are not need to + generate prime numbers. + Added comments to "manview.sh" + Added comment to "tree.sh" + Added "obj-oriented.sh" example of object-oriented programming in a script. + Fixed error in comment in "pw.sh" + Notes on "string.sh". + In "Sed and Awk Micro-Primer" section, corrections, clarifications, + additions, and more examples. + In "Sample .bashrc File" appendix, correction pointing out that only + interactive shells read ".bashrc". + In "Sha-Bang" section: + Added note about the "#!" line being interpreted as a comment + by the command interpreter. + Added note about script needing read, as well as execute permission. + Added note about starting a "README" file with "#!/bin/more". + In "/dev and /proc" section: + Added note that /dev/sndstat has been eliminated as of the 2.3 + kernel. + Clarification on virtual devices. + Simplified code snippets illustrating "extracting data" from /proc files. + Noted that /dev is not a filesystem. + Added commentary to "pid-identifier.sh" example. + Fixed error in footnote: entries in /dev do take up some space. + In "Options" section: + Clarified "-c" option. + Added note to "-u" option. + Fixed typo (--arg1arg2) on "--" (changed to "-- arg1 arg2") + In "Converting DOS Batch Files" section: + Removed unnecessary variable from "viewdata.sh" example. + Fixups on tables of DOS batch file / shell script equivalents. + In "Scripting With Style" section: + Fixup on example script. + Noted that "exit status" of a script is available to the parent process + of that script, not necessarily the shell. + Rewritten version of "example 3-2". + Added "A Detailed Introduction to I/O Redirection" appendix. + Added "Localization" appendix. + Made corrections. + + + + +====================================================================================== + +Version 0.3, released 02/12/01 + +Comments: Another major improvement. The HOWTO is nearly book length, + still evolving toward becoming a GUIDE. + +Changes from version 0.2: + +1) Fixed: + Renamed Example A-2 in Appendix A (Contributed Scripts) to + "encryptedpw". It had previously been named "manview", duplicating + the title of Example A-1. + +2) In Chapter 1, the reader is now advised to use the example scripts + (something-or-other.sh), as an alternative to laboriously + cutting-and-pasting from rendered HTML. + +3) In "Special Characters" section, added brace expansion {xxx,yyy,zzz...}. + +4) Deleted the erroneous statement that the "set -r" option cannot be + invoked from within a script. + +5) Added section for "restricted shells" with additional info. + +6) Added a couple of script options. + +7) Fixed minor bug in code snippet in "Interactive Scripts" section. + +8) More info on interactive scripts. + +9) Fixed an error confusing '$#' with '$*' in "Loops" section and in ex23.sh. + +10) Added Antek Sawicki's random password script in contrib scripts. + +In "External Filters, Programs, and Commands" section: +------------------------------------------------------ +11) More accurately described the "{} \;" arguments to "find" command. Thanks + to Jim Van Zandt for pointing this out. + +12) Added note to "xargs" that "echo" is default command. Again thanks + to Jim Van Zandt. + +13) Fixed error claiming "diff" needs sorted files. Jim Van Zandt again. + +14) Cleared up ambiguity about "colrm". + +15) More info on "umask" and corrections. + +16) Added "mkfifo". +------------------------------------------------------ + +17) Added cross-reference on "&&". + +18) Added cross-reference to embedded sed script. + +19) Added example of embedded awk script (col-totaler.sh). + +20) Fixed clumsy wording in sed and awk description. + +21) Added "su" to "System and Administrative Commands" section. + +22) Added Jim Van Zandt's "daily backup" example script + to "Contrib-Scripts" section. + +23) Enhanced example 66 (ex66.sh) on arrays with more methods of initializing + array variables. + +24) Corrected "Siever" entry in bibliography. + +25) Added Jordi Sanfeliu's "tree" script to "Contrib-Scripts" section. + +26) Added Robbins' "Bash Reference Card" to bibliography. + +27) Added reference to Duarte's sed tutorial in bibliography. + +28) Added "rn.sh", file rename utility to "Contrib-Scripts" section. + +29) Added "initializing multiple variables on same line" to ex9.sh. + +30) Fixed title on "ex52.sh". + +31) Added a case when not to use shell scripts, in intro. + +32) Added shell script as embedded command in another script, Tcl or wish + script, etc. to "Miscellany / Assorted Tips" section. + +33) Added download link for latest version of document to intro. + +34) Added "id" to "System and Administrative Commands" section. + +35) Added "stty" to "System and Administrative Commands" section. + +36) Added "strip-comments.sh" example to illustrate "file" command, + and "rot13.sh" example to "tr" command, in "External Filters" section. + +37) Added "modular approach" sidebar to Chapter 2, section 1. + +38) Added example cross-references to use of REs in scripts by sed, + awk, and Perl. + +39) More info and clarification on command substitution and arithmetic + expansion in "Backticks" section. + +40) Corrected "Bibliography" section entry for Ben Okopnik's introductory + Bash scripting articles in "Linux Gazette". + +41) Added "Bibliography" section entries for "Bash-Prompt HOWTO" and + "Bash-Programming-Intro HOWTO". + +42) Added $OLDPWD, $BASH_VERSION, $DIRSTACK, $HOSTNAME, $PPID, $MACHTYPE, + $HOSTTYPE, $OSTYPE, $UID, $EUID, $SHELLOPTS, $IGNOREEOF, and $GROUPS + to internal Bash variables in "Variables Revisited" section. + +43) Added info on the "-" operator (may also be interpreted as "old + working directory", depending on context). + +44) Added collecting favorite definitions and functions into "library file" to + "Miscellany / Assorted Tips" section. + +45) Added cross reference from "dot" command to "source", later on in + tutorial. + +46) In "Special Characters" section, noted that a command may not follow + a comment on the same line. + +47) Added section on "Aliases", including two example scripts. + +48) Added discussion of "for" loops with multiple parameters in each [list] + element to "Loops Section". + +49) Added discussion of "while" loops with multiple conditions to "Loops + Section". + +50) Added cross-reference to mention of "getopts" in "while loops" discussion. + +51) Added cross-reference on "exec" in "System and Administrative Commands" + section back to use of "exec" in "find" command sequence in "External + Filters, Programs, and Commands" section. Added other cross-references in + this section. + +52) Added footnote about fd 5 being reserved to "I/O Redirection" section. + +53) Additional discussion in "I/O Redirection" section. + +54) Added using "exec" to redirect stdin to "I/O Redirection" section. + +55) Added "redir1.sh", example of I/O redirection using "exec". + +56) Added "redir2.sh", example of I/O redirected "while" loop. + +57) Added "redir3.sh", example of I/O redirected "until" loop. + +58) Added "redir4.sh", example of I/O redirected "for" loop. + +59) Added "redir5.sh", example of I/O redirected "if/then" test. + +60) Added "wipedir.sh" example to $PWD listing in "Variables Revisited" + section. + +61) More cross-references in "I/O Redirection" section. + +62) Added "grp.sh", 'grep' emulation script, after 'grep' listing + in "External Filters, Programs and Commands" section. + +63) Added "nice", "arch", "users" , "logname", "dmesg", "groups", + "hostname", and "pidof" to "System and Administrative Commands" + section. + +64) Added "bzip2", "sq", "rev", "strings", "pathchk" and references to + "egrep", "fgrep" , "groff, gs, TeX", "column", "look", "ptx", + "chattr", "cal", "nslookup", "traceroute", "dig", "rx/sx", "rz/sz", + "uucp", and "sum, cksum, md5sum" to "External Filters, Programs and + Commands" section. Also added illustrative examples for "column" + and "look". + +65) Added bibliography entries for GNU "gawk" reference manual and "groff" + tutorial. Also for I/O reference on UAlberta site. + +66) Added cross-references to script examples to "zcat" and "mv" + commands" in "External Filters, Programs and Commands" section. + +67) Clarification on [ -n $string ] string test operator. Added illustrative + example (str-test.sh). + +68) Added "lp" and related commands to "External Filters, Programs and + Commands" section. + +69) Added double-quoting variables to "Gotchas" section. + +70) Added more xrefs to examples in "Variables Revisited" section. + +71) Added "PS3" and "PS4" to "Variables Revisited" section. + +72) Added enabling script options from #! header to "Options" section. + +73) Added double backslash (\\) to "Quoting" section. + +74) Added "Sed and Awk Micro-primer" appendix. + +75) Fuller explanation of differences between "$*" and "$@" in "Variables + Revisited" section. Also added example to illustrate this, + "arglist.sh". + +76) More cross-references to examples in "System and Administrative Commands" + section. + +77) Added more detail to description of $PATH, in "Variables Revisited" + section. + +78) Added more detail to "Files" section. + +79) Added "command", "enable", , "builtin", "host", and "vrfy" to + "Internal Commands and Builtins" section. + +80) Moved "umask" from "External Filters, Programs, and Commands" to "System + and Administrative Commands" section. + +81) Rearranged the entries in "External Filters, Programs and Commands" in + somewhat more logical order and subdivided the section into logical + subsections. + +82) Moved discussion of embedded Perl scripts from "System and Administrative + Commands" section to "Shell Wrappers" subsection. + +83) Added example .bashrc file, thanks to Emmanuel Rouat. + +84) Many minor changes not listed above. + + + + +==================================================================== + +Version 0.2, released 10/30/00. + +Comments: This is a major improvement over 0.1. + +Changes from version 0.1: + + +Bugfixes + +1) fixed if [ cond1 && cond2 ] ==> if [ cond1 ] && [ cond2 ] + if [ cond1 || cond2 ] ==> if [ cond1 ] || [ cond2 ] +Added -a and -o options + if [ cond1 -a cond2 ] + if [ cond1 -o cond2 ] + +Added 'and-or.sh' as new example to illustrate && and ||. + + +2) Corrected ex6.sh, added $'s in front of {USER?} and {MAIL?}, + and added additional explanatory material. + +3) Noted that "-" is not a bash option. + + +Other changes + +4) ex55.sh: added note that 'killall' is Red Hat specific + +5) Added to 'Gotchas': + interchanging -eq and = + starting variables with a digit + +6) Substituted for Samuel Johnson quote at beginning: +"...there are dark corners in the Bourne shell, and people use all of them." + --Chet Ramey + +7) Added reference to /usr/doc/initscripts-X.XX/sysconfig.txt just after + ex. 3-52. + +8) Added reference to 'nl' in "External Filters" section and illustrative + example. + +9) Added material to 'cat' listing. + +10) Added: + cd source-directory + tar cf - . | (cd ../target-directory; tar xzf -) + to Alan Cox example as an alternative. + +11) Added material & example to {} + +12) Added "Renaming file extensions" example + to pattern matching section. + +13) Added "Bash F.A.Q." and "sed F.A.Q." to references. + +14) Added missing line in "Tests" section. + +15) Revised the 'abstract'. + +16) Added element. + +17) Reorganized: + Moved two examples placed erroneously in 'backticks' section + to where they belong. + +18) Fleshed out section on 'subshells'. + Added 2 examples. + +19) Rewrote text to first 'variables' section. + +20) Added "rpm-check.sh" example to "code blocks" discussion. + +21) Added "online.sh" example to "trap" discussion. + +22) Expanded "I/O Redirection" section + Definition of 'file descriptor' added. + More on file descriptors 3 - 9. + +23) Expanded "Regular Expression" section. + +24) Added explanation of signals to "debugging" section. + +25) Added SECONDS and REPLY to internal variables listing (plus illustrative + examples). + +26) Added 'ulimit' to administrative commands listing. + +27) Added more information on 'trap' in 'Debugging' section. + +28) Fixed erroneous '==' reference in 'Variables Revisited section. + +29) Added 'jobs', 'ps', and 'nohup' to 'Administrative Commands' section. + +30) Added additional entries to file tests in 'Tests' section. + +31) Added additional entries and much more detail in 'Options' section. + +32) More detail on 'grep'. + +33) More detail on 'export'. + +34) Added entries to file and string tests. + +35) Added 'uptime' to 'System and Administrative Commands' section. + +36) Added '~' to 'Special Characters' section. + +37) Added material to 'Backquotes' section. + +38) Added 'which' to 'External Filters and Commands' section. + +39) More detail on parameters to functions. + +40) More detail on arrays. + +41) More detail on 'at'. + +42) More detail on $RANDOM. Expanded example. + +43) Added example script to demonstrate timed input. + +44) Added 'Representation of Numerical Constants' subsection to 'Operations' + section. + +45) Added "eval var1=\$$var2" indirect reference notation to 'Variables + Revisited' section. + +46) Reorganized: + Moved 'Parameter Substition' discussion from 'Special Characters' section + to 'Variables' section. + Added extra illustrative code snippets. + +47) Added bubble sort example to 'Arrays' section. + +48) Added %= operator to 'Operations' section. + +49) Added reference to 'whoami' to 'System and Administrative Commands' + section. + +50) More detail and an additional example for 'Quoting' section. + +51) Added info on using pattern match operator, ${var/patt/}, for deletion. + +52) More detail on 'touch' and 'read' in 'External Filters'. + +53) More detail on 'null' operator (:). + +54) Some of the preexisting examples revised, with more material. + +55) 'Miscellany' section added. + subsection 'Interactive Scripts' + subsection 'Optimizations' + subsection 'Assorted Tips' + +56) Contrib script section added + 4 scripts so far. + +57) Expanded 'Credits' section. + + +58) Many other corrections, minor changes, and additions. + + + +==================================================================== + +Version 0.1 released 14 June, 2000. diff --git a/LDP/guide/docbook/abs-guide/assert.sh b/LDP/guide/docbook/abs-guide/assert.sh new file mode 100644 index 00000000..263af9f7 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/assert.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# assert.sh + +assert () # If condition false, +{ #+ exit from script with error message. + E_PARAM_ERR=98 + E_ASSERT_FAILED=99 + + + if [ -z "$2" ] # Not enough parameters passed. + then + return $E_PARAM_ERR # No damage done. + fi + + lineno=$2 + + if [ ! $1 ] + then + echo "Assertion failed: \"$1\"" + echo "File $0, line $lineno" + exit $E_ASSERT_FAILED + # else + # return + # and continue executing script. + fi +} + + +a=5 +b=4 +condition="$a -lt $b" # Error message and exit from script. + # Try setting "condition" to something else, + #+ and see what happens. + +assert "$condition" $LINENO +# The remainder of the script executes only if the "assert" does not fail. + + +# Some commands. +# ... +# Some more commands. + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/bashandperl.sh b/LDP/guide/docbook/abs-guide/bashandperl.sh new file mode 100644 index 00000000..718d8eaf --- /dev/null +++ b/LDP/guide/docbook/abs-guide/bashandperl.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# bashandperl.sh + +echo "Greetings from the Bash part of the script." +# More Bash commands may follow here. + +exit 0 +# End of Bash part of the script. + +# ======================================================= + +#!/usr/bin/perl +# This part of the script must be invoked with -x option. + +print "Greetings from the Perl part of the script.\n"; +# More Perl commands may follow here. + +# End of Perl part of the script. diff --git a/LDP/guide/docbook/abs-guide/idelete.sh b/LDP/guide/docbook/abs-guide/idelete.sh new file mode 100644 index 00000000..94d789be --- /dev/null +++ b/LDP/guide/docbook/abs-guide/idelete.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# idelete.sh: Deleting a file by its inode number. + +# This is useful when a filename starts with an illegal character, +#+ such as ? or -. + +ARGCOUNT=1 # Filename arg must be passed to script. +E_WRONGARGS=70 +E_FILE_NOT_EXIST=71 +E_CHANGED_MIND=72 + +if [ $# -ne "$ARGCOUNT" ] +then + echo "Usage: `basename $0` filename" + exit $E_WRONGARGS +fi + +if [ ! -e "$1" ] +then + echo "File \""$1"\" does not exist." + exit $E_FILE_NOT_EXIST +fi + +inum=`ls -i | grep "$1" | awk '{print $1}'` +# inum = inode (index node) number of file +# Every file has an inode, a record that hold its physical address info. + +echo; echo -n "Are you absolutely sure you want to delete \"$1\" (y/n)? " +read answer +case "$answer" in +[nN]) echo "Changed your mind, huh?" + exit $E_CHANGED_MIND + ;; +*) echo "Deleting file \"$1\".";; +esac + +find . -inum $inum -exec rm {} \; +echo "File "\"$1"\" deleted!" + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/int-or-string.sh b/LDP/guide/docbook/abs-guide/int-or-string.sh new file mode 100644 index 00000000..43480194 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/int-or-string.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# int-or-string.sh +# Integer or string? + +a=2334 # Integer. +let "a += 1" +echo "a = $a " # Integer, still. +echo + +b=${a/23/BB} # Transform into a string. +echo "b = $b" # BB35 +declare -i b # Declaring it an integer doesn't help. +echo "b = $b" # BB35, still. + +let "b += 1" # BB35 + 1 = +echo "b = $b" # 1 +echo + +c=BB34 +echo "c = $c" # BB34 +d=${c/BB/23} # Transform into an integer. +echo "d = $d" # 2334 +let "d += 1" # 2334 + 1 = +echo "d = $d" # 2335 + +# Variables in Bash are essentially untyped. + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/m4.sh b/LDP/guide/docbook/abs-guide/m4.sh new file mode 100644 index 00000000..e4ebb5af --- /dev/null +++ b/LDP/guide/docbook/abs-guide/m4.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# m4.sh: Using the m4 macro processor + +# Strings +string=abcdA01 +echo "len($string)" | m4 # 7 +echo "substr($string,4)" | m4 # A01 +echo "regexp($string,[0-1][0-1],\&Z)" | m4 # 01Z + +# Arithmetic +echo "incr(22)" | m4 # 23 +echo "eval(99 / 3)" | m4 # 33 + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/match-string.sh b/LDP/guide/docbook/abs-guide/match-string.sh new file mode 100644 index 00000000..357ffbc2 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/match-string.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# match-string.sh: simple string matching + +match_string () +{ + MATCH=0 + NOMATCH=90 + PARAMS=2 # Function requires 2 arguments. + BAD_PARAMS=91 + + [ $# -eq $PARAMS ] || return $BAD_PARAMS + + case "$1" in + "$2") return $MATCH;; + * ) return $NOMATCH;; + esac + +} + + +a=one +b=two +c=three +d=two + + +match_string $a # wrong number of parameters +echo $? # 91 + +match_string $a $b # no match +echo $? # 90 + +match_string $b $d # match +echo $? # 0 + + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/ramdisk.sh b/LDP/guide/docbook/abs-guide/ramdisk.sh new file mode 100644 index 00000000..8199da4c --- /dev/null +++ b/LDP/guide/docbook/abs-guide/ramdisk.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# ramdisk.sh + +# A "ramdisk" is a segment of system RAM memory +#+ that acts as if it were a filesystem. +# Its advantage is very fast access (read/write time). +# Disadvantages: volatility, loss of data on reboot or powerdown. +# less RAM available to system. +# +# What good is a ramdisk? +# Keeping a large dataset, such as a table or dictionary on ramdisk +#+ speeds up data lookup, since memory access is much faster than disk access. + + +E_NON_ROOT_USER=70 # Must run as root. +ROOTUSER_NAME=root + +MOUNTPT=/mnt/ramdisk +SIZE=2000 # 2K blocks (change as appropriate) +BLOCKSIZE=1024 # 1K (1024 byte) block size +DEVICE=/dev/ram0 # First ram device + +username=`id -nu` +if [ "$username" != "$ROOTUSER_NAME" ] +then + echo "Must be root to run \"`basename $0`\"." + exit $E_NON_ROOT_USER +fi + +if [ ! -d "$MOUNTPT" ] # Test whether mount point already there, +then #+ so no error if this script is run + mkdir $MOUNTPT #+ multiple times. +fi + +dd if=/dev/zero of=$DEVICE count=$SIZE bs=$BLOCKSIZE # Zero out RAM device. +mke2fs $DEVICE # Create an ext2 filesystem on it. +mount $DEVICE $MOUNTPT # Mount it. +chmod 777 $MOUNTPT # So ordinary user can access ramdisk. + # However, must be root to unmount it. + +echo "\"$MOUNTPT\" now available for use." +# The ramdisk is now accessible for storing files, even by an ordinary user. + +# Caution, the ramdisk is volatile, and its contents will disappear +#+ on reboot or power loss. +# Copy anything you want saved to a regular directory. + +# After reboot, run this script again to set up ramdisk. +# Remounting /mnt/ramdisk without the other steps will not work. + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/recurse.sh b/LDP/guide/docbook/abs-guide/recurse.sh new file mode 100644 index 00000000..56ef0848 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/recurse.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# recurse.sh + +# Can a script recursively call itself? +# Yes, but this is of little or no practical use +#+ except perhaps as a "proof of concept". + +RANGE=10 +MAXVAL=9 + +i=$RANDOM +let "i %= $RANGE" # Generate a random number between 0 and $MAXVAL. + +if [ "$i" -lt "$MAXVAL" ] +then + echo "i = $i" + ./$0 # Script recursively spawns a new instance of itself. +fi # Each child script does the same, until + #+ a generated $i equals $MAXVAL. + +# Using a "while" loop instead of an "if/then" test causes problems. +# Exercise for the reader: Explain why. + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/redir4a.sh b/LDP/guide/docbook/abs-guide/redir4a.sh new file mode 100644 index 00000000..36c73815 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/redir4a.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +if [ -z "$1" ] +then + Filename=names.data # Default, if no filename specified. +else + Filename=$1 +fi + +Savefile=$Filename.new # Filename to save results in. +FinalName=Jonah # Name to terminate "read" on. + +line_count=`wc $Filename | awk '{ print $1 }'` # Number of lines in target file. + + +for name in `seq $line_count` +do + read name + echo "$name" + if [ "$name" = "$FinalName" ] + then + break + fi +done < "$Filename" > "$Savefile" # Redirects stdin to file $Filename, +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ and saves it to backup file. + +exit 0 diff --git a/LDP/guide/docbook/abs-guide/symlinks2.sh b/LDP/guide/docbook/abs-guide/symlinks2.sh new file mode 100644 index 00000000..2171812e --- /dev/null +++ b/LDP/guide/docbook/abs-guide/symlinks2.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# symlinks.sh: Lists symbolic links in a directory. + +ARGS=1 # Expect one command-line argument. +OUTFILE=symlinks.list # save file + +if [ $# -ne "$ARGS" ] # If not 1 arg... +then + directory=`pwd` # current working directory +else + directory=$1 +fi + +echo "symbolic links in directory \"$directory\"" + +for file in $( find $directory -type l ) # -type l = symbolic links +do + echo "$file" +done | sort > "$OUTFILE" # stdout of loop +# ^^^^^^^^^^^^ redirected to save file. + +exit 0