This commit is contained in:
gferg 2012-04-04 22:51:18 +00:00
parent 2e40af0c0f
commit 8f64a41334
43 changed files with 454 additions and 165 deletions

View File

@ -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

View File

@ -927,6 +927,8 @@
<para>* * *</para>
<para>Backlight, <link linkend="backlight">setting the
brightness</link></para>
<para><link linkend="backticksref">Backquotes</link>,
used in <link linkend="backquotesref">command
substitution</link></para>
@ -1012,12 +1014,17 @@
redirecting output of a a code block</para></listitem>
</itemizedlist></para>
<para><link linkend="bfs">Bootable flash drives</link>, creating</para>
<!-- ********************** -->
<para><link linkend="braceexpref">Brace expansion</link>
<itemizedlist>
<listitem><para><link
linkend="braceexpref33">Extended</link>,
<replaceable>{a..z}</replaceable></para></listitem>
<listitem><para><link
linkend="braceexpref3">Parameterizing</link>
</para></listitem>
<listitem><para>With <link
linkend="braceexpref4">increment and
zero-padding</link> (new feature in Bash, <link linkend="bash4ref">version
@ -1890,7 +1897,11 @@
<para>* * *</para>
<para><link linkend="keywordref">Keywords</link></para>
<para><link linkend="keywordref">Keywords</link>
<itemizedlist>
<listitem><para><link linkend="missingkeyword">error</link>,
if missing</para></listitem>
</itemizedlist></para>
<para><link linkend="killref">kill</link>,
terminate a process by <link linkend="processiddef">process ID</link>
@ -2573,7 +2584,7 @@
linkend="globbingref">globbing</link></para></listitem>
<listitem><para>In a
<link linkend="cstrinary"><firstterm>C</firstterm>-style
Trinary operator</link></para></listitem>
Trinary (ternary) operator</link></para></listitem>
</itemizedlist></para>
<!-- *************************************************************** -->
@ -3393,7 +3404,7 @@
specifying an action upon receipt of a <link
linkend="signald">signal</link></para>
<para><firstterm>Trinary</firstterm> operator,
<para><firstterm>Trinary (ternary)</firstterm> operator,
<firstterm>C</firstterm>-style,
<userinput>var>10?88:99</userinput>
<itemizedlist>

View File

@ -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)

View File

@ -382,6 +382,7 @@
<!ENTITY ipaddresses SYSTEM "ip-addresses.sh">
<!ENTITY stddev SYSTEM "sd.sh">
<!ENTITY samorse SYSTEM "sam.sh">
<!ENTITY backlight SYSTEM "backlight.sh">
<!ENTITY showallc SYSTEM "show-all-colors.sh">
<!ENTITY gronsfeld SYSTEM "gronsfeld.bash">
<!ENTITY gen0data SYSTEM "gen0">
@ -407,21 +408,14 @@
</author>
<releaseinfo>6.4</releaseinfo>
<pubdate>30 Aug 2011</pubdate>
<releaseinfo>6.5</releaseinfo>
<pubdate>05 Apr 2012</pubdate>
<isbn>978-1-4357-5219-1</isbn>
<revhistory>
<revision>
<revnumber>6.2</revnumber>
<date>17 Mar 2010</date>
<authorinitials>mc</authorinitials>
<revremark>'ROWANBERRY' release</revremark>
</revision>
<revision>
<revnumber>6.3</revnumber>
<date>27 Apr 2011</date>
@ -436,6 +430,13 @@
<revremark>'VORTEXBERRY' release</revremark>
</revision>
<revision>
<revnumber>6.5</revnumber>
<date>05 Apr 2012</date>
<authorinitials>mc</authorinitials>
<revremark>'TUNGSTENBERRY' release</revremark>
</revision>
</revhistory>
@ -523,7 +524,7 @@
linkend="builtinref">builtins</link>, features internal to the
shell.</para></footnote>
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 <quote>rules</quote> governing
their use. Most short scripts work right the first time, and
@ -656,8 +657,9 @@
<footnote><para>An <firstterm>acronym</firstterm>
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.
</para></footnote>
for <quote>Bourne-Again shell</quote> and a pun on Stephen Bourne's
@ -680,7 +682,7 @@
<para>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 (<filename>scriptname.sh</filename> or
@ -690,15 +692,15 @@
that are Bourne shell compliant generally take a name with a
<filename>.sh</filename> extension. System scripts, such as
those found in <filename class="directory">/etc/rc.d</filename>,
do not conform to this nomenclature.</para></footnote>
do not necessarily conform to this nomenclature.</para></footnote>
give them <firstterm>execute</firstterm> permission
(<userinput>chmod u+rx scriptname</userinput>),
then run them to see what happens. Should the <ulink
url="http://bash.webofcrafts.net/abs-guide-latest.tar.bz2">source
url="http://bash.deta.in/abs-guide-latest.tar.bz2">source
archive</ulink> not be available, then cut-and-paste from the <ulink
url="http://www.tldp.org/LDP/abs/abs-guide.html.tar.gz">HTML</ulink> or
<ulink url="http://bash.webofcrafts.net/abs-guide.pdf">pdf</ulink>
<ulink url="http://bash.deta.in/abs-guide.pdf">pdf</ulink>
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.</para>
@ -1788,7 +1790,11 @@ fi</programlisting>
<para>In a <link linkend="dblparens">double-parentheses
construct</link>, the <token>?</token>
can serve as an element of a C-style
<firstterm>trinary</firstterm> operator.</para>
<firstterm>trinary</firstterm> operator.
<footnote><para>This is more commonly known
as the <firstterm>ternary</firstterm>
operator.</para></footnote>
</para>
<para><varname>condition</varname><command>?</command><varname>result-if-true</varname><command>:</command><varname>result-if-false</varname></para>
@ -2665,7 +2671,7 @@ fi</programlisting></para>
<listitem>
<para><anchor id="piperef"></para>
<formalpara><title>pipe</title>
<para>Passes the output (<filename>stdout</filename>
<para>Passes the output (<filename>stdout</filename>)
of a previous command to the input
(<filename>stdin</filename>) 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</programlisting></para>
<para><xref linkend="cards"> demonstrates a nested
<replaceable>if/then</replaceable> condition test.</para>
<para><xref linkend="cards"> and <xref linkend="backlight">
demonstrate nested <replaceable>if/then</replaceable> condition
tests.</para>
</sect1> <!-- Nested if/then Tests -->
@ -11030,7 +11037,7 @@ case "$1" in
* ) FILENAME=$1;; # Otherwise, $1.
esac</programlisting></para>
<para>Here is an more straightforward example of
<para>Here is a more straightforward example of
command-line parameter handling:
<programlisting>#! /bin/bash
@ -11856,6 +11863,7 @@ let "z += 3" # Quotes permit the use of spaces in variable assignment.
<listitem><para><link linkend="mimencoderef">mimencode</link></para></listitem>
<listitem><para><link linkend="mkbootdiskref">mkbootdisk</link></para></listitem>
<listitem><para><link linkend="mkdirref">mkdir</link></para></listitem>
<listitem><para><link linkend="mkdosfsref">mkdosfs</link></para></listitem>
<listitem><para><link linkend="mke2fsref">mke2fs</link></para></listitem>
<listitem><para><link linkend="mkfiforef">mkfifo</link></para></listitem>
<listitem><para><link linkend="mkisofsref">mkisofs</link></para></listitem>
@ -12043,6 +12051,7 @@ let "z += 3" # Quotes permit the use of spaces in variable assignment.
<listitem><para><link linkend="whoisref">whois</link></para></listitem>
<listitem><para><link linkend="writeref">write</link></para></listitem>
<listitem><para><link linkend="xargsref">xargs</link></para></listitem>
<listitem><para><link linkend="xrandrref">xrandr</link></para></listitem>
<listitem><para><link linkend="yaccref">yacc</link></para></listitem>
<listitem><para><link linkend="yesref">yes</link></para></listitem>
<listitem><para><link linkend="zcatref">zcat</link></para></listitem>
@ -12693,7 +12702,7 @@ while read f; do
<caution>
<para>The <firstterm>let</firstterm> command can,
in certain contexts, return an anomalous <link
in certain contexts, return a surprising <link
linkend="exitstatusref">exit status</link>.</para>
<para><programlisting># 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!</programlisting></para>
</caution>
# 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']</programlisting></para></caution>
</listitem>
</varlistentry>
@ -12801,6 +12813,16 @@ eval eval echo $a # d
<programlisting>&rot14;</programlisting>
</example>
<para>Here is another example of using <firstterm>eval</firstterm>
to <emphasis>evaluate</emphasis> a complex expression,
this one from YongYe's <ulink
url="http://bash.deta.in/Tetris_Game.sh">Tetris
game script</ulink>.</para>
<para>
<programlisting>eval ${1}+=\"${x} ${y} \"</programlisting>
</para>
<para><xref linkend="samorse"> uses
<firstterm>eval</firstterm> to convert <link
linkend="arrayref">array</link> elements into a command
@ -12812,6 +12834,10 @@ eval eval echo $a # d
<programlisting>eval var=\$$var</programlisting>
</para>
<tip><para>The <firstterm>eval</firstterm> command can
be used to <link linkend="braceexpref3">parameterize
<firstterm>brace expansion</firstterm></link>.</para></tip>
<para><anchor id="evalrisk"></para>
<caution><para>The <command>eval</command> 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.</programlisting></para>
#+ but it's good programming practice nevertheless.</programlisting></para>
</listitem>
</varlistentry>
@ -18882,7 +18908,7 @@ echo "tempfile name = $tempfile"
script.</para>
<para><anchor id="ping0"></para>
<para><programlisting> HNAME=nastyspammer.com
<para><programlisting> 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
<userinput>dd if=/dev/fd0 of=/home/bozo/projects/floppy.img</userinput>
</para>
<para><anchor id="bfs">Likewise, <command>dd</command>
can create bootable flash drives.
<userinput>dd if=image.iso of=/dev/sdb</userinput>
See <ulink url="http://marlow.dk/site.php/tech/usbkeys">
Marlow's Bootable USB Keys site</ulink>.</para>
<para><anchor id="ddswap"></para>
<para>
Other applications of <command>dd</command> include
@ -23497,6 +23529,23 @@ mount -o loop /dev/loop0 /mnt # Mount it.
</listitem>
</varlistentry>
<varlistentry>
<term><anchor id="mkdosfsref"><command>mkdosfs</command></term>
<indexterm>
<primary>mkdosfs</primary>
</indexterm>
<indexterm>
<primary>command</primary>
<secondary>mkdosfs</secondary>
</indexterm>
<listitem>
<para>Create a DOS <firstterm>FAT</firstterm>
filesystem.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><anchor id="tune2fsref"><command>tune2fs</command></term>
<indexterm>
@ -24453,6 +24502,28 @@ print "even when I don't know where to find Perl.\n";
</listitem>
</varlistentry>
<varlistentry>
<term><anchor id="xrandrref"><command>xrandr</command></term>
<indexterm>
<primary>xrandr</primary>
</indexterm>
<indexterm>
<primary>command</primary>
<secondary>xrandr</secondary>
</indexterm>
<listitem>
<para>Command-line tool for manipulating the root window
of the screen.</para>
<example id="backlight">
<title><firstterm>Backlight</firstterm>: changes
the brightness of the (laptop) screen backlight</title>
<programlisting>&backlight;</programlisting>
</example>
</listitem>
</varlistentry>
<varlistentry>
<term><anchor id="rdistref"><command>rdist</command></term>
<indexterm>
@ -25987,7 +26058,7 @@ done <<< $(echo ${ArrayVar[*]})
2>&amp;1 | [command(s)]
bad_command 2>&1 | awk '{print $5}' # found
# Sends stderr through a pipe.
# |&amp was added to Bash 4 as an abbreviation for 2>&amp;.
# |&amp was added to Bash 4 as an abbreviation for 2>&amp;1 |.
i>&amp;j
# Redirects file descriptor <emphasis>i</emphasis> to <emphasis>j</emphasis>.
@ -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 ..
<replaceable>false</replaceable> is the last one to
execute).</para>
<para>An interesting use of a two-condition <firstterm>and
list</firstterm> from YongYe's <ulink
url="http://bash.deta.in/Tetris_Game.sh">Tetris
game script</ulink>:</para>
<para>
<programlisting>equation()
{ # core algorithm used for doubling and halving the coordinates
[[ ${cdx} ]] && ((y=cy+(ccy-cdy)${2}2))
eval ${1}+=\"${x} ${y} \"
}</programlisting>
</para>
<example id="ex64">
@ -27901,6 +27991,8 @@ drwxr-xr-x 40 bozo bozo 2048 Feb 6 14:04 ..
execute). This is obviously the inverse of the <quote>and
list</quote>.</para>
<example id="ex65">
<title>Using <firstterm>or lists</firstterm> in combination
with an <firstterm>and list</firstterm></title>
@ -31046,7 +31138,7 @@ test "$city" \< Paris && echo "Yes, Paris is greater than $city"
<para>Alister's <ulink url="http://code.google.com/p/ansi-color/">
ansi-color</ulink> utility (based on <ulink
url="http://bash.webofcrafts.net/color-1.1.tar.gz">Moshe
url="http://bash.deta.in/color-1.1.tar.gz">Moshe
Jacobson's color utility</ulink> considerably simplifies using
ANSI escape sequences. It substitutes a clean and logical
syntax for the clumsy constructs just discussed.</para>
@ -32054,6 +32146,11 @@ echo "User entered: "$answer""</programlisting>
Mortice Kern Associates add shell scripting capabilities to
Windows.</para>
<para>Another alternative is <ulink
url="http://www2.research.att.com/~gsf/download/uwin/uwin.html">
UNWIN</ulink>, written by David Korn of AT&amp;T, of <link
linkend="kornshellref">Korn Shell</link> fame.</para>
<para>In 2006, Microsoft released the <trademark
class=registered>Windows Powershell</trademark>,
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}</programlisting></para>
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</programlisting></para>
</listitem>
@ -33112,12 +33221,14 @@ echo</programlisting></para>
<footnote><para>Those who can, do. Those who can't . . . get an
MCSE.</para></footnote>
This book is somewhat of a departure from his other major work,
<ulink url="http://bash.webofcrafts.net/hmw60.zip">
<ulink url="http://bash.deta.in/hmw60.zip">
HOW-2 Meet Women: The Shy Man's Guide to
Relationships</ulink>. He has also written the <ulink
url="http://tldp.org/HOWTO/Software-Building-HOWTO.html">Software-Building
HOWTO</ulink>. Of late, he has been trying his (heavy) hand at
short fiction.</para>
HOWTO</ulink>. Of late, he has been trying his
(heavy) hand at short fiction and has at least one <ulink
url="http://www.instructables.com/id/Arduino-Morse-Code-Shield/">Instructable</ulink>
to his (dis)credit.</para>
<para>A Linux user since 1995 (Slackware 2.2, kernel 1.2.1),
the author has emitted a few
@ -33130,13 +33241,13 @@ echo</programlisting></para>
Scrabble&reg; adjudicator, the <ulink
url="http://ibiblio.org/pub/Linux/libs/yawl-0.3.2.tar.gz">yawl</ulink>
word gaming list package, and the <ulink
url="http://bash.webofcrafts.net/qky.README.html">Quacky</ulink>
url="http://bash.deta.in/qky.README.html">Quacky</ulink>
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.</para>
<para>Living in a secluded community with wife and orange
<para>Living in an out-of-the-way community with wife and orange
tabby, he cherishes human frailty, especially his own.
<footnote><para>Sometimes it seems as if he has spent
his entire life flouting conventional wisdom and defying the
@ -33578,9 +33689,6 @@ echo</programlisting></para>
the basic concepts of shell scripting.</para></footnote>
In fact, this book was the <firstterm>ABS Guide</firstterm> author's
first exposure to UNIX shell scripting, lo these many years ago.</para>
<para>For more information, see <ulink
url="http://www.kochan-wood.com/">the Kochan-Wood
website</ulink>.</para>
<para>*</para>
</abstract>
</biblioentry>
@ -33741,7 +33849,7 @@ echo</programlisting></para>
</copyright>
<isbn>0-691-02356-5</isbn>
<abstract><para>The classic tutorial on problem-solving methods
(i.e., algorithms), with special emphasis on how to teach them.</para>
(algorithms), with special emphasis on how to teach them.</para>
<para>*</para>
</abstract>
</biblioentry>
@ -33806,7 +33914,7 @@ echo</programlisting></para>
book is part of the <firstterm>awk</firstterm> documentation,
and printed copies of the latest version are available from
O'Reilly and Associates.</para>
<para>This book has served as an inspiration for the author
<para>This book served as an inspiration for the author
of the <firstterm>ABS Guide</firstterm>.</para>
<para>*</para>
</abstract>
@ -33825,9 +33933,9 @@ echo</programlisting></para>
</copyright>
<isbn>1-56592-054-6</isbn>
<abstract>
<para>This well-written book contains some excellent pointers on shell
scripting in general.</para>
<para>*</para>
<para><anchor id="kornshellref">This well-written book contains
some excellent pointers on shell scripting in general.</para>
<para>*</para>
</abstract>
</biblioentry>
@ -33887,7 +33995,7 @@ echo</programlisting></para>
<year>2004</year>
</copyright>
<isbn>1-59327-012-7</isbn>
<abstract><para>Just what the title promises . . .</para>
<abstract><para>Pretty much what the title promises . . .</para>
<para>*</para>
</abstract>
</biblioentry>
@ -34112,6 +34220,14 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc
</abstract>
</biblioentry>
<biblioentry>
<abstract>
<para>YongYe's wonderfully complex <ulink
url="http://bash.deta.in/Tetris_Game.sh">Tetris game
script</ulink>.</para>
</abstract>
</biblioentry>
<biblioentry>
<abstract>
<para>Mark Komarinski's <ulink
@ -34228,6 +34344,15 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc
</abstract>
</biblioentry>
<biblioentry>
<abstract>
<para><ulink
url="http://auctiongallery.sourceforge.net">AuctionGallery</ulink>,
an application for eBay <quote>power sellers</quote> coded
in Bash.</para>
</abstract>
</biblioentry>
<biblioentry>
<abstract>
<para>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
<title>Contributed Scripts</title>
<para>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.</para>
<example id="mailformat">
@ -34837,7 +34962,7 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc
<para><command>*</command> <emphasis>Must be quoted</emphasis>,
otherwise it defaults to
<quote><varname>$@</varname></quote>.</para>
<varname>$@</varname>.</para>
<para><anchor id="bincomptab"></para>
@ -35425,7 +35550,7 @@ url="http://nixshell.wordpress.com/2011/07/13/arcade-games-written-in-a-shell-sc
<row>
<entry><option>(( var0 = var1&lt;98?9:21 ))</option></entry>
<entry><firstterm>C-style</firstterm> <link
linkend="cstrinary"> trinary</link> operation</entry>
linkend="cstrinary"> ternary</link> operation</entry>
</row>
<row><entry></entry><entry></entry></row>
<row>
@ -35898,13 +36023,13 @@ awk '{print $0}' $filename
<entry><option>2</option></entry>
<entry>Misuse of shell builtins (according to Bash documentation)</entry>
<entry>empty_function() {}</entry>
<entry>Seldom seen, usually defaults to exit
code <errorcode>1</errorcode></entry>
<entry><link linkend="missingkeyword">Missing keyword</link>
or command</entry>
</row>
<row>
<entry><option>126</option></entry>
<entry>Command invoked cannot execute</entry>
<entry></entry>
<entry>/dev/null</entry>
<entry>Permission problem or command is not an executable</entry>
</row>
<row>
@ -35931,7 +36056,7 @@ awk '{print $0}' $filename
<row>
<entry><option>130</option></entry>
<entry>Script terminated by Control-C</entry>
<entry></entry>
<entry><emphasis>Ctl-C</emphasis></entry>
<entry>Control-C is fatal error signal
<errorcode>2</errorcode>, (130 = 128 + 2, see above)</entry>
</row>
@ -38994,6 +39119,11 @@ thegrendel@theriver.com</programlisting></para>
<entry>30 Aug 2011</entry>
<entry>VORTEXBERRY release: Minor update.</entry>
</row>
<row>
<entry><option>6.5</option></entry>
<entry>05 Apr 2012</entry>
<entry>TUNGSTENBERRY release: Minor update.</entry>
</row>
</tbody>
</tgroup>
</table>
@ -39010,31 +39140,32 @@ thegrendel@theriver.com</programlisting></para>
<link linkend="bzipref">bzip2-ed</link>
<quote>tarball</quote> including both the SGML source
and rendered HTML, may be downloaded from the <ulink
url="http://bash.webofcrafts.net/abs-guide-latest.tar.bz2">author's
url="http://bash.deta.in/abs-guide-latest.tar.bz2">author's
home site</ulink>).
A <ulink
url="http://bash.webofcrafts.net/abs-guide.pdf">
pdf version</ulink> is also available.
url="http://bash.deta.in/abs-guide.pdf">
pdf version</ulink> is also available (<ulink
url="http://www.mediafire.com/?3y6fkpd976fcash">mirror site</ulink>).
There is likewise an <ulink
url="http://bash.webofcrafts.net/abs-guide.epub">
url="http://bash.deta.in/abs-guide.epub">
epub version</ulink>, courtesy of Craig Barnes.
The <ulink
url="http://bash.webofcrafts.net/Change.log">change
url="http://bash.deta.in/Change.log">change
log</ulink> gives a detailed revision history.
The <emphasis>ABS Guide</emphasis> even has <ulink
url="http://freshmeat.net/projects/advancedbashscriptingguide/">
its own <filename>freshmeat.net</filename> page</ulink> to keep
track of major updates, user comments, and popularity ratings
for the project.</para>
url="http://freecode.com/projects/advancedbashscriptingguide/">
its own <filename>freshmeat.net/freecode</filename> page</ulink>
to keep track of major updates, user comments, and popularity
ratings for the project.</para>
<para>The legacy hosting site for this document is the <ulink
url="http://www.tldp.org/LDP/abs/">Linux Documentation Project</ulink>,
which maintains many other Guides and HOWTOs as well.</para>
<para>Many thanks to Ronny Bangsund for donating <ulink
url="http://bash.webofcrafts.net/">server space</ulink> to host
url="http://bash.deta.in/">server space</ulink> to host
this project.</para>
@ -39212,17 +39343,18 @@ distributors, or any of its associated software or documentation.</programlistin
url="http://gazette.linux.ru.net/rus/articles/index-abs-guide.html">Russian</ulink>,
<ulink url="http://premekvihan.net/bash">Czech</ulink>, <ulink
url="http://www.linuxsir.org/bbs/showthread.php?t=256887">Chinese</ulink>,
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.</para>
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.</para>
<sidebar><para>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,
<sidebar><para>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,
<email>thegrendel.abs@gmail.com</email>. Note that this
is emphatically <emphasis>not</emphasis> necessary, or even
recommended. This book is a free and freely distributed document
is <emphasis>not</emphasis> necessary.
This book is a free and freely distributed document
for the use and enjoyment of the Linux community.</para></sidebar>

View File

@ -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.

View File

@ -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 $?

View File

@ -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 $?

View File

@ -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.

View File

@ -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

View File

@ -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' . . .)

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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 "==============================================================="

View File

@ -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 ))

View File

@ -3,7 +3,7 @@
# Author: M. Cooper
# License: GPL3
# ---------------------------------
# ----------algorithm--------------
# Fibo(0) = 0
# Fibo(1) = 1
# else

View File

@ -139,7 +139,7 @@ function Solved
}
################### MAIN () ########################
################### MAIN () #######################{
moves=0
Jumble
@ -165,7 +165,7 @@ PrintPuzzle
echo; echo "BRAVO!"; echo
exit 0
####################################################
###################################################}
# Exercise:
# --------

View File

@ -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

View File

@ -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.

View File

@ -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."

View File

@ -9,7 +9,7 @@
#
# Lines beginning with a '#' are comments, and the script ignores them.
__.__..___
___._.____
__.._.____
____.___..
_._______.
____._____

View File

@ -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.
---

View File

@ -7,14 +7,14 @@
# This is an implementation of the Gronsfeld Cipher.
# It's essentially a stripped-down variant of the
#+ polyalphabetic Vigen&egrave;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.
# ************************************************************** #

View File

@ -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

View File

@ -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 ]

View File

@ -7,3 +7,7 @@ do
# done # Required keyword 'done' commented out in line 7.
exit 0
# === #
echo $? # 2

View File

@ -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 &lt;tenox@tenox.tc&gt;,

View File

@ -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

View File

@ -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

View File

@ -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 ^^^^ ^^^^

View File

@ -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."

View File

@ -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 &lt;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

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,6 @@
#!/bin/bash
E_WRONG_DIRECTORY=65
E_WRONG_DIRECTORY=85
clear # Clear the screen.

View File

@ -4,7 +4,9 @@ syzygy
orangutan
doing
madeupword
making
gargantuan
linux
nicrosoft
nogood
ziggurat
what

View File

@ -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.

View File

@ -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 | \