From 8f64a41334f57a93b095266f2d40abfddd812343 Mon Sep 17 00:00:00 2001 From: gferg <> Date: Wed, 4 Apr 2012 22:51:18 +0000 Subject: [PATCH] updated --- LDP/guide/docbook/abs-guide/Change.log | 89 +++++- LDP/guide/docbook/abs-guide/INDEX00.sgml | 17 +- LDP/guide/docbook/abs-guide/README | 2 +- LDP/guide/docbook/abs-guide/abs-guide.sgml | 272 +++++++++++++----- LDP/guide/docbook/abs-guide/agram.sh | 2 +- LDP/guide/docbook/abs-guide/agram2.sh | 10 +- LDP/guide/docbook/abs-guide/backlight.sh | 62 ++++ LDP/guide/docbook/abs-guide/behead.sh | 6 +- LDP/guide/docbook/abs-guide/cw-solver.sh | 2 +- LDP/guide/docbook/abs-guide/dev-tcp.sh | 2 +- LDP/guide/docbook/abs-guide/ex10.sh | 4 +- LDP/guide/docbook/abs-guide/ex12.sh | 2 +- LDP/guide/docbook/abs-guide/ex14.sh | 2 +- LDP/guide/docbook/abs-guide/ex19.sh | 2 +- LDP/guide/docbook/abs-guide/ex2.sh | 2 +- LDP/guide/docbook/abs-guide/ex35.sh | 6 +- LDP/guide/docbook/abs-guide/ex56.sh | 2 +- LDP/guide/docbook/abs-guide/ex68.sh | 2 +- LDP/guide/docbook/abs-guide/fibo.sh | 2 +- LDP/guide/docbook/abs-guide/fifteen.sh | 4 +- LDP/guide/docbook/abs-guide/for-loopc.sh | 6 +- LDP/guide/docbook/abs-guide/from.sh | 4 +- .../docbook/abs-guide/func-cmdlinearg.sh | 4 +- LDP/guide/docbook/abs-guide/gen0 | 2 +- LDP/guide/docbook/abs-guide/getopt-simple.sh | 2 +- LDP/guide/docbook/abs-guide/gronsfeld.bash | 18 +- LDP/guide/docbook/abs-guide/is_spammer.bash | 2 +- LDP/guide/docbook/abs-guide/lookup.sh | 4 + .../docbook/abs-guide/missing-keyword.sh | 4 + LDP/guide/docbook/abs-guide/pw.sh | 2 +- LDP/guide/docbook/abs-guide/qky.sh | 27 +- LDP/guide/docbook/abs-guide/ramdisk.sh | 4 +- LDP/guide/docbook/abs-guide/rand-string.sh | 3 +- LDP/guide/docbook/abs-guide/random-test.sh | 8 +- LDP/guide/docbook/abs-guide/rot13.sh | 9 +- LDP/guide/docbook/abs-guide/sam.sh | 8 +- LDP/guide/docbook/abs-guide/spam-lookup.sh | 2 +- LDP/guide/docbook/abs-guide/t-out.sh | 4 +- LDP/guide/docbook/abs-guide/wf2.sh | 2 +- LDP/guide/docbook/abs-guide/wipedir.sh | 2 +- LDP/guide/docbook/abs-guide/words.data | 4 +- LDP/guide/docbook/abs-guide/wr-ps.bash | 4 +- LDP/guide/docbook/abs-guide/wstrings.sh | 2 +- 43 files changed, 454 insertions(+), 165 deletions(-) create mode 100644 LDP/guide/docbook/abs-guide/backlight.sh diff --git a/LDP/guide/docbook/abs-guide/Change.log b/LDP/guide/docbook/abs-guide/Change.log index eceaef93..ad4a2a6e 100644 --- a/LDP/guide/docbook/abs-guide/Change.log +++ b/LDP/guide/docbook/abs-guide/Change.log @@ -3,19 +3,89 @@ Release History The latest version of this file is available on-line at - http://http://bash.webofcrafts.net/Change.log + http://http://bash.deta.in/Change.log ================================================================== - Current version = 6.4 - Dated 08/30/11 + Current version = 6.5 + Dated 04/05/12 - http://bash.webofcrafts.net/abs-guide-latest.tar.bz2 - http://bash.webofcrafts.net/abs-guide.pdf + http://bash.deta.in/abs-guide-latest.tar.bz2 + http://bash.deta.in/abs-guide.pdf -------------------------------------------------------------------- - News: Version 6.4 released! + News: Version 6.5 released! ==================================================================== +Version 6.5, Vortexberry* release +05 April 2012 + + * No such thing, but there most certainly ought to be. + Imagine a genetically engineered berry containing metallic + fibers which could be used as filaments in incandescent lightbulbs. + + + +1) In "Bash, versions 2, 3, and 4" chapter, + In the Version 3.0 section, + At the Extended Brace Expansion discussion, + Added "eval" workaround for parameterization. + (Thank you, Emiliano G.!) + +2) In "Special Characters" chapter, + Fixed missing parenthesis at "pipe" entry. + (Thank you, Adamas, for pointing this out.) + +3) In "Internal Commands and Builtins" chapter, + At "let" entry, + added Jeff Gorak's correction to the return value "anomaly." + +4) At references to "trinary" operator, noted the somewhat more common + "ternary" usage. + +5) In "External Commands" chapter: + In "Miscellaneous Commands" section, + At "dd" entry, added creating bootable flash drives example. + +6) In "System and Administrative Commands" chapter, + In "Filesystem" subsection, + Added "mkdosfs" entry. + In "Miscellaneous" subsection, + Added "xrandr" entry and "backlight.sh" example script. + +7) In the Bibliography, added "AuctionGallery" entry. + +8) Appendix D, + Revision of exit code 2 entry. + Added an example for exit code 126. + +9) Fix quoting error in "Special Variables" Table in Reference Cards, + per Matthew Stanfield (Thank you!). + +10) In "Complex Commands" section of "External Commands" Chapter: + Added as comment Rich's alternative awk syntax + to the month_length () example. + +11) Used (with permission) code snippets from YongYe's "Tetris Game" + script in "Internal Commands" and "List Constructs" chapters. + Also added an entry for this in the "Bibliography" appendix. + The URLS for YongYe's script are: + http://bash.deta.in/Tetris_Game.sh + http://bbs.chinaunix.net/thread-3614425-1-1.html + +12) In "Miscellany" chapter, + In "Shell Scripting Under Windows" section, + added reference to UNWIN, as pointed out by Greg Alheid. + +13) New cover for pdf version! + +14) Fixups on scripts. + [Thanks go to Darren Birkett, Chris Manson, yongye, and others.] + +15) Domain shift! Changed webofcrafts.net links to deta.in. + + + + Version 6.4, Vortexberry* release 30 August 2011 @@ -178,7 +248,7 @@ Version 6.3, Swozzleberry* release 14) In the "Miscellany" chapter: Fixed the URL on Moshe Jacobson's utility (changed it to point to the "ansi-color" script). Then, decided to rehost Jacobson's original - source code on webofcrafts.net. + source code on webofcrafts.net (Update: deta.in). (Thank you, qun-ying, for pointing out the broken URL.) 15) In the "Variables Revisited" chapter: @@ -2512,7 +2582,8 @@ chapter: Added usage example at "last" entry. 17) In "/dev" section of "/dev and /proc" chapter: - Changed reference URL from slashdot.org to net.cn (a known spam ISP). + Changed reference URL from slashdot.org to news-15.net + (a known spam ISP). Added to footnote about mounting a USB flash drive. 18) In "Gotchas" chapter: @@ -2725,7 +2796,7 @@ Loganberry release, 10/03/04 (Thanks, bojster.) 18) In "Time/Date Commands" section of "External Commands" chapter: - At "date" entry, dded discussion of more options. + At "date" entry, added discussion of more options. 19) In "Miscellaneous Commands" section of "External Commands" Chapter: Added comment to "blot-out.sh" example script noting that it may not diff --git a/LDP/guide/docbook/abs-guide/INDEX00.sgml b/LDP/guide/docbook/abs-guide/INDEX00.sgml index 3b5c3b0d..9b047737 100644 --- a/LDP/guide/docbook/abs-guide/INDEX00.sgml +++ b/LDP/guide/docbook/abs-guide/INDEX00.sgml @@ -927,6 +927,8 @@ * * * + Backlight, setting the + brightness Backquotes, used in command substitution @@ -1012,12 +1014,17 @@ redirecting output of a a code block + Bootable flash drives, creating + Brace expansion Extended, {a..z} + Parameterizing + With increment and zero-padding (new feature in Bash, version @@ -1890,7 +1897,11 @@ * * * - Keywords + Keywords + + error, + if missing + kill, terminate a process by process ID @@ -2573,7 +2584,7 @@ linkend="globbingref">globbing In a C-style - Trinary operator + Trinary (ternary) operator @@ -3393,7 +3404,7 @@ specifying an action upon receipt of a signal - Trinary operator, + Trinary (ternary) operator, C-style, var>10?88:99 diff --git a/LDP/guide/docbook/abs-guide/README b/LDP/guide/docbook/abs-guide/README index cac33d85..92e83560 100644 --- a/LDP/guide/docbook/abs-guide/README +++ b/LDP/guide/docbook/abs-guide/README @@ -104,7 +104,7 @@ qky.sh line 87 line 113 (The unaltered, executable script can be downloaded. - See: http://bash.webofcrafts.net/qky.README.html) + See: http://bash.deta.in/qky.README.html) maned.sh line 6 (comment) diff --git a/LDP/guide/docbook/abs-guide/abs-guide.sgml b/LDP/guide/docbook/abs-guide/abs-guide.sgml index e2c71f1a..6a9a471d 100644 --- a/LDP/guide/docbook/abs-guide/abs-guide.sgml +++ b/LDP/guide/docbook/abs-guide/abs-guide.sgml @@ -382,6 +382,7 @@ + @@ -407,21 +408,14 @@ - 6.4 - 30 Aug 2011 + 6.5 + 05 Apr 2012 978-1-4357-5219-1 - - 6.2 - 17 Mar 2010 - mc - 'ROWANBERRY' release - - 6.3 27 Apr 2011 @@ -436,6 +430,13 @@ 'VORTEXBERRY' release + + 6.5 + 05 Apr 2012 + mc + 'TUNGSTENBERRY' release + + @@ -523,7 +524,7 @@ linkend="builtinref">builtins, features internal to the shell. - to learn. The syntax is simple and straightforward, similar to + to learn. The syntax is simple -- even austere -- similar to that of invoking and chaining together utilities at the command line, and there are only a few rules governing their use. Most short scripts work right the first time, and @@ -656,8 +657,9 @@ An acronym is a word formed by pasting together the initial letters of the - words in a tongue-tripping phrase. This is a harmful - and subversive practice that surely deserves severe punishment. + words into a tongue-tripping phrase. This is a pernicious + and subversive practice that surely deserves appropriately + severe punishment. for Bourne-Again shell and a pun on Stephen Bourne's @@ -680,7 +682,7 @@ What follows is a tutorial on shell scripting. It relies heavily on examples to illustrate various features of the shell. - The example scripts work -- they've been tested, insofar as was + The example scripts work -- they've been tested, insofar as possible -- and some of them are even useful in real life. The reader can play with the actual working code of the examples in the source archive (scriptname.sh or @@ -690,15 +692,15 @@ that are Bourne shell compliant generally take a name with a .sh extension. System scripts, such as those found in /etc/rc.d, - do not conform to this nomenclature. + do not necessarily conform to this nomenclature. give them execute permission (chmod u+rx scriptname), then run them to see what happens. Should the source + url="http://bash.deta.in/abs-guide-latest.tar.bz2">source archive not be available, then cut-and-paste from the HTML or - pdf + pdf rendered versions. Be aware that some of the scripts presented here introduce features before they are explained, and this may require the reader to temporarily skip ahead for enlightenment. @@ -1788,7 +1790,11 @@ fi In a double-parentheses construct, the ? can serve as an element of a C-style - trinary operator. + trinary operator. + This is more commonly known + as the ternary + operator. + condition?result-if-true:result-if-false @@ -2665,7 +2671,7 @@ fi pipe - Passes the output (stdout + Passes the output (stdout) of a previous command to the input (stdin) of the next one, or to the shell. This is a method of chaining commands @@ -6144,8 +6150,9 @@ then echo "The value of \"a\" lies somewhere between 0 and 5." fi - demonstrates a nested - if/then condition test. + and + demonstrate nested if/then condition + tests. @@ -11030,7 +11037,7 @@ case "$1" in * ) FILENAME=$1;; # Otherwise, $1. esac - Here is an more straightforward example of + Here is a more straightforward example of command-line parameter handling: #! /bin/bash @@ -11856,6 +11863,7 @@ let "z += 3" # Quotes permit the use of spaces in variable assignment. mimencode mkbootdisk mkdir + mkdosfs mke2fs mkfifo mkisofs @@ -12043,6 +12051,7 @@ let "z += 3" # Quotes permit the use of spaces in variable assignment. whois write xargs + xrandr yacc yes zcat @@ -12693,7 +12702,7 @@ while read f; do The let command can, - in certain contexts, return an anomalous exit status. # Evgeniy Ivanov points out: @@ -12716,8 +12725,11 @@ echo $? # 0 let var=0 echo $? # 1 # The command was successful, so why isn't $?=0 ??? - # Anomaly! - + +# However, as Jeff Gorak points out, +#+ this is part of the design spec for 'let' . . . +# "If the last ARG evaluates to 0, let returns 1; +# let returns 0 otherwise." ['help let'] @@ -12801,6 +12813,16 @@ eval eval echo $a # d &rot14; + Here is another example of using eval + to evaluate a complex expression, + this one from YongYe's Tetris + game script. + + + eval ${1}+=\"${x} ${y} \" + + uses eval to convert array elements into a command @@ -12812,6 +12834,10 @@ eval eval echo $a # d eval var=\$$var + The eval command can + be used to parameterize + brace expansion. + The eval command can be @@ -18528,7 +18554,7 @@ echo "tempfile name = $tempfile" # Creates a file of that name in the current working directory #+ with 600 file permissions. # A "umask 177" is therefore unnecessary, -#+ but it's good programming practice anyhow. +#+ but it's good programming practice nevertheless. @@ -18882,7 +18908,7 @@ echo "tempfile name = $tempfile" script. - HNAME=nastyspammer.com + HNAME=news-15.net # Notorious spammer. # HNAME=$HOST # Debug: test for localhost. count=2 # Send only two pings. @@ -20545,6 +20571,12 @@ dd if=$filename conv=ucase > $filename.uppercase dd if=/dev/fd0 of=/home/bozo/projects/floppy.img + Likewise, dd + can create bootable flash drives. + dd if=image.iso of=/dev/sdb + See + Marlow's Bootable USB Keys site. + Other applications of dd include @@ -23497,6 +23529,23 @@ mount -o loop /dev/loop0 /mnt # Mount it. + + + mkdosfs + + mkdosfs + + + command + mkdosfs + + + Create a DOS FAT + filesystem. + + + + tune2fs @@ -24453,6 +24502,28 @@ print "even when I don't know where to find Perl.\n"; + + xrandr + + xrandr + + + command + xrandr + + + Command-line tool for manipulating the root window + of the screen. + + + <firstterm>Backlight</firstterm>: changes + the brightness of the (laptop) screen backlight + &backlight; + + + + + rdist @@ -25987,7 +26058,7 @@ done <<< $(echo ${ArrayVar[*]}) 2>&1 | [command(s)] bad_command 2>&1 | awk '{print $5}' # found # Sends stderr through a pipe. - # |& was added to Bash 4 as an abbreviation for 2>&. + # |& was added to Bash 4 as an abbreviation for 2>&1 |. i>&j # Redirects file descriptor i to j. @@ -27366,6 +27437,12 @@ echo "$monthD" | awk '{ print $'"${1}"' }' # Tricky. # Template for passing a parameter to embedded awk script: # $'"${script_parameter}"' +# Here's a slightly simpler awk construct: +# echo $monthD | awk -v month=$1 '{print $(month)}' +# Uses the -v awk option, which assigns a variable value +#+ prior to execution of the awk program block. +# Thank you, Rich. + # Needs error checking for correct parameter range (1-12) #+ and for February in leap year. } @@ -27862,6 +27939,19 @@ drwxr-xr-x 40 bozo bozo 2048 Feb 6 14:04 .. false is the last one to execute). + An interesting use of a two-condition and + list from YongYe's Tetris + game script: + + + equation() + +{ # core algorithm used for doubling and halving the coordinates + [[ ${cdx} ]] && ((y=cy+(ccy-cdy)${2}2)) + eval ${1}+=\"${x} ${y} \" +} + @@ -27901,6 +27991,8 @@ drwxr-xr-x 40 bozo bozo 2048 Feb 6 14:04 .. execute). This is obviously the inverse of the and list. + + Using <firstterm>or lists</firstterm> in combination with an <firstterm>and list</firstterm> @@ -31046,7 +31138,7 @@ test "$city" \< Paris && echo "Yes, Paris is greater than $city" Alister's ansi-color utility (based on Moshe + url="http://bash.deta.in/color-1.1.tar.gz">Moshe Jacobson's color utility considerably simplifies using ANSI escape sequences. It substitutes a clean and logical syntax for the clumsy constructs just discussed. @@ -32054,6 +32146,11 @@ echo "User entered: "$answer"" Mortice Kern Associates add shell scripting capabilities to Windows. + Another alternative is + UNWIN, written by David Korn of AT&T, of Korn Shell fame. + In 2006, Microsoft released the Windows Powershell, which contains limited Bash-like command-line scripting @@ -32179,11 +32276,23 @@ echo {{a..c},{1..3}} # a b c 1 2 3 # The "comma operator" splices together strings. - +# ########## ######### ############ ########### ######### ############### # Unfortunately, brace expansion does not lend itself to parameterization. var1=1 var2=5 -echo {$var1..$var2} # {1..5} +echo {$var1..$var2} # {1..5} + + +# Yet, as Emiliano G. points out, using "eval" overcomes this limitation. + +start=0 +end=10 +for index in $(eval echo {$start..$end}) +do + echo -n "$index " # 0 1 2 3 4 5 6 7 8 9 10 +done + +echo @@ -33112,12 +33221,14 @@ echo Those who can, do. Those who can't . . . get an MCSE. This book is somewhat of a departure from his other major work, - + HOW-2 Meet Women: The Shy Man's Guide to Relationships. He has also written the Software-Building - HOWTO. Of late, he has been trying his (heavy) hand at - short fiction. + HOWTO. Of late, he has been trying his + (heavy) hand at short fiction and has at least one Instructable + to his (dis)credit. A Linux user since 1995 (Slackware 2.2, kernel 1.2.1), the author has emitted a few @@ -33130,13 +33241,13 @@ echo Scrabble® adjudicator, the yawl word gaming list package, and the Quacky + url="http://bash.deta.in/qky.README.html">Quacky anagramming gaming package. He got off to a rather shaky start in the computer game -- programming FORTRAN IV on a CDC 3800 (on paper coding pads, no less) -- and is not the least bit nostalgic for those days. - Living in a secluded community with wife and orange + Living in an out-of-the-way community with wife and orange tabby, he cherishes human frailty, especially his own. Sometimes it seems as if he has spent his entire life flouting conventional wisdom and defying the @@ -33578,9 +33689,6 @@ echo the basic concepts of shell scripting. In fact, this book was the ABS Guide author's first exposure to UNIX shell scripting, lo these many years ago. - For more information, see the Kochan-Wood - website. * @@ -33741,7 +33849,7 @@ echo 0-691-02356-5 The classic tutorial on problem-solving methods - (i.e., algorithms), with special emphasis on how to teach them. + (algorithms), with special emphasis on how to teach them. * @@ -33806,7 +33914,7 @@ echo book is part of the awk documentation, and printed copies of the latest version are available from O'Reilly and Associates. - This book has served as an inspiration for the author + This book served as an inspiration for the author of the ABS Guide. * @@ -33825,9 +33933,9 @@ echo 1-56592-054-6 - This well-written book contains some excellent pointers on shell - scripting in general. - * + This well-written book contains + some excellent pointers on shell scripting in general. + * @@ -33887,7 +33995,7 @@ echo 2004 1-59327-012-7 - Just what the title promises . . . + Pretty much what the title promises . . . * @@ -34112,6 +34220,14 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc + + + YongYe's wonderfully complex Tetris game + script. + + + Mark Komarinski's AuctionGallery, + an application for eBay power sellers coded + in Bash. + + + Of historical interest are Colin Needham's @@ -34350,7 +34475,7 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc Contributed Scripts These scripts, while not fitting into the text of this document, do - illustrate some interesting shell programming techniques. They are useful, + illustrate some interesting shell programming techniques. Some are useful, too. Have fun analyzing and running them. @@ -34837,7 +34962,7 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc * Must be quoted, otherwise it defaults to - $@. + $@. @@ -35425,7 +35550,7 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc C-style trinary operation + linkend="cstrinary"> ternary operation @@ -35898,13 +36023,13 @@ awk '{print $0}' $filename Misuse of shell builtins (according to Bash documentation) empty_function() {} - Seldom seen, usually defaults to exit - code 1 + Missing keyword + or command Command invoked cannot execute - + /dev/null Permission problem or command is not an executable @@ -35931,7 +36056,7 @@ awk '{print $0}' $filename Script terminated by Control-C - + Ctl-C Control-C is fatal error signal 2, (130 = 128 + 2, see above) @@ -38994,6 +39119,11 @@ thegrendel@theriver.com 30 Aug 2011 VORTEXBERRY release: Minor update. + + + 05 Apr 2012 + TUNGSTENBERRY release: Minor update. + @@ -39010,31 +39140,32 @@ thegrendel@theriver.com bzip2-ed tarball including both the SGML source and rendered HTML, may be downloaded from the author's + url="http://bash.deta.in/abs-guide-latest.tar.bz2">author's home site). A - pdf version is also available. + url="http://bash.deta.in/abs-guide.pdf"> + pdf version is also available (mirror site). There is likewise an + url="http://bash.deta.in/abs-guide.epub"> epub version, courtesy of Craig Barnes. The change + url="http://bash.deta.in/Change.log">change log gives a detailed revision history. The ABS Guide even has - its own freshmeat.net page to keep - track of major updates, user comments, and popularity ratings - for the project. + url="http://freecode.com/projects/advancedbashscriptingguide/"> + its own freshmeat.net/freecode page + to keep track of major updates, user comments, and popularity + ratings for the project. The legacy hosting site for this document is the Linux Documentation Project, which maintains many other Guides and HOWTOs as well. Many thanks to Ronny Bangsund for donating server space to host + url="http://bash.deta.in/">server space to host this project. @@ -39212,17 +39343,18 @@ distributors, or any of its associated software or documentation.Russian, Czech, Chinese, - Indonesian, Dutch, and Romanian translations are also available or - in progress. If you wish to translate this document into another - language, please feel free to do so, subject to the terms stated - above. The author wishes to be notified of such efforts. + Indonesian, Dutch, Romanian, and Bulgarian translations are also + available or in progress. If you wish to translate this document + into another language, please feel free to do so, subject to + the terms stated above. The author wishes to be notified of such + efforts. - For those readers who absolutely insist on making - a donation to the author, you may contribute a small amount - via Paypal to my e-mail address, + For those generous readers who insist + on making a donation to the author, you may contribute a small + amount via Paypal to my e-mail address, thegrendel.abs@gmail.com. Note that this - is emphatically not necessary, or even - recommended. This book is a free and freely distributed document + is not necessary. + This book is a free and freely distributed document for the use and enjoyment of the Linux community. diff --git a/LDP/guide/docbook/abs-guide/agram.sh b/LDP/guide/docbook/abs-guide/agram.sh index 237dd4ea..b52cfef1 100644 --- a/LDP/guide/docbook/abs-guide/agram.sh +++ b/LDP/guide/docbook/abs-guide/agram.sh @@ -16,7 +16,7 @@ grep -v 'ed$' # no past tense verbs # Uses "anagram" utility #+ that is part of the author's "yawl" word list package. # http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz -# http://bash.webofcrafts.net/yawl-0.3.2.tar.gz +# http://bash.deta.in/yawl-0.3.2.tar.gz exit 0 # End of code. diff --git a/LDP/guide/docbook/abs-guide/agram2.sh b/LDP/guide/docbook/abs-guide/agram2.sh index d15c300c..7d38cef7 100644 --- a/LDP/guide/docbook/abs-guide/agram2.sh +++ b/LDP/guide/docbook/abs-guide/agram2.sh @@ -5,10 +5,10 @@ # Uses "anagram" utility #+ that is part of the author's "yawl" word list package. # http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz -# http://bash.webofcrafts.net/yawl-0.3.2.tar.gz +# http://bash.deta.in/yawl-0.3.2.tar.gz -E_NOARGS=66 -E_BADARG=67 +E_NOARGS=86 +E_BADARG=87 MINLEN=7 if [ -z "$1" ] @@ -38,9 +38,9 @@ echo ${Anagrams[1]} # Second anagram. # echo "${Anagrams[*]}" # To list all the anagrams in a single line . . . -# Look ahead to the "Arrays" chapter for enlightenment on +# Look ahead to the Arrays chapter for enlightenment on #+ what's going on here. -# See also the agram.sh script for an example of anagram finding. +# See also the agram.sh script for an exercise in anagram finding. exit $? diff --git a/LDP/guide/docbook/abs-guide/backlight.sh b/LDP/guide/docbook/abs-guide/backlight.sh new file mode 100644 index 00000000..12832dd1 --- /dev/null +++ b/LDP/guide/docbook/abs-guide/backlight.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# backlight.sh +# reldate 02dec2011 + +# A bug in Fedora Core 16 messes up the keyboard backlight controls. +# This script is a quick-n-dirty workaround, essentially a shell wrapper +#+ for xrandr. It gives more control than on-screen sliders and widgets. + +OUTPUT=$(xrandr | grep LV | awk '{print $1}') # Get display name! +INCR=.05 # For finer-grained control, set INCR to .03 or .02. + +old_brightness=$(xrandr --verbose | grep rightness | awk '{ print $2 }') + + +if [ -z "$1" ] +then + bright=1 # If no command-line arg, set brightness to 1.0 (default). + + else + if [ "$1" = "+" ] + then + bright=$(echo "scale=2; $old_brightness + $INCR" | bc) # +.05 + + else + if [ "$1" = "-" ] + then + bright=$(echo "scale=2; $old_brightness - $INCR" | bc) # -.05 + + else + if [ "$1" = "#" ] # Echoes current brightness; does not change it. + then + bright=$old_brightness + + else + if [[ "$1" = "h" || "$1" = "H" ]] + then + echo + echo "Usage:" + echo "$0 [No args] Sets/resets brightness to default (1.0)." + echo "$0 + Increments brightness by 0.5." + echo "$0 - Decrements brightness by 0.5." + echo "$0 # Echoes current brightness without changing it." + echo "$0 N (number) Sets brightness to N (useful range .7 - 1.2)." + echo "$0 h [H] Echoes this help message." + echo "$0 any-other Gives xrandr usage message." + + bright=$old_brightness + + else + bright="$1" + + fi + fi + fi + fi +fi + + +xrandr --output "$OUTPUT" --brightness "$bright" # See xrandr manpage. +echo "Current brightness = $bright" + +exit $? diff --git a/LDP/guide/docbook/abs-guide/behead.sh b/LDP/guide/docbook/abs-guide/behead.sh index 02fb2d85..e8023107 100644 --- a/LDP/guide/docbook/abs-guide/behead.sh +++ b/LDP/guide/docbook/abs-guide/behead.sh @@ -1,7 +1,7 @@ #! /bin/sh -# Strips off the header from a mail/News message i.e. till the first -# empty line. -# Author: Mark Moraes, University of Toronto +# Strips off the header from a mail/News message i.e. till the first +#+ empty line. +# Author: Mark Moraes, University of Toronto # ==> These comments added by author of this document. diff --git a/LDP/guide/docbook/abs-guide/cw-solver.sh b/LDP/guide/docbook/abs-guide/cw-solver.sh index 5da6a770..166316b7 100644 --- a/LDP/guide/docbook/abs-guide/cw-solver.sh +++ b/LDP/guide/docbook/abs-guide/cw-solver.sh @@ -20,7 +20,7 @@ DICT=/usr/share/dict/word.lst #+ download the author's "yawl" word list package. # http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz # or -# http://bash.webofcrafts.net/yawl-0.3.2.tar.gz +# http://bash.deta.in/yawl-0.3.2.tar.gz if [ -z "$1" ] # If no word pattern specified diff --git a/LDP/guide/docbook/abs-guide/dev-tcp.sh b/LDP/guide/docbook/abs-guide/dev-tcp.sh index 2377fe2c..844eb02e 100644 --- a/LDP/guide/docbook/abs-guide/dev-tcp.sh +++ b/LDP/guide/docbook/abs-guide/dev-tcp.sh @@ -4,7 +4,7 @@ # Script by Troy Engel. # Used with permission. -TCP_HOST=www.dns-diy.com # A known spam-friendly ISP. +TCP_HOST=news-15.net # A known spam-friendly ISP. TCP_PORT=80 # Port 80 is http. # Try to connect. (Somewhat similar to a 'ping' . . .) diff --git a/LDP/guide/docbook/abs-guide/ex10.sh b/LDP/guide/docbook/abs-guide/ex10.sh index bfadd790..3d959b4b 100644 --- a/LDP/guide/docbook/abs-guide/ex10.sh +++ b/LDP/guide/docbook/abs-guide/ex10.sh @@ -1,7 +1,7 @@ #!/bin/bash # Tip: -# If you're unsure of how a certain condition would evaluate, +# If you're unsure how a certain condition might evaluate, #+ test it in an if-test. echo @@ -95,7 +95,7 @@ echo # When is "false" true? echo "Testing \"false\"" -if [ "false" ] # It seems that "false" is just a string. +if [ "false" ] # It seems that "false" is just a string ... then echo "\"false\" is true." #+ and it tests true. else diff --git a/LDP/guide/docbook/abs-guide/ex12.sh b/LDP/guide/docbook/abs-guide/ex12.sh index 7ec8c86c..42d709fd 100644 --- a/LDP/guide/docbook/abs-guide/ex12.sh +++ b/LDP/guide/docbook/abs-guide/ex12.sh @@ -3,7 +3,7 @@ filename=sys.log cat /dev/null > $filename; echo "Creating / cleaning out file." -# Creates file if it does not already exist, +# Creates the file if it does not already exist, #+ and truncates it to zero length if it does. # : > filename and > filename also work. diff --git a/LDP/guide/docbook/abs-guide/ex14.sh b/LDP/guide/docbook/abs-guide/ex14.sh index 635a3a8e..836e49d7 100644 --- a/LDP/guide/docbook/abs-guide/ex14.sh +++ b/LDP/guide/docbook/abs-guide/ex14.sh @@ -13,7 +13,7 @@ then echo "Usage: `basename $0` filename" >&2 # Error message to stderr. exit $E_NOARGS - # Returns 65 as exit status of script (error code). + # Returns 85 as exit status of script (error code). fi filename=$1 diff --git a/LDP/guide/docbook/abs-guide/ex19.sh b/LDP/guide/docbook/abs-guide/ex19.sh index b8095ed9..fdf6208b 100644 --- a/LDP/guide/docbook/abs-guide/ex19.sh +++ b/LDP/guide/docbook/abs-guide/ex19.sh @@ -4,7 +4,7 @@ # Name this script something like shft.sh, #+ and invoke it with some parameters. #+ For example: -# sh shft.sh a b c def 23 Skidoo +# sh shft.sh a b c def 83 barndoor until [ -z "$1" ] # Until all parameters used up . . . do diff --git a/LDP/guide/docbook/abs-guide/ex2.sh b/LDP/guide/docbook/abs-guide/ex2.sh index 89a59945..554d5a38 100644 --- a/LDP/guide/docbook/abs-guide/ex2.sh +++ b/LDP/guide/docbook/abs-guide/ex2.sh @@ -68,7 +68,7 @@ fi # Doublecheck if in right directory before messing with log file. tail -n $lines messages > mesg.temp # Save last section of message log file. -mv mesg.temp messages # Becomes new log directory. +mv mesg.temp messages # Rename it as system log file. # cat /dev/null > messages diff --git a/LDP/guide/docbook/abs-guide/ex35.sh b/LDP/guide/docbook/abs-guide/ex35.sh index 739e027b..01fa51d7 100644 --- a/LDP/guide/docbook/abs-guide/ex35.sh +++ b/LDP/guide/docbook/abs-guide/ex35.sh @@ -1,9 +1,9 @@ #!/bin/bash -a=/home/bozo/daily-journal.txt +address=/home/bozo/daily-journal.txt -echo "Basename of /home/bozo/daily-journal.txt = `basename $a`" -echo "Dirname of /home/bozo/daily-journal.txt = `dirname $a`" +echo "Basename of /home/bozo/daily-journal.txt = `basename $address`" +echo "Dirname of /home/bozo/daily-journal.txt = `dirname $address`" echo echo "My own home is `basename ~/`." # `basename ~` also works. echo "The home of my home is `dirname ~/`." # `dirname ~` also works. diff --git a/LDP/guide/docbook/abs-guide/ex56.sh b/LDP/guide/docbook/abs-guide/ex56.sh index 20d581e3..97c94418 100644 --- a/LDP/guide/docbook/abs-guide/ex56.sh +++ b/LDP/guide/docbook/abs-guide/ex56.sh @@ -4,7 +4,7 @@ echo "This precedes the embedded Perl script within \"$0\"." echo "===============================================================" -perl -e 'print "This is an embedded Perl script.\n";' +perl -e 'print "This line prints from an embedded Perl script.\n";' # Like sed, Perl also uses the "-e" option. echo "===============================================================" diff --git a/LDP/guide/docbook/abs-guide/ex68.sh b/LDP/guide/docbook/abs-guide/ex68.sh index 4046cd09..d377045a 100644 --- a/LDP/guide/docbook/abs-guide/ex68.sh +++ b/LDP/guide/docbook/abs-guide/ex68.sh @@ -120,7 +120,7 @@ Primes=( '' $(seq $UPPER_LIMIT) ) i=1 until (( ( i += 1 ) > SPLIT )) # Need check only halfway. do - if [[ -n $Primes[i] ]] + if [[ -n ${Primes[i]} ]] then t=$i until (( ( t += i ) > UPPER_LIMIT )) diff --git a/LDP/guide/docbook/abs-guide/fibo.sh b/LDP/guide/docbook/abs-guide/fibo.sh index e52f1fd9..c7361d28 100644 --- a/LDP/guide/docbook/abs-guide/fibo.sh +++ b/LDP/guide/docbook/abs-guide/fibo.sh @@ -3,7 +3,7 @@ # Author: M. Cooper # License: GPL3 -# --------------------------------- +# ----------algorithm-------------- # Fibo(0) = 0 # Fibo(1) = 1 # else diff --git a/LDP/guide/docbook/abs-guide/fifteen.sh b/LDP/guide/docbook/abs-guide/fifteen.sh index 9b2fad42..2d20687f 100644 --- a/LDP/guide/docbook/abs-guide/fifteen.sh +++ b/LDP/guide/docbook/abs-guide/fifteen.sh @@ -139,7 +139,7 @@ function Solved } -################### MAIN () ######################## +################### MAIN () #######################{ moves=0 Jumble @@ -165,7 +165,7 @@ PrintPuzzle echo; echo "BRAVO!"; echo exit 0 -#################################################### +###################################################} # Exercise: # -------- diff --git a/LDP/guide/docbook/abs-guide/for-loopc.sh b/LDP/guide/docbook/abs-guide/for-loopc.sh index 2ae5e74c..93f9d516 100644 --- a/LDP/guide/docbook/abs-guide/for-loopc.sh +++ b/LDP/guide/docbook/abs-guide/for-loopc.sh @@ -38,10 +38,10 @@ echo; echo LIMIT=10 -for ((a=1; a <= LIMIT ; a++)) # Double parentheses, and "LIMIT" with no "$". +for ((a=1; a <= LIMIT ; a++)) # Double parentheses, and naked "LIMIT" do echo -n "$a " -done # A construct borrowed from 'ksh93'. +done # A construct borrowed from ksh93. echo; echo @@ -50,7 +50,7 @@ echo; echo # Let's use the C "comma operator" to increment two variables simultaneously. for ((a=1, b=1; a <= LIMIT ; a++, b++)) -do # The comma chains together operations. +do # The comma concatenates operations. echo -n "$a-$b " done diff --git a/LDP/guide/docbook/abs-guide/from.sh b/LDP/guide/docbook/abs-guide/from.sh index 5a7cee28..ae0a424a 100644 --- a/LDP/guide/docbook/abs-guide/from.sh +++ b/LDP/guide/docbook/abs-guide/from.sh @@ -1,13 +1,13 @@ #!/bin/bash # from.sh -# Emulates the useful "from" utility in Solaris, BSD, etc. +# Emulates the useful 'from' utility in Solaris, BSD, etc. # Echoes the "From" header line in all messages #+ in your e-mail directory. MAILDIR=~/mail/* # No quoting of variable. Why? -# Maybe check if exists $MAILDIR . . . if [ -d $MAILDIR ] . . . +# Maybe check if-exists $MAILDIR: if [ -d $MAILDIR ] . . . GREP_OPTS="-H -A 5 --color" # Show file, plus extra context lines #+ and display "From" in color. TARGETSTR="^From" # "From" at beginning of line. diff --git a/LDP/guide/docbook/abs-guide/func-cmdlinearg.sh b/LDP/guide/docbook/abs-guide/func-cmdlinearg.sh index cdc62d49..62249295 100644 --- a/LDP/guide/docbook/abs-guide/func-cmdlinearg.sh +++ b/LDP/guide/docbook/abs-guide/func-cmdlinearg.sh @@ -7,8 +7,8 @@ func () { -echo "$1" -} +echo "$1" # Echoes first arg passed to the function. +} # Does a command-line arg qualify? echo "First call to function: no arg passed." echo "See if command-line arg is seen." diff --git a/LDP/guide/docbook/abs-guide/gen0 b/LDP/guide/docbook/abs-guide/gen0 index 9e52111c..160837af 100644 --- a/LDP/guide/docbook/abs-guide/gen0 +++ b/LDP/guide/docbook/abs-guide/gen0 @@ -9,7 +9,7 @@ # # Lines beginning with a '#' are comments, and the script ignores them. __.__..___ -___._.____ +__.._.____ ____.___.. _._______. ____._____ diff --git a/LDP/guide/docbook/abs-guide/getopt-simple.sh b/LDP/guide/docbook/abs-guide/getopt-simple.sh index 868dc692..632e9f05 100644 --- a/LDP/guide/docbook/abs-guide/getopt-simple.sh +++ b/LDP/guide/docbook/abs-guide/getopt-simple.sh @@ -29,7 +29,7 @@ getopt_simple $* echo "test is '$test'" echo "test2 is '$test2'" -exit 0 # See also, UseGetOpt.sh, a modified versio of this script. +exit 0 # See also, UseGetOpt.sh, a modified version of this script. --- diff --git a/LDP/guide/docbook/abs-guide/gronsfeld.bash b/LDP/guide/docbook/abs-guide/gronsfeld.bash index 91285f85..a30a36d2 100644 --- a/LDP/guide/docbook/abs-guide/gronsfeld.bash +++ b/LDP/guide/docbook/abs-guide/gronsfeld.bash @@ -7,14 +7,14 @@ # This is an implementation of the Gronsfeld Cipher. # It's essentially a stripped-down variant of the #+ polyalphabetic Vigenère Tableau, but with only 10 alphabets. -# The classic Gronsfeld has a numerical sequence as the key word, -#+ but instead we substitute a letter string, for ease of use. +# The classic Gronsfeld has a numeric sequence as the key word, +#+ but here we substitute a letter string, for ease of use. # Allegedly, this cipher was invented by the eponymous Count Gronsfeld #+ in the 17th Century. It was at one time considered to be unbreakable. # Note that this is ###not### a secure cipher by modern standards. # Global Variables # -Enc_suffix="29378" # Encrypted text output with this 5-digit suffix. +Enc_suffix="29379" # Encrypted text output with this 5-digit suffix. # This functions as a decryption flag, #+ and when used to generate passwords adds security. Default_key="gronsfeldk" @@ -31,7 +31,7 @@ wraplen=26 # Wrap around if past end of alphabet. dflag= # Decrypt flag (set if $Enc_suffix present). E_NOARGS=76 # Missing command-line args? DEBUG=77 # Debugging flag. -declare -a offsets # This array holds the numerical shift values for +declare -a offsets # This array holds the numeric shift values for #+ encryption/decryption. ########Keychain######### @@ -64,10 +64,10 @@ do # Shift forward to encrypt. test $(( $idx % $GROUPLEN)) = 0 && echo -n " " # Groups of 5 letters. # Comment out above line for output as a string without whitespace, - # for example, if using the script as a password generator. + #+ for example, if using the script as a password generator. fi - ((off1--)) # Normalize. + ((off1--)) # Normalize. Why is this necessary? if [ $off1 -lt 0 ] then # Catch negative indices. @@ -93,7 +93,7 @@ done # int main () { -# Check if command-line args. +# Check for command-line args. if [ -z "$1" ] then echo "Usage: $0 TEXT TO ENCODE/DECODE" @@ -140,8 +140,8 @@ exit $? # } End-of-script # This script can function as a password generator, #+ with several minor mods, see above. # That would allow an easy-to-remember password, even the word -#+ "password" itself, which encrypts to vrgfotvo29378 +#+ "password" itself, which encrypts to vrgfotvo29379 #+ a fairly secure password not susceptible to a dictionary attack. # Or, you could use your own name (surely that's easy to remember!). -# For example, Bozo Bozeman encrypts to hfnbttdppkt29378. +# For example, Bozo Bozeman encrypts to hfnbttdppkt29379. # ************************************************************** # diff --git a/LDP/guide/docbook/abs-guide/is_spammer.bash b/LDP/guide/docbook/abs-guide/is_spammer.bash index f6464b64..2a547442 100644 --- a/LDP/guide/docbook/abs-guide/is_spammer.bash +++ b/LDP/guide/docbook/abs-guide/is_spammer.bash @@ -102,7 +102,7 @@ Optional environment variables Additional documentation Download the archived set of scripts explaining and illustrating the function contained within this script. - http://bash.webofcrafts.net/mszick_clf.tar.bz2 + http://bash.deta.in/mszick_clf.tar.bz2 Study notes diff --git a/LDP/guide/docbook/abs-guide/lookup.sh b/LDP/guide/docbook/abs-guide/lookup.sh index 40d1da4a..0c2a788d 100644 --- a/LDP/guide/docbook/abs-guide/lookup.sh +++ b/LDP/guide/docbook/abs-guide/lookup.sh @@ -3,12 +3,16 @@ file=words.data # Data file from which to read words to test. +echo +echo "Testing file $file" echo while [ "$word" != end ] # Last word in data file. do # ^^^ read word # From data file, because of redirection at end of loop. look $word > /dev/null # Don't want to display lines in dictionary file. + # Searches for words in the file /usr/share/dict/words + #+ (usually a link to linux.words). lookup=$? # Exit status of 'look' command. if [ "$lookup" -eq 0 ] diff --git a/LDP/guide/docbook/abs-guide/missing-keyword.sh b/LDP/guide/docbook/abs-guide/missing-keyword.sh index cd9f90e7..237d983e 100644 --- a/LDP/guide/docbook/abs-guide/missing-keyword.sh +++ b/LDP/guide/docbook/abs-guide/missing-keyword.sh @@ -7,3 +7,7 @@ do # done # Required keyword 'done' commented out in line 7. exit 0 + +# === # + +echo $? # 2 diff --git a/LDP/guide/docbook/abs-guide/pw.sh b/LDP/guide/docbook/abs-guide/pw.sh index 62a7cb47..3e4642c6 100644 --- a/LDP/guide/docbook/abs-guide/pw.sh +++ b/LDP/guide/docbook/abs-guide/pw.sh @@ -1,5 +1,5 @@ #!/bin/bash -# May need to be invoked with #!/bin/bash2 on older machines. +# # # Random password generator for Bash 2.x + #+ by Antek Sawicki <tenox@tenox.tc>, diff --git a/LDP/guide/docbook/abs-guide/qky.sh b/LDP/guide/docbook/abs-guide/qky.sh index 52199bd7..68e4d8e2 100644 --- a/LDP/guide/docbook/abs-guide/qky.sh +++ b/LDP/guide/docbook/abs-guide/qky.sh @@ -13,7 +13,7 @@ WLIST=/usr/share/dict/word.lst # ^^^^^^^^ Word list file found here. # ASCII word list, one word per line, UNIX format. # A suggested list is the script author's "yawl" word list package. -# http://bash.webofcrafts.net/yawl-0.3.2.tar.gz +# http://bash.deta.in/yawl-0.3.2.tar.gz # or # http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz @@ -32,7 +32,7 @@ E_DUP=70 # Duplicate word error. TIMEOUT=10 # Time for word input. NVLET=10 # 10 letters for non-vulnerable. -VULET=13 # 13 letters for vulnerable (not yet implemented). +VULET=13 # 13 letters for vulnerable (not yet implemented!). declare -a Words declare -a Status @@ -70,7 +70,7 @@ but it is otherwise feature-complete. As the game begins, the player gets 10 letters. The object is to construct valid dictionary words -of at least 3-letter-length from the letterset. +of at least 3-letter length from the letterset. Each word-length category -- 3-letter, 4-letter, 5-letter, ... -- fills up with the fifth word entered, @@ -103,7 +103,7 @@ Category completion bonuses are: 6-letter words 800 7-letter words 2000 8-letter words 10000 -This is a simplification of the absurdly complicated Perquackey bonus +This is a simplification of the absurdly baroque Perquackey bonus scoring system. INSTRUCTION2 @@ -117,7 +117,7 @@ Hitting just ENTER for a word entry ends the game. Individual word entry is timed to a maximum of 10 seconds. *** Timing out on an entry ends the game. *** -Other than that, the game is untimed. +Aside from that, the game is untimed. -------------------------------------------------- Game statistics are automatically saved to a file. @@ -277,7 +277,7 @@ get_word () } is_constructable () -{ # This was the most complex and difficult-to-write function. +{ # This is the most complex and difficult-to-write function. local -a local_LS=( "${LS[@]}" ) # Local copy of letter set. local is_found=0 local idx=0 @@ -305,7 +305,7 @@ is_constructable () is_valid () { # Surprisingly easy to check if word in dictionary ... - fgrep -qw "$1" "$WLIST" # ... thanks to 'grep' ... + fgrep -qw "$1" "$WLIST" # ... courtesy of 'grep' ... echo $? } @@ -354,7 +354,7 @@ check_word () return $NG fi - ### FIXME: Streamline the above code. + ### FIXME: Streamline the above code block. } @@ -394,7 +394,7 @@ play () { word="Start game" # Dummy word, to start ... - while [ "$word" ] # If player just hits return (blank word), + while [ "$word" ] # If player just hits return (null word), do #+ then game ends. echo "$word: "${Status[@]}"" echo -n "Last score: [${Score[0]}] TOTAL score: [${Score[1]}]: Next word: " @@ -414,7 +414,7 @@ play () done # Exit game. ### FIXME: The play () function calls too many other functions. - ### This is perilously close to "spaghetti code" ... + ### This verges on "spaghetti code" !!! } end_of_game () @@ -457,9 +457,10 @@ exit $? # 3) Improve the time-out ... maybe change to untimed entry, #+ but with a time limit for the overall round. # 4) An on-screen countdown timer would be nice. -# 5) Implement "vulnerable" mode of play. +# 5) Implement "vulnerable" mode of play for compatibility with classic +#+ version of the game. # 6) Improve save-to-file capability (and maybe make it optional). # 7) Fix bugs!!! -# Reference for more info: -# http://bash.webofcrafts.net/qky.README.html +# For more info, reference: +# http://bash.deta.in/qky.README.html diff --git a/LDP/guide/docbook/abs-guide/ramdisk.sh b/LDP/guide/docbook/abs-guide/ramdisk.sh index bd0b4a94..ec3c5f41 100644 --- a/LDP/guide/docbook/abs-guide/ramdisk.sh +++ b/LDP/guide/docbook/abs-guide/ramdisk.sh @@ -4,7 +4,7 @@ # A "ramdisk" is a segment of system RAM memory #+ which 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. +# Disadvantages: volatility, loss of data on reboot or powerdown, #+ less RAM available to system. # # Of what use is a ramdisk? @@ -15,7 +15,7 @@ E_NON_ROOT_USER=70 # Must run as root. ROOTUSER_NAME=root -MOUNTPT=/mnt/ramdisk +MOUNTPT=/mnt/ramdisk # Create with mkdir /mnt/ramdisk. SIZE=2000 # 2K blocks (change as appropriate) BLOCKSIZE=1024 # 1K (1024 byte) block size DEVICE=/dev/ram0 # First ram device diff --git a/LDP/guide/docbook/abs-guide/rand-string.sh b/LDP/guide/docbook/abs-guide/rand-string.sh index 69c3466e..4602abf3 100644 --- a/LDP/guide/docbook/abs-guide/rand-string.sh +++ b/LDP/guide/docbook/abs-guide/rand-string.sh @@ -13,7 +13,8 @@ POS=2 # Starting from position 2 in the string. LEN=8 # Extract eight characters. str1=$( echo "$str0" | md5sum | md5sum ) -# Doubly scramble: ^^^^^^ ^^^^^^ +# Doubly scramble ^^^^^^ ^^^^^^ +#+ by piping and repiping to md5sum. randstring="${str1:$POS:$LEN}" # Can parameterize ^^^^ ^^^^ diff --git a/LDP/guide/docbook/abs-guide/random-test.sh b/LDP/guide/docbook/abs-guide/random-test.sh index a9d8878c..81047468 100644 --- a/LDP/guide/docbook/abs-guide/random-test.sh +++ b/LDP/guide/docbook/abs-guide/random-test.sh @@ -5,7 +5,7 @@ RANDOM=$$ # Reseed the random number generator using script process ID. PIPS=6 # A die has 6 pips. MAXTHROWS=600 # Increase this if you have nothing better to do with your time. -throw=0 # Throw count. +throw=0 # Number of times the dice have been cast. ones=0 # Must initialize counts to zero, twos=0 #+ since an uninitialized variable is null, not zero. @@ -30,8 +30,8 @@ update_count() { case "$1" in 0) let "ones += 1";; # Since die has no "zero", this corresponds to 1. - 1) let "twos += 1";; # And this to 2, etc. - 2) let "threes += 1";; + 1) let "twos += 1";; # And this to 2. + 2) let "threes += 1";; # Etc. 3) let "fours += 1";; 4) let "fives += 1";; 5) let "sixes += 1";; @@ -65,4 +65,4 @@ exit 0 # Exercise (easy): # --------------- # Rewrite this script to flip a coin 1000 times. -# Choices are "HEADS" and "TAILS". +# Choices are "HEADS" and "TAILS." diff --git a/LDP/guide/docbook/abs-guide/rot13.sh b/LDP/guide/docbook/abs-guide/rot13.sh index c29cf651..7f98e650 100644 --- a/LDP/guide/docbook/abs-guide/rot13.sh +++ b/LDP/guide/docbook/abs-guide/rot13.sh @@ -1,13 +1,14 @@ #!/bin/bash # rot13.sh: Classic rot13 algorithm, -# encryption that might fool a 3-year old. +# encryption that might fool a 3-year old +# for about 10 minutes. # Usage: ./rot13.sh filename # or ./rot13.sh <filename # or ./rot13.sh and supply keyboard input (stdin) -cat "$@" | tr 'a-zA-Z' 'n-za-mN-ZA-M' # "a" goes to "n", "b" to "o", etc. -# The 'cat "$@"' construction -#+ permits getting input either from stdin or from files. +cat "$@" | tr 'a-zA-Z' 'n-za-mN-ZA-M' # "a" goes to "n", "b" to "o" ... +# The cat "$@" construct +#+ permits input either from stdin or from files. exit 0 diff --git a/LDP/guide/docbook/abs-guide/sam.sh b/LDP/guide/docbook/abs-guide/sam.sh index ef05c042..d838513a 100644 --- a/LDP/guide/docbook/abs-guide/sam.sh +++ b/LDP/guide/docbook/abs-guide/sam.sh @@ -1,7 +1,7 @@ #!/bin/bash -# sam.sh, v. 01 +# sam.sh, v. .01a # Still Another Morse (code training script) -# With apologies to Sam (F.B.) Morse. +# With profuse apologies to Sam (F.B.) Morse. # Author: Mendel Cooper # License: GPL3 # Reldate: 05/25/11 @@ -13,7 +13,7 @@ # Get the wav files from the source tarball: -# http://bash.webofcrafts.net/abs-guide-latest.tar.bz2 +# http://bash.deta.in/abs-guide-latest.tar.bz2 DOT='soundfiles/dot.wav' DASH='soundfiles/dash.wav' # Maybe move soundfiles to /usr/local/sounds? @@ -64,7 +64,7 @@ morse[5]="dot; dot; dot; dot; dot" morse[6]="dash; dot; dot; dot; dot" morse[7]="dash; dash; dot; dot; dot" morse[8]="dash; dash; dash; dot; dot" -morse[8]="dash; dash; dash; dash; dot" +morse[9]="dash; dash; dash; dash; dot" # The following must be escaped or quoted. morse[?]="dot; dot; dash; dash; dot; dot" morse[.]="dot; dash; dot; dash; dot; dash" diff --git a/LDP/guide/docbook/abs-guide/spam-lookup.sh b/LDP/guide/docbook/abs-guide/spam-lookup.sh index 02559eac..ada71608 100644 --- a/LDP/guide/docbook/abs-guide/spam-lookup.sh +++ b/LDP/guide/docbook/abs-guide/spam-lookup.sh @@ -4,7 +4,7 @@ # Check for command-line arg. ARGCOUNT=1 -E_WRONGARGS=65 +E_WRONGARGS=85 if [ $# -ne "$ARGCOUNT" ] then echo "Usage: `basename $0` domain-name" diff --git a/LDP/guide/docbook/abs-guide/t-out.sh b/LDP/guide/docbook/abs-guide/t-out.sh index 6ad61cf7..b83a488c 100644 --- a/LDP/guide/docbook/abs-guide/t-out.sh +++ b/LDP/guide/docbook/abs-guide/t-out.sh @@ -1,5 +1,5 @@ #!/bin/bash -# t-out.sh +# t-out.sh [time-out] # Inspired by a suggestion from "syngin seven" (thanks). @@ -8,7 +8,7 @@ TIMELIMIT=4 # 4 seconds read -t $TIMELIMIT variable <&1 # ^^^ # In this instance, "<&1" is needed for Bash 1.x and 2.x, -# but unnecessary for Bash 3.x. +# but unnecessary for Bash 3+. echo diff --git a/LDP/guide/docbook/abs-guide/wf2.sh b/LDP/guide/docbook/abs-guide/wf2.sh index 5d76e2c2..07583a7b 100644 --- a/LDP/guide/docbook/abs-guide/wf2.sh +++ b/LDP/guide/docbook/abs-guide/wf2.sh @@ -17,7 +17,7 @@ then exit $E_BADARGS fi -if [ ! -f "$1" ] # Check if file exists. +if [ ! -f "$1" ] # Does file exist? then echo "File \"$1\" does not exist." exit $E_NOFILE diff --git a/LDP/guide/docbook/abs-guide/wipedir.sh b/LDP/guide/docbook/abs-guide/wipedir.sh index 3d599a85..5e5e3531 100644 --- a/LDP/guide/docbook/abs-guide/wipedir.sh +++ b/LDP/guide/docbook/abs-guide/wipedir.sh @@ -1,6 +1,6 @@ #!/bin/bash -E_WRONG_DIRECTORY=65 +E_WRONG_DIRECTORY=85 clear # Clear the screen. diff --git a/LDP/guide/docbook/abs-guide/words.data b/LDP/guide/docbook/abs-guide/words.data index 7c8540dc..330a8f25 100644 --- a/LDP/guide/docbook/abs-guide/words.data +++ b/LDP/guide/docbook/abs-guide/words.data @@ -4,7 +4,9 @@ syzygy orangutan doing madeupword -making +gargantuan +linux +nicrosoft nogood ziggurat what diff --git a/LDP/guide/docbook/abs-guide/wr-ps.bash b/LDP/guide/docbook/abs-guide/wr-ps.bash index d2fd8a3b..39be70f8 100644 --- a/LDP/guide/docbook/abs-guide/wr-ps.bash +++ b/LDP/guide/docbook/abs-guide/wr-ps.bash @@ -21,7 +21,7 @@ while read i do echo $i global=3D": Available outside the loop." - # ... because it does *not* run in a subshell. + # ... because it does NOT run in a subshell. done < <( echo "random input" ) # ^ ^ @@ -57,7 +57,7 @@ while read line do outloop[$index]="$line" ((index++)) - # It does *not* run in a subshell, so ... + # It does NOT run in a subshell, so ... done < <( cat $0 ) echo "OUTPUT = " echo ${outloop[*]} # ... the entire script echoes. diff --git a/LDP/guide/docbook/abs-guide/wstrings.sh b/LDP/guide/docbook/abs-guide/wstrings.sh index 305163d7..562a5bc6 100644 --- a/LDP/guide/docbook/abs-guide/wstrings.sh +++ b/LDP/guide/docbook/abs-guide/wstrings.sh @@ -31,7 +31,7 @@ WORDFILE=/usr/share/dict/linux.words # Dictionary file. # May specify a different word list file #+ of one-word-per-line format. # For example, the "yawl" word-list package, -# http://bash.webofcrafts.net/yawl-0.3.2.tar.gz +# http://bash.deta.in/yawl-0.3.2.tar.gz wlist=`strings "$1" | tr A-Z a-z | tr '[:space:]' Z | \