From b1fa3999005ff240b139e9063f98aeb4d5e90763 Mon Sep 17 00:00:00 2001 From: gferg <> Date: Fri, 21 Oct 2005 13:31:28 +0000 Subject: [PATCH] updated --- LDP/guide/docbook/abs-guide/Change.log | 104 ++- LDP/guide/docbook/abs-guide/abs-guide.sgml | 596 ++++++++++++------ LDP/guide/docbook/abs-guide/ex21.sh | 8 + LDP/guide/docbook/abs-guide/fc4upd.sh | 214 +++++++ LDP/guide/docbook/abs-guide/gcd.sh | 9 +- LDP/guide/docbook/abs-guide/idelete.sh | 6 +- LDP/guide/docbook/abs-guide/list-glob.sh | 16 +- LDP/guide/docbook/abs-guide/monthlypmt.sh | 15 +- .../docbook/abs-guide/multiple-processes.sh | 7 + LDP/guide/docbook/abs-guide/read-redir.sh | 2 +- LDP/guide/docbook/abs-guide/wf.sh | 5 + 11 files changed, 765 insertions(+), 217 deletions(-) create mode 100644 LDP/guide/docbook/abs-guide/fc4upd.sh diff --git a/LDP/guide/docbook/abs-guide/Change.log b/LDP/guide/docbook/abs-guide/Change.log index 005ad76f..da5ad874 100644 --- a/LDP/guide/docbook/abs-guide/Change.log +++ b/LDP/guide/docbook/abs-guide/Change.log @@ -6,6 +6,91 @@ http://personal.riverusers.com/~thegrendel/Change.log ------------------------------------------------------------------------ +Version 3.7 +Whortleberry release, 10/23/05 + +1) In "Special Characters" chapter: + At "whitespace" entry, added footnote about newline/linefeed. + +2) In "Basic Commands" section of "External Commands" Chapter: + At "ln" entry, noted that only symbolic links can refer to a directory. + +3) In "Text Processing Commands" section of "External Commands" Chapter: + Modified comments in "wf.sh" example. + At "grep" entry, fixed 2 typos + "Now, let's search this file . . . " + "printf 'a b\nc d\n\n\n\n\n\000\n\000e\000\000\nf' | grep -cz ." + At "diff" entry, fixed typo ("spiff" --> "sdiff"). + (Thank you, Frank Wang.) + At "colrm" entry, changed "warning" to "caution" -- toned it down a bit. + At "cut" entry, + Added note about using linefeed as delimiter. + (Thank you, Jaka Kranjc.) + Got rid of unnecessary "cat" in inline example. + At "iconv" entry, added snippet of code from "booklistgen.sh" script. + (Thank you, Peter Knowles, for permission to use it.) + +4) In "Complex Commands" section of "External Commands" Chapter: + At "expr" entry, added usage example of escaped parentheses. + (Thank you, Peter Knowles, for permission to use it.) + +5) In "File and Archiving Commands" section of "External Commands" Chapter: + Added "sha1sum" command at Frank Wang's suggestion. + +6) In "Communications Commands" section of "External Commands" chapter: + In "Remote Host Access" subsection, added "scp" entry. + Added material at "uucp" entry. + Added "uux" entry. + At "wget" listing, added comments. + + At "rsync" entry, fixed up usage example. + Added "fc4upd.sh" example. + (Thank you, Frank Wang.) + +7) In "Complex Commands" section of "External Commands" Chapter: + At "xargs" entry, added footnote about speeding up execution. + +8) In "Math Commands" section of "External Commands" chapter: + Added Frank Wang's comments to "monthlypmt.sh" example. + +9) In "Miscellaneous Commands" section of "External Commands" chapter: + At "tee" entry, redesigned diagram for greater clarity. + +10) In "Testing and Branching" section of "Loops and Branches" chapter: + Rewrote explanation of filename "globbing" in the [list] of a for-loop + and added comments to "list-glob.sh" example. + +11) In "Quoting" chapter: + Added sidebar near beginning of chapter. + Removed intro paragraph (superfluous) at beginning of "Quoting Variables" + section. + +12) In "$RANDOM" section of "Variables Revisited" chapter: + Added comment to "ex21.sh" example. + +13) In "Command Substitution" chapter: + Added footnote about nesting command substitution with backticks + by using escaping. + (Thanks, John Default.) + +14) In "System and Administrative Commands" chapter: + Moved "dmesg" entry to "Information and Statistics" subsection. + In "Process Control and Booting" subsection, added "service" entry. + At "uptime" entry, added note about load average. + Fixups at "terminals and modes" sidebar, second example. + (Thank you, Mark Norman.) + +15) In "Bibliography" section: + Added reference and URL for Col Needham's original IBDB scripts. + +16) Numerous typos corrected, per a list sent in by Mark Norman (thanks!). + +17) Various changes and fixups in example scripts. + + + + + Version 3.6 Pokeberry release, 08/28/05 @@ -75,13 +160,10 @@ Pokeberry release, 08/28/05 At "xargs" entry, added extra usage example. At "expr" entry, added example of illegal arithmetic operation. -14) In "Here Documents" chapter: - Added "self-document2.sh" example. - -15) In "$RANDOM" section of "Variables Revisited" chapter: +14) In "$RANDOM" section of "Variables Revisited" chapter: Added Frank Wang's alternative to jipe's example. -16) In "Quoting" chapter: +15) In "Quoting" chapter: Split the chapter into introduction and "Quoting Variables" and "Escaping" sections. @@ -93,33 +175,33 @@ Pokeberry release, 08/28/05 splitting. (Thank you, Harald Koenig.) -17) In "Local Variables" section of "Functions" chapter: +16) In "Local Variables" section of "Functions" chapter: In footnoted example of a segfaulting recursive function, added an "echo" to properly exercise the function. (Thank you, Dr. Roland Sonnenschein.) -18) In "Debugging" chapter: +17) In "Debugging" chapter: At listing of "Tools for debugging non-working scripts," added list item for "$LINENO" variable and "caller" builtin. At "trap" entry, replaced buggy "multiple-processes.sh" example. (Thank you, Tedman Eng.) -19) In "Copyright" chapter: +18) In "Copyright" chapter: Updated licensing terms to give the LDP the right to reassign custodianship of the book in the event the author cannot be contacted. -20) In "Bibliography" section: +19) In "Bibliography" section: Added entry for Peter Knowles' booklistgen.sh -- Sony Librie booklist generator -- making possible Linux access to this neat e-book reader. -21) Corrected spelling of the name of contributor Stéphane Chazelas +20) Corrected spelling of the name of contributor Stéphane Chazelas in multiple places. (Thank you, Bertrand Mollinier Toublet, for pointing out these embarrassing typos.) -22) Various changes and fixups in example scripts. +21) Various changes and fixups in example scripts. diff --git a/LDP/guide/docbook/abs-guide/abs-guide.sgml b/LDP/guide/docbook/abs-guide/abs-guide.sgml index 3f31758e..a4a77fd5 100644 --- a/LDP/guide/docbook/abs-guide/abs-guide.sgml +++ b/LDP/guide/docbook/abs-guide/abs-guide.sgml @@ -327,6 +327,7 @@ Uncomment line below to generate index. + @@ -347,19 +348,12 @@ Uncomment line below to generate index. - 3.6 - 28 August 2005 + 3.7 + 23 October 2005 - - 3.4 - 08 May 2005 - mc - 'TEABERRY' release: Important Update. - - 3.5 04 June 2005 @@ -374,6 +368,13 @@ Uncomment line below to generate index. 'POKEBERRY' release: Bugfix Update. + + 3.7 + 23 Oct 2005 + mc + 'WHORTLEBERRY' release: Bugfix Update. + + @@ -394,7 +395,7 @@ Uncomment line below to generate index. introduction to programming concepts. + url="http://personal.riverusers.com/~thegrendel/abs-guide-3.7.tar.bz2"> The latest update of this document, as an archived, bzip2-ed tarball including both the SGML source and rendered HTML, may @@ -1257,7 +1258,7 @@ esac NOP (no op, a do-nothing operation). It may be considered a synonym for the shell builtin true. The - : command is a itself a + : command is itself a Bash builtin, and its exit status is true (0). @@ -1344,7 +1345,7 @@ fi May be used to begin a comment line, although this is not recommended. Using # for a comment turns off error checking for the remainder of that line, so - almost anything may be appear in a comment. However, + almost anything may appear in a comment. However, this is not the case with :. : This is a comment that generates an error, ( if [ $x -eq 3] ). @@ -1828,7 +1829,7 @@ echo "a = $a" # a = 321 (value inside code block) linkend="subshellsref">subshell. Exception: a code block in braces as - part of a pipe may be run as a + part of a pipe may run as a subshell. ls | { read firstline; read secondline; } @@ -2884,11 +2885,19 @@ echo <Ctl-V><Ctl-J> functions as a separator, separating commands or variables. - Whitespace consists of either spaces, tabs, blank - lines, or any combination thereof. In some contexts, - such as variable assignment, - whitespace is not permitted, and results in a syntax - error. + Whitespace consists of either + spaces, + tabs, blank + lines, or any combination thereof. + + A linefeed (newline) + is also a whitespace character. This explains why + a blank line, consisting only + of a linefeed, is considered whitespace. + + In some contexts, such as variable + assignment, whitespace is not permitted, and + results in a syntax error. Blank lines have no effect on the action of a script, @@ -3374,6 +3383,11 @@ fi ls: [Vv]*: No such file or directory + In everyday speech or writing, when we + quote a phrase, we set it apart and give it special + meaning. In a Bash script, when we quote a + string, we set it apart and protect its literal + meaning. Certain programs and utilities reinterpret or expand special characters in a quoted string. An important use of @@ -3414,13 +3428,6 @@ fi Quoting Variables - Bash interprets a weak-quoted string starting with - $ as the value of a - variable. - - . . . - When referencing a variable, it is generally advisable to enclose its name in double quotes. This prevents reinterpretation of all special characters within @@ -4494,7 +4501,8 @@ home=/home/bozo -h - file is a symbolic link + file is a symbolic + link -L @@ -4553,7 +4561,7 @@ home=/home/bozo when an ordinary user invokes it. Be aware that suid - binaries may open security holes and that the + binaries may open security holes. The suid flag has no effect on shell scripts. @@ -4599,7 +4607,9 @@ home=/home/bozo he can only delete files in it that he owns. This keeps users from inadvertently overwriting or deleting each other's files in a publicly accessible directory, such - as /tmp. + as /tmp. + (The owner of the directory or root + can, of course, delete or rename files there.) @@ -5136,13 +5146,15 @@ echo "z = $z" # z = 125 - modulo, or mod (returns the remainder of an integer - division operation) + modulo, or mod (returns the + remainder of an integer division + operation) bash$ expr 5 % 3 2 + 5/3 = 1 with remainder 2 This operator finds use in, among other things, @@ -8627,10 +8639,11 @@ echo $? # 1 - The [list] in a - for loop may contain filename globbing, that is, - wildcards used in filename expansion. + If the [list] in a + for loop contains wildcards + (* and ?) used in filename + expansion, then globbing + takes place. <command>Operating on files with a for</command> loop @@ -8664,7 +8677,7 @@ echo $? # 1 - This is a somewhat more complex example of using command + Here is a somewhat more complex example of using command substitution to create the [list]. @@ -8694,7 +8707,8 @@ echo $? # 1 a command or commands. - Listing the symbolic links in a directory + Listing the <link linkend="symlinkref">symbolic + links</link> in a directory &symlinks; @@ -9489,7 +9503,7 @@ var=nonexistent_directory error() { printf "$@" >&2 - # Formats positional params passed, and sents them to stderr. + # Formats positional params passed, and sends them to stderr. echo exit $E_BADDIR } @@ -11452,11 +11466,13 @@ chmod u+s filename The ln creates only a reference, a pointer to the file only a few bytes in size. + + The ln command is most often used with the , symbolic or - soft link flag. An advantage of using the - flag is that it permits linking across - file systems. + soft link flag. Advantages of using the + flag are that it permits linking across + file systems or to directories. The syntax of the command is a bit tricky. For example: ln -s oldfile newfile links the @@ -11464,28 +11480,28 @@ chmod u+s filename newly created link, newfile. If a file named newfile has - previously existed, it will be deleted when the filename - newfile is preempted as the name for a - link. + previously existed, an error message will + result. Which type of link to use? As John Macdonald explains it: - Both of these provide a certain measure of dual reference - -- if you edit the contents of the file using any - name, your changes will affect both the original name - and either a hard or soft new name. The differences - between them occurs when you work at a higher level. - The advantage of a hard link is that the new name is - totally independent of the old name -- if you remove or - rename the old name, that does not affect the hard link, - which continues to point to the data while it would leave - a soft link hanging pointing to the old name which is no - longer there. The advantage of a soft link is that it - can refer to a different file system (since it is just - a reference to a file name, not to actual data). + Both of these [types of links] provide a certain measure of dual reference + -- if you edit the contents of the file using any name, + your changes will affect both the original name and either + a hard or soft new name. The differences between them + occurs when you work at a higher level. The advantage of + a hard link is that the new name is totally independent + of the old name -- if you remove or rename the old name, + that does not affect the hard link, which continues + to point to the data while it would leave a soft link + hanging pointing to the old name which is no longer + there. The advantage of a soft link is that it can refer + to a different file system (since it is just a reference + to a file name, not to actual data). And, unlike a hard + link, a symbolic link can refer to a directory. @@ -11686,7 +11702,11 @@ find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' \ substitution fails with a too many arguments error, substituting xargs often - works. Normally, xargs reads from + works. + And even when xargs is + not strictly necessary, it can speed up execution of a command + involving batch processing of multiple files. + Normally, xargs reads from stdin or from a pipe, but it can also be given the output of a file. @@ -11714,7 +11734,6 @@ find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' \ ./sent-mail-jul-2005: (Linux Documentation Project Site, rtf version) ./sent-mail-jul-2005: Subject: Criticism of Bozo's Windows/Linux article ./sent-mail-jul-2005: while mentioning that the Linux ext2/ext3 filesystem - ./sent-mail-jul-2005: As a side-effect of the Docbook/SGML stylesheet . . . @@ -11875,11 +11894,22 @@ find /etc -type f -exec cat '{}' \; | tr -c '.[:digit:]' '\n' \ - This example illustrates how + The above script illustrates how expr uses the escaped parentheses -- \( ... \) -- grouping operator in tandem with regular - expression parsing to match a substring. + expression parsing to match a substring. + Here is a another example, this time from real + life. + + # Strip the whitespace from the beginning and end. +LRFDATE=`expr "$LRFDATE" : '[[:space:]]*\(.*\)[[:space:]]*$'` + +# From Peter Knowles' "booklistgen.sh" script +#+ for converting files to Sony Librie format. +# (http://booklistgensh.peterknowles.com) + + Perl, @@ -12420,7 +12450,7 @@ OneYearAgo=$(date --date='1 year ago') Using cut to obtain a listing of the mounted filesystems: - cat /etc/mtab | cut -d ' ' -f1,2 + cut -d ' ' -f1,2 /etc/mtab Using cut to list the OS and kernel version: uname -a | cut -d" " -f1,3,11,12 @@ -12450,6 +12480,22 @@ done cut -d ' ' -f2,3 filename is equivalent to awk -F'[ ]' '{ print $2, $3 }' filename + + It is even possible to specify a linefeed as a + delimiter. The trick is to actually embed a linefeed + (RETURN) in the command sequence. + + bash$ cut -d' + ' -f3,7,19 testfile +This is line 3 of testfile. + This is line 7 of testfile. + This is line 19 of testfile. + + + + Thank you, Jaka Kranjc, for pointing this out. + + See also . @@ -12688,7 +12734,7 @@ done # means count (-c) zero-separated (-z) items matching "." # that is, non-empty ones (containing at least 1 character). # -printf 'a b\nc d\n\n\n\n\n\000\n\000e\000\000\nf' | grep -cz . # 4 +printf 'a b\nc d\n\n\n\n\n\000\n\000e\000\000\nf' | grep -cz . # 3 printf 'a b\nc d\n\n\n\n\n\000\n\000e\000\000\nf' | grep -cz '$' # 5 printf 'a b\nc d\n\n\n\n\n\000\n\000e\000\000\nf' | grep -cz '^' # 5 # @@ -12782,7 +12828,7 @@ Here is some text. Now, let's search this file for lines containing both file and - test . . . + text . . . bash$ grep file tstfile # Filename: tstfile @@ -13194,12 +13240,12 @@ tr -d 0-9 <filename colrm 2 4 <filename removes the second through fourth characters from each line of the text file filename. - If the file contains tabs or nonprintable + If the file contains tabs or nonprintable characters, this may cause unpredictable behavior. In such cases, consider using expand and unexpand in a pipe preceding - colrm. + colrm. @@ -13317,9 +13363,24 @@ tr -d 0-9 <filename encoding + A utility for converting file(s) to a different encoding (character set). Its chief use is for localization. + + + # Convert a string from UTF-8 to UTF-16 and print to the BookList +function write_utf8_string { + STRING=$1 + BOOKLIST=$2 + echo -n "$STRING" | iconv -f UTF8 -t UTF16 | cut -b 3- | tr -d \\n >> "$BOOKLIST" +} + +# From Peter Knowles' "booklistgen.sh" script +#+ for converting files to Sony Librie format. +# (http://booklistgensh.peterknowles.com) + + @@ -13496,7 +13557,11 @@ tr -d 0-9 <filename - The standard UNIX archiving utility. Originally a + The standard UNIX archiving utility. + An archive, + in the sense discussed here, is simply a set of related + files stored in a single location. + Originally a Tape ARchiving program, it has developed into a general purpose package that can handle all manner of archiving with all types of destination @@ -13587,15 +13652,16 @@ tr -d 0-9 <filename Shell archiving utility. The files in a shell archive - are concatenated without compression, and the resultant - archive is essentially a shell script, complete with - #!/bin/sh header, and containing all - the necessary unarchiving commands. Shar archives + are concatenated without compression, and the + resultant archive is essentially a shell script, + complete with #!/bin/sh header, + and containing all the necessary unarchiving + commands. Shar archives still show up in Internet newsgroups, but otherwise shar has been pretty well replaced by tar/gzip. The unshar command unpacks - shar archives. + shar archives. @@ -14216,7 +14282,7 @@ file $DIRECTORY/* | fgrep $KEYWORD make the output of the command easier to interpret. There are available various fancy frontends for - diff, such as spiff, + diff, such as sdiff, wdiff, xdiff, and mgdiff. @@ -14492,6 +14558,7 @@ gzip -cd patchXX.gz | patch -p0 sum cksum md5sum + sha1sum sum @@ -14513,17 +14580,23 @@ gzip -cd patchXX.gz | patch -p0 command md5sum + + command + sha1sum + These are utilities for generating checksums. A checksum is a number mathematically calculated from the contents of a file, for the purpose of checking its integrity. A script might refer to a list - of checksums for security purposes, such as ensuring that - the contents of key system files have not been altered - or corrupted. For security applications, use the 128-bit + of checksums for security purposes, such as ensuring + that the contents of key system files have not been + altered or corrupted. For security applications, use the md5sum (message digest 5 - checksum) command. + checksum) command, or better yet, + the newer sha1sum (Secure Hash + Algorithm). @@ -14549,9 +14622,10 @@ gzip -cd patchXX.gz | patch -p0 The cksum command shows the size, in bytes, of its target, whether file or stdout. - The md5sum command displays a - dash when it receives its input from - stdout. + The md5sum and + sha1sum commands display a + dash when they receive their input from + stdout. @@ -14559,10 +14633,24 @@ gzip -cd patchXX.gz | patch -p0 &fileintegrity; - See also and Also see and for creative uses of the md5sum command. + + There have been reports that the 128-bit + md5sum can be cracked, so the more secure + 160-bit sha1sum is a welcome new addition + to the checksum toolkit. + + bash$ md5sum testfile +e181e2c8720c60522c4c4c981108e367 testfile + + +bash$ sha1sum testfile +5d7425a9c08a66c3177f1e31286fa40986ffc996 testfile + + @@ -15278,6 +15366,8 @@ echo "tempfile name = $tempfile" uucp + uux + cu uucp @@ -15285,9 +15375,22 @@ echo "tempfile name = $tempfile" command uucp + + uux + unix to unix execute + + + cu + call up + + + command + uucp + - UNIX to UNIX copy. This is a + uucp: UNIX to UNIX + copy. This is a communications package for transferring files between UNIX servers. A shell script is an effective way to handle a uucp command sequence. @@ -15296,28 +15399,27 @@ echo "tempfile name = $tempfile" uucp seems to have faded into obscurity, but it still exists and remains perfectly workable in situations where an Internet connection is not available - or appropriate. + or appropriate. The advantage of uucp + is that it is fault-tolerant, so even if there is a service + interruption the copy operation will resume where it left + off when the connection is restored. + --- + + uux: UNIX to UNIX execute. + Execute a command on a remote system. This + command is part of the uucp package. + + --- + + cu: Call Up + a remote system and connect as a simple terminal. + It is a sort of dumbed-down version of telnet. This command is part + of the uucp package. - - cu - - cu - - - command - call up - - - Call Up - a remote system and connect as a simple terminal. This - command is part of the uucp package. It - is a sort of dumbed-down version of telnet. - - telnet @@ -15349,10 +15451,15 @@ echo "tempfile name = $tempfile" The wget utility non-interactively retrieves or downloads files from a Web or ftp site. It works well in a - script. - wget -p http://www.xyz23.com/file01.html -wget -r ftp://ftp.xyz24.net/~bozo/project_files/ -O $SAVEFILE - + script. + + wget -p http://www.xyz23.com/file01.html +# The -p or --page-requisite option causes wget to fetch all files +#+ required to display the specified page. + +wget -r ftp://ftp.xyz24.net/~bozo/project_files/ -O $SAVEFILE +# The -r option recursively follows and retrieves all links +#+ on the specified site. Getting a stock quote @@ -15456,15 +15563,21 @@ wget -r ftp://ftp.xyz24.net/~bozo/project_files/ -O $SAVEFILE (synchronizes) files between two different networked machines. - - rsync -a /node1/subdirectory/ + + bash$ rsync -a ~/sourcedir/*txt /node1/subdirectory/ + + + + Updating FC4 + &fc4upd; + Using rcp, rsync, - and similar utilities with security implications in a shell - script may not be advisable. Consider, instead, using - ssh or an expect - script. + and similar utilities with security implications in a + shell script may not be advisable. Consider, instead, + using ssh, scp, + or an expect script. @@ -15507,6 +15620,24 @@ wget -r ftp://ftp.xyz24.net/~bozo/project_files/ -O $SAVEFILE + + + scp + + scp + + + command + secure copy + + + Secure copy, similar in + function to rcp, copies files between + two different networked machines, but does so using + authentication, and with a security level similar to + ssh. + + @@ -16225,7 +16356,7 @@ done tee - [UNIX borrows an idea here from the plumbing trade.] + [UNIX borrows an idea from the plumbing trade.] This is a redirection operator, but with a difference. Like the plumber's tee, it permits siponing off to a file the output of a command @@ -16234,12 +16365,12 @@ done keep track of it for debugging purposes. - tee - |------> to file - | - ===============|=============== - command--->----|-operator-->---> result of command(s) - =============================== + (redirection) + |----> to file + | + ==========================|==================== + command ---> command ---> |tee ---> command ---> ---> output of pipe + =============================================== @@ -17219,12 +17350,12 @@ sudo cp /root/secretfile /home/bozo/secret <ctl-D> bash$ cat filexxx hello world -bash$ bash$ wc -c < file -13 +bash$ wc -c < filexxx +12 - The process controlling the terminal receives only 13 - characters (12 alphabetic ones, plus a newline), although + The process controlling the terminal receives only 12 + characters (11 alphabetic ones, plus a newline), although the user hit 26 keys. @@ -17419,37 +17550,9 @@ setserial /dev/$DEVICE irq 0 ; setserial /dev/$DEVICE irq $IRQ< - - dmesg - - dmesg - - - command - dmesg - - - Lists all system bootup messages to - stdout. Handy for debugging and - ascertaining which device drivers were installed - and which system interrupts in use. The output - of dmesg may, of course, be - parsed with grep, - sed, or awk from within a script. - - bash$ dmesg | grep hda -Kernel command line: ro root=/dev/hda2 - hda: IBM-DLGA-23080, ATA DISK drive - hda: 6015744 sectors (3080 MB) w/96KiB Cache, CHS=746/128/63 - hda: hda1 hda2 hda3 < hda5 hda6 hda7 > hda4 - - - - - + <anchor id="statisticssys1">Information and Statistics @@ -17605,7 +17708,7 @@ setserial /dev/$DEVICE irq 0 ; setserial /dev/$DEVICE irq $IRQ< This is the Linux equivalent of - truss. + the Solaris truss command. @@ -17798,6 +17901,35 @@ exit 0 + + dmesg + + dmesg + + + command + dmesg + + + Lists all system bootup messages to + stdout. Handy for debugging and + ascertaining which device drivers were installed + and which system interrupts in use. The output + of dmesg may, of course, be + parsed with grep, + sed, or awk from within a script. + + bash$ dmesg | grep hda +Kernel command line: ro root=/dev/hda2 + hda: IBM-DLGA-23080, ATA DISK drive + hda: 6015744 sectors (3080 MB) w/96KiB Cache, CHS=746/128/63 + hda: hda1 hda2 hda3 < hda5 hda6 hda7 > hda4 + + + + + stat @@ -17900,10 +18032,19 @@ exit 0 uptime + Shows how long the system has been running, along with associated statistics. + bash$ uptime 10:28pm up 1:57, 3 users, load average: 0.17, 0.34, 0.27 + + A load average of 1 or less + indicates that the system handles processes immediately. A load + average greater than 1 means that processes are being queued. When + the load average gets above 3, then system performance is + significantly degraded. + @@ -18432,6 +18573,7 @@ Average: all 6.33 1.70 14.71 0.00 77.26init + The init command is the parent of all processes. Called in the final step of a bootup, init @@ -18507,6 +18649,30 @@ Average: all 6.33 1.70 14.71 0.00 77.26 + + service + + service + + + command + service + + + Starts or stops a system service. + The startup scripts in /etc/init.d + and /etc/rc.d use this + command to start services at bootup. + + root# /sbin/service iptables stop +Flushing firewall rules: [ OK ] + Setting chains to policy ACCEPT: filter [ OK ] + Unloading iptables modules: [ OK ] + + + + + @@ -20054,8 +20220,18 @@ File_contents2=$(<$file2) # Bash permits this also. - Unlike backticks, the $(...) form of - command substitution permits nesting. + The $(...) form of command + substitution permits nesting. + + + In fact, nesting with backticks is also possible, + but only by escaping the inner backticks, as John + Default points out. + word_count=` wc -w \`ls -l | awk '{print $9}'\` ` + + + + word_count=$( wc -w $(ls -l | awk '{print $9}') ) @@ -26269,13 +26445,24 @@ fi Where to Go For Help The author - will usually, if not too busy (and in a good mood), - answer general scripting questions. However, if - you have a problem getting a specific script to - work, you would be well advised to post to the E-mails from certain spam-infested TLDs + (61, 202, 211, 218, 220, etc.) will be trapped by spam + filters and deleted unread. If your ISP is located on + one of these, please use a Webmail account to contact the + author. + However, if you have a problem getting a specific script + to work, you might be well advised to post to the comp.os.unix.shell Usenet newsgroup. + If you need assistance with a schoolwork assignment, read + the pertinent sections of this and other reference works. + Do your best to solve the problem using your own wits and + resources. Please do not waste the author's time. You will get + neither help nor sympathy. + @@ -26441,28 +26628,29 @@ fi errors and other corrections. Special thanks! Others contributing scripts, making helpful suggestions, and - pointing out errors were Gabor Kiss, Leopold Toetsch, - Peter Tillier, Marcus Berglof, Tony Richardson, Nick Drage - (script ideas!), Rich Bartell, Jess Thrysoee, Adam Lazur, Bram - Moolenaar, Baris Cicek, Greg Keraunen, Keith Matthews, Sandro - Magi, Albert Reiner, Dim Segebart, Rory Winston, Lee Bigelow, - Wayne Pollock, jipe, bojster, - nyal, Hobbit, Ender, - Little Monster (Alexis), Mark, - Emilio Conti, Ian. D. Allen, Arun Giridhar, Dennis Leeuw, Dan - Jacobson, Aurelio Marinho Jargas, Edward Scholtz, Jean Helou, - Chris Martin, Lee Maschmeyer, Bruno Haible, Wilbert Berendsen, - Sebastien Godard, Bjön Eriksson, John MacDonald, Joshua - Tschida, Troy Engel, Manfred Schwarb, Amit Singh, Bill Gradwohl, - David Lombard, Jason Parker, Steve Parker, Bruce W. Clare, William + pointing out errors were Gabor Kiss, Leopold Toetsch, Peter + Tillier, Marcus Berglof, Tony Richardson, Nick Drage (script + ideas!), Rich Bartell, Jess Thrysoee, Adam Lazur, Bram Moolenaar, + Baris Cicek, Greg Keraunen, Keith Matthews, Sandro Magi, Albert + Reiner, Dim Segebart, Rory Winston, Lee Bigelow, Wayne Pollock, + jipe, bojster, nyal, + Hobbit, Ender, Little + Monster (Alexis), Mark, Emilio Conti, + Ian. D. Allen, Arun Giridhar, Dennis Leeuw, Dan Jacobson, Aurelio + Marinho Jargas, Edward Scholtz, Jean Helou, Chris Martin, + Lee Maschmeyer, Bruno Haible, Wilbert Berendsen, Sebastien + Godard, Bjön Eriksson, John MacDonald, Joshua Tschida, + Troy Engel, Manfred Schwarb, Amit Singh, Bill Gradwohl, David + Lombard, Jason Parker, Steve Parker, Bruce W. Clare, William Park, Vernia Damiano, Mihai Maties, Jeremy Impson, Ken Fuchs, Frank Wang, Sylvain Fourmanoit, Matthew Walker, Kenny Stauffer, Filip Moritz, Andrzej Stefanski, Daniel Albers, Stefano Palmeri, - Nils Radtke, Jeroen Domburg, Alfredo Pironti, Phil Braham, Bruno - de Oliveira Schneider, Stefano Falsetto, Chris Morgan, Walter - Dnes, Linc Fessenden, Michael Iatrou, Pharis Monalo, Jesse Gough, - Fabian Kreutz, Harald Koenig, Mariusz Gniazdowski, Tedman Eng, - and David Lawyer (himself an author of four HOWTOs). + Nils Radtke, Jeroen Domburg, Alfredo Pironti, Phil Braham, + Bruno de Oliveira Schneider, Stefano Falsetto, Chris Morgan, + Walter Dnes, Linc Fessenden, Michael Iatrou, Pharis Monalo, + Jesse Gough, Fabian Kreutz, Mark Norman, Harald Koenig, Peter + Knowles, Mariusz Gniazdowski, Tedman Eng, and David Lawyer + (himself an author of four HOWTOs). My gratitude to Chet Ramey and Brian Fox for writing Bash, @@ -27214,6 +27402,17 @@ fi full-fledged debugger for Bash. + + + + + + Of historical interest are Colin Needham's original + International Movie Database (IMDB) reader polling + scripts, which nicely illustrate the use of awk for string parsing. --- @@ -29092,9 +29291,18 @@ exit 0 /etc + Et cetera. Systemwide configuration scripts. - + + Of particular interest are the + /etc/fstab (filesystem table), + /etc/mtab + (mounted filesystem table), and the /etc/inittab + files. + + /etc/rc.d @@ -30535,6 +30743,10 @@ Smith,Tom,404 Polk Ave.,Los Angeles,CA,90003,(213) 879-5612 For some ideas, see and . + Optional: Write a script that searches through a batch of + e-mail messages and deletes the spam according to specified + filters. + @@ -30590,10 +30802,10 @@ Smith,Tom,404 Polk Ave.,Los Angeles,CA,90003,(213) 879-5612 write a script that emulates a 64-bit shift register as an array. Implement functions to load the register, - shift left, and shift - right. Finally, write a function that - interprets the register contents as eight 8-bit ASCII - characters. + shift left, shift + right, and rotate + it. Finally, write a function that interprets the register + contents as eight 8-bit ASCII characters. @@ -30707,7 +30919,7 @@ Smith,Tom,404 Polk Ave.,Los Angeles,CA,90003,(213) 879-5612 might consider the number of letters in a word and the vowel-consonant mix. - A strict interpretation of the Gunning Fog index does + A strict interpretation of the Gunning fog index does not count compound words and proper nouns as difficult words, but this would enormously complicate the script. @@ -30771,7 +30983,7 @@ already used. To encrypt, separate the plaintext message into digrams (2-letter groups). If a group has two identical letters, delete the second, and form a new group. If there is a single letter left over at the end, -insert a "null" character, typically an "X". +insert a "null" character, typically an "X." THIS IS A TOP SECRET MESSAGE @@ -30818,7 +31030,7 @@ and #2 (move in opposite direction for substitution). Under case #3, just take the remaining two corners of the rectangle. -Helen Fouche Gaines' classic work, "Elementary Cryptanalysis" (1939), gives a +Helen Fouche Gaines' classic work, ELEMENTARY CRYPTANALYSIS (1939), gives a fairly detailed rundown on the Playfair Cipher and its solution methods. @@ -30863,10 +31075,10 @@ fairly detailed rundown on the Playfair Cipher and its solution methods. This document first appeared as a HOWTO in the late spring - of 2000. Since then, it has gone through many updates and - revisions. This book could not have been written without the - assistance of the Linux community, and especially of the volunteers of - the Linux Documentation Project. + of 2000. Since then, it has gone through quite a number of + updates and revisions. This book could not have been written + without the assistance of the Linux community, and especially + of the volunteers of the Linux Documentation Project. @@ -31045,6 +31257,11 @@ fairly detailed rundown on the Playfair Cipher and its solution methods.28 Aug 2005 POKEBERRY release: Bugfixes, some materials added. + + + 23 Oct 2005 + WHORTLEBERRY release: Bugfixes, some materials added. + @@ -31056,7 +31273,7 @@ fairly detailed rundown on the Playfair Cipher and its solution methods.Mirror Sites + url="http://personal.riverusers.com/~thegrendel/abs-guide-3.7.tar.bz2"> The latest update of this document, as an archived tarball including both the SGML source and rendered HTML, may @@ -31117,7 +31334,7 @@ fairly detailed rundown on the Playfair Cipher and its solution methods. 2000, by Mendel Cooper. The author also asserts copyright on all previous versions of this document. - This blanket copyright recognizes and protects the rights of the + This blanket copyright recognizes and protects the rights of all contributors to this document. @@ -31204,6 +31421,7 @@ B. Distribution of the work or derivative of the work in any standard Linux is a trademark registered to Linus Torvalds. Unix and UNIX are trademarks registered to the Open Group. MS Windows is a trademark registered to the Microsoft Corp. + Solaris is a trademark registered to Sun, Inc. OSX is a trademark registered to Apple, Inc. Yahoo is a trademark registered to Yahoo, Inc. Pentium is a trademark registered to Intel, Inc. diff --git a/LDP/guide/docbook/abs-guide/ex21.sh b/LDP/guide/docbook/abs-guide/ex21.sh index 75e2b453..fdab41ba 100644 --- a/LDP/guide/docbook/abs-guide/ex21.sh +++ b/LDP/guide/docbook/abs-guide/ex21.sh @@ -31,6 +31,8 @@ echo "Random number less than $RANGE --- $number" echo + + # If you need a random integer greater than a lower bound, #+ then set up a test to discard all numbers below that. @@ -44,6 +46,12 @@ done echo "Random number greater than $FLOOR --- $number" echo + # Let's examine a simple alternative to the above loop, namely + # let "number = $RANDOM + $FLOOR" + # That would eliminate the while-loop and run faster. + # But, there might be a problem with that. What is it? + + # Combine above two techniques to retrieve random number between two limits. number=0 #initialize diff --git a/LDP/guide/docbook/abs-guide/fc4upd.sh b/LDP/guide/docbook/abs-guide/fc4upd.sh new file mode 100644 index 00000000..fea2bbd3 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/fc4upd.sh @@ -0,0 +1,214 @@ +#!/bin/bash +# fc4upd.sh + +# Script author: Frank Wang. +# Slight stylistic modifications by ABS Guide author. +# Used in ABS Guide with permission. + + +# Download Fedora 4 update from mirror site using rsync. +# Only download latest package if multiple versions exist, +#+ to save space. + +URL=rsync://distro.ibiblio.org/fedora-linux-core/updates/ +# URL=rsync://ftp.kddilabs.jp/fedora/core/updates/ +# URL=rsync://rsync.planetmirror.com/fedora-linux-core/updates/ + +DEST=${1:-/var/www/html/fedora/updates/} +LOG=/tmp/repo-update-$(/bin/date +%Y-%m-%d).txt +PID_FILE=/var/run/${0##*/}.pid + +E_RETURN=65 # Something unexpected happened. + + +# General rsync options +# -r: recursive download +# -t: reserve time +# -v: verbose + +OPTS="-rtv --delete-excluded --delete-after --partial" + +# rsync include pattern +# Leading slash causes absolute path name match. +INCLUDE=( + "/4/i386/kde-i18n-Chinese*" +# ^ ^ +# Quoting is necessary to prevent globbing. +) + + +# rsync exclude pattern +# Temporarily comment out unwanted pkgs using "#" . . . +EXCLUDE=( + /1 + /2 + /3 + /testing + /4/SRPMS + /4/ppc + /4/x86_64 + /4/i386/debug + "/4/i386/kde-i18n-*" + "/4/i386/openoffice.org-langpack-*" + "/4/i386/*i586.rpm" + "/4/i386/GFS-*" + "/4/i386/cman-*" + "/4/i386/dlm-*" + "/4/i386/gnbd-*" + "/4/i386/kernel-smp*" +# "/4/i386/kernel-xen*" +# "/4/i386/xen-*" +) + + +init () { + # Let pipe command return possible rsync error, e.g., stalled network. + set -o pipefail + + TMP=${TMPDIR:-/tmp}/${0##*/}.$$ # Store refined download list. + trap "{ + rm -f $TMP 2>/dev/null + }" EXIT # Clear temporary file on exit. +} + + +check_pid () { +# Check if process exists. + if [ -s "$PID_FILE" ]; then + echo "PID file exists. Checking ..." + PID=$(/bin/egrep -o "^[[:digit:]]+" $PID_FILE) + if /bin/ps --pid $PID &>/dev/null; then + echo "Process $PID found. ${0##*/} seems to be running!" + /usr/bin/logger -t ${0##*/} \ + "Process $PID found. ${0##*/} seems to be running!" + exit $E_RETURN + fi + echo "Process $PID not found. Start new process . . ." + fi +} + + +# Set overall file update range starting from root or $URL, +#+ according to above patterns. +set_range () { + include= + exclude= + for p in "${INCLUDE[@]}"; do + include="$include --include \"$p\"" + done + + for p in "${EXCLUDE[@]}"; do + exclude="$exclude --exclude \"$p\"" + done +} + + +# Retrieve and refine rsync update list. +get_list () { + echo $$ > $PID_FILE || { + echo "Can't write to pid file $PID_FILE" + exit $E_RETURN + } + + echo -n "Retrieving and refining update list . . ." + + # Retrieve list -- 'eval' is needed to run rsync as a single command. + # $3 and $4 is the date and time of file creation. + # $5 is the full package name. + previous= + pre_file= + pre_date=0 + eval /bin/nice /usr/bin/rsync \ + -r $include $exclude $URL | \ + egrep '^dr.x|^-r' | \ + awk '{print $3, $4, $5}' | \ + sort -k3 | \ + { while read line; do + # Get seconds since epoch, to filter out obsolete pkgs. + cur_date=$(date -d "$(echo $line | awk '{print $1, $2}')" +%s) + # echo $cur_date + + # Get file name. + cur_file=$(echo $line | awk '{print $3}') + # echo $cur_file + + # Get rpm pkg name from file name, if possible. + if [[ $cur_file == *rpm ]]; then + pkg_name=$(echo $cur_file | sed -r -e \ + 's/(^([^_-]+[_-])+)[[:digit:]]+\..*[_-].*$/\1/') + else + pkg_name= + fi + # echo $pkg_name + + if [ -z "$pkg_name" ]; then # If not a rpm file, + echo $cur_file >> $TMP #+ then append to download list. + elif [ "$pkg_name" != "$previous" ]; then # A new pkg found. + echo $pre_file >> $TMP # Output latest file. + previous=$pkg_name # Save current. + pre_date=$cur_date + pre_file=$cur_file + elif [ "$cur_date" -gt "$pre_date" ]; then # If same pkg, but newer, + pre_date=$cur_date #+ then update latest pointer. + pre_file=$cur_file + fi + done + echo $pre_file >> $TMP # TMP contains ALL + #+ of refined list now. + # echo "subshell=$BASH_SUBSHELL" + + } # Bracket required here to let final "echo $pre_file >> $TMP" + # Remained in the same subshell ( 1 ) with the entire loop. + + RET=$? # Get return code of the pipe command. + + [ "$RET" -ne 0 ] && { + echo "List retrieving failed with code $RET" + exit $E_RETURN + } + + echo "done"; echo +} + +# Real rsync download part. +get_file () { + + echo "Downloading..." + /bin/nice /usr/bin/rsync \ + $OPTS \ + --filter "merge,+/ $TMP" \ + --exclude '*' \ + $URL $DEST \ + | /usr/bin/tee $LOG + + RET=$? + + # --filter merge,+/ is crucial for the intention. + # + modifier means include and / means absolute path. + # Then sorted list in $TMP will contain ascending dir name and + #+ prevent the following --exclude '*' from "shortcutting the circuit." + + echo "Done" + + rm -f $PID_FILE 2>/dev/null + + return $RET +} + +# ------- +# Main +init +check_pid +set_range +get_list +get_file +RET=$? +# ------- + +if [ "$RET" -eq 0 ]; then + /usr/bin/logger -t ${0##*/} "Fedora update mirrored successfully." +else + /usr/bin/logger -t ${0##*/} "Fedora update mirrored with failure code: $RET" +fi + +exit $RET diff --git a/LDP/guide/docbook/abs-guide/gcd.sh b/LDP/guide/docbook/abs-guide/gcd.sh index 27d4d7f9..31556fa8 100644 --- a/LDP/guide/docbook/abs-guide/gcd.sh +++ b/LDP/guide/docbook/abs-guide/gcd.sh @@ -32,14 +32,13 @@ fi gcd () { - # Arbitrary assignment. - dividend=$1 # It does not matter - divisor=$2 #+ which of the two is larger. - # Why? + dividend=$1 # Arbitrary assignment. + divisor=$2 #+ It doesn't matter which of the two is larger. + # Why not? remainder=1 # If uninitialized variable used in loop, #+ it results in an error message - #+ on first pass through loop. + #+ on the first pass through loop. until [ "$remainder" -eq 0 ] do diff --git a/LDP/guide/docbook/abs-guide/idelete.sh b/LDP/guide/docbook/abs-guide/idelete.sh index b48b0719..64e5dfa5 100644 --- a/LDP/guide/docbook/abs-guide/idelete.sh +++ b/LDP/guide/docbook/abs-guide/idelete.sh @@ -23,9 +23,9 @@ 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. -# ---------------------------------------------------------------------- +# ----------------------------------------------------------------------- +# Every file has an inode, a record that holds its physical address info. +# ----------------------------------------------------------------------- echo; echo -n "Are you absolutely sure you want to delete \"$1\" (y/n)? " # The '-v' option to 'rm' also asks this. diff --git a/LDP/guide/docbook/abs-guide/list-glob.sh b/LDP/guide/docbook/abs-guide/list-glob.sh index 81d324a7..24ced560 100644 --- a/LDP/guide/docbook/abs-guide/list-glob.sh +++ b/LDP/guide/docbook/abs-guide/list-glob.sh @@ -1,18 +1,20 @@ #!/bin/bash -# list-glob.sh: Generating [list] in a for-loop using "globbing". +# list-glob.sh: Generating [list] in a for-loop, using "globbing" echo for file in * +# ^ Bash performs filename expansion +#+ on expressions that globbing recognizes. do ls -l "$file" # Lists all files in $PWD (current directory). - # Recall that the wild card character "*" matches every filename, - # however, in "globbing", it doesn't match dot-files. + # Recall that the wild card character "*" matches every filename, + #+ however, in "globbing," it doesn't match dot-files. - # If the pattern matches no file, it is expanded to itself. - # To prevent this, set the nullglob option - # (shopt -s nullglob). - # Thanks, S.C. + # If the pattern matches no file, it is expanded to itself. + # To prevent this, set the nullglob option + #+ (shopt -s nullglob). + # Thanks, S.C. done echo; echo diff --git a/LDP/guide/docbook/abs-guide/monthlypmt.sh b/LDP/guide/docbook/abs-guide/monthlypmt.sh index 1833be02..5420f78e 100644 --- a/LDP/guide/docbook/abs-guide/monthlypmt.sh +++ b/LDP/guide/docbook/abs-guide/monthlypmt.sh @@ -40,6 +40,8 @@ read term bottom=$(echo "scale=9; $bottom+$bot" | bc) # bottom = $(($bottom + $bot")) done +# ==================================================================== + # -------------------------------------------------------------------- # Rick Boivie pointed out a more efficient implementation #+ of the above loop, which decreases computation time by 2/3. @@ -61,8 +63,18 @@ read term # done # echo 'bottom' # } | bc` # Embeds a 'for loop' within command substitution. +# -------------------------------------------------------------------------- +# On the other hand, Frank Wang suggests: +# bottom=$(echo "scale=9; ($interest_rate^$term-1)/($interest_rate-1)" | bc) + +# Because . . . +# The algorithm behind the loop +#+ is actually a sum of geometric proportion series. +# The sum formula is e0(1-q^n)/(1-q), +#+ where e0 is the first element and q=e(n+1)/e(n) +#+ and n is the number of elements. +# -------------------------------------------------------------------------- -# ==================================================================== # let "payment = $top/$bottom" payment=$(echo "scale=2; $top/$bottom" | bc) @@ -75,6 +87,7 @@ read term exit 0 + # Exercises: # 1) Filter input to permit commas in principal amount. # 2) Filter input to permit interest to be entered as percent or decimal. diff --git a/LDP/guide/docbook/abs-guide/multiple-processes.sh b/LDP/guide/docbook/abs-guide/multiple-processes.sh index 0fc83615..420edc8a 100644 --- a/LDP/guide/docbook/abs-guide/multiple-processes.sh +++ b/LDP/guide/docbook/abs-guide/multiple-processes.sh @@ -69,8 +69,15 @@ exit 0 # I ran it with limit = 500 and after the first few hundred iterations, #+ one of the concurrent threads disappeared! # Not sure if this is collisions from trap signals or something else. +# Once the trap is received, there's a brief moment while executing the +#+ trap handler but before the next trap is set. During this time, it may +#+ be possible to miss a trap signal, thus miss spawning a child process. + # No doubt someone may spot the bug and will be writing #+ . . . in the future. + + + # ===================================================================== # diff --git a/LDP/guide/docbook/abs-guide/read-redir.sh b/LDP/guide/docbook/abs-guide/read-redir.sh index 705e5a55..f838c1d6 100644 --- a/LDP/guide/docbook/abs-guide/read-redir.sh +++ b/LDP/guide/docbook/abs-guide/read-redir.sh @@ -34,7 +34,7 @@ while read name passwd uid gid fullname ignore do echo "$name ($fullname)" done </etc/passwd # I/O redirection. -IFS=$OIFS # Restore originial $IFS. +IFS=$OIFS # Restore original $IFS. # This code snippet also by Heiner Steven. diff --git a/LDP/guide/docbook/abs-guide/wf.sh b/LDP/guide/docbook/abs-guide/wf.sh index f83a213b..2e18a256 100644 --- a/LDP/guide/docbook/abs-guide/wf.sh +++ b/LDP/guide/docbook/abs-guide/wf.sh @@ -43,6 +43,11 @@ sed -e 's/\.//g' -e 's/\,//g' -e 's/ /\ #+ least significant column #+ (word or string, optionally case-insensitive) #+ and last on the most significant column (frequency)." +# +# As Frank Wang explains, the above is equivalent to +#+ . . . | sort | uniq -c | sort +0 -nr +#+ and the following also works: +#+ . . . | sort | uniq -c | sort -k1nr -k ######################################################## exit 0