This commit is contained in:
gferg 2009-01-19 15:31:05 +00:00
parent c344f1affc
commit 54b9f39293
10 changed files with 376 additions and 326 deletions

View File

@ -37,7 +37,7 @@
</author>
</authorgroup>
<edition>Version 1.10 Last updated 20080606</edition>
<edition>Version 1.11 Last updated 20081227</edition>
<keywordset>
<keyword>Linux</keyword>
<keyword>Scripts</keyword>
@ -94,7 +94,7 @@
<section id="intro_03">
<title>New versions, translations and availability</title>
<para>The most recent edition can be found at <ulink url="http://tille.xalasys.com/training/bash/" />. You should find the same version at <ulink url="http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html" />.</para>
<para>The most recent edition can be found at <ulink url="http://tille.garrels.be/training/bash/" />. You should find the same version at <ulink url="http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html" />.</para>
<para>This guide is available in print from <ulink url="http://store.fultus.com/product_info.php?products_id=66">Fultus.com</ulink>.</para>
@ -123,6 +123,12 @@
<para>
<revhistory>
<revision>
<revnumber>1.11</revnumber>
<date>2008-12-27</date>
<authorinitials>MG</authorinitials>
<revremark>Processed input from readers.</revremark>
</revision>
<revision>
<revnumber>1.10</revnumber>
<date>2008-06-06</date>
<authorinitials>MG</authorinitials>
@ -152,37 +158,6 @@
<authorinitials>MG</authorinitials>
<revremark>Minor debugging, added more keywords, info about new Bash 3.0, took out blank image.</revremark>
</revision>
<revision>
<revnumber>1.5</revnumber>
<date>2004-12-06</date>
<authorinitials>MG</authorinitials>
<revremark>Changes because of new domain, minor corrections.</revremark>
</revision>
<revision>
<revnumber>1.4</revnumber>
<date>2004-10-18</date>
<authorinitials>MG</authorinitials>
<revremark>Debugging, added a couple of notes in chap9, replaced screenshots with screen sections. Corrected some typos.</revremark>
</revision>
<revision>
<revnumber>1.3</revnumber>
<date>2004-07-09</date>
<authorinitials>MG</authorinitials>
<revremark>Added tracer image 1x1 pixel http://tille.xalasys.com/images/blank-bash.png, added textobjects for all pictures, fixed wrong links in index, made signal list more clear.</revremark>
</revision>
<revision>
<revnumber>1.2</revnumber>
<date>2004-06-15</date>
<authorinitials>MG</authorinitials>
<revremark>Added index, more markup in screen sections.</revremark>
</revision>
<revision>
<revnumber>1.1</revnumber>
<date>2004-05-22</date>
<authorinitials>MG</authorinitials>
<revremark>Last read-through before going to press, added more examples, checked summaries, exercises, cleaned up introduction.</revremark>
</revision>
<revision>
<revnumber>1.0</revnumber>
<date>2004-04-27</date>
@ -223,7 +198,7 @@ Thanks to all the friends who helped (or tried to) and to my husband; your encou
<para>
Missing information, missing links, missing characters, remarks? Mail it to
<address><email>tille wants no spam _at_ xalasys dot com</email></address>
<address><email>tille wants no spam _at_ garrels dot be</email></address>
the maintainer of this document.
</para>
@ -353,7 +328,7 @@ is the heart of the system.</quote></entry>
within this guide.</entry>
</row>
<row>
<entry><ulink url="http://tille.xalasys.com">The author</ulink></entry>
<entry><ulink url="http://tille.garrels.be">The author</ulink></entry>
<entry>Clickable link to an external web resource.</entry>
</row>
</tbody>

View File

@ -459,7 +459,7 @@ the shell expansions or by the <command>let</command> built-in.</para>
<prompt>tom:~&gt;</prompt> <command>cat <filename>mysystem.sh</filename></command>
#!/bin/bash
clear
printf "This is information provided by mysystem.sh. Program starts now."
printf "This is information provided by mysystem.sh. Program starts now.\n"
printf "Hello, $USER.\n\n"

View File

@ -17,7 +17,11 @@
<para>To create<indexterm><primary>scripts</primary><secondary>creation</secondary></indexterm> a shell script, open a new empty file in your editor. Any text editor will do: <command>vim</command>, <command>emacs</command>, <command>gedit</command>, <command>dtpad</command> et cetera are all valid. You might want to chose a more advanced editor like <command>vim</command> or <command>emacs</command>, however, because these can be configured to recognize shell and Bash syntax and can be a great help in preventing those errors that beginners frequently make, such as forgetting brackets and semi-colons.</para>
<tip><title>Syntax highlighting in vim</title>
<para>In order to activate syntax highlighting in <command>vim</command>, use the command</para>
<cmdsynopsis><command>:set syntax enable</command></cmdsynopsis>
<cmdsynopsis><command>:syntax enable</command></cmdsynopsis>
<para>or</para>
<cmdsynopsis><command>:sy enable</command></cmdsynopsis>
<para>or</para>
<cmdsynopsis><command>:syn enable</command></cmdsynopsis>
<para>You can add this setting to your <filename>.vimrc</filename> file to make it permanent.</para>
</tip>
<para>Put UNIX commands in the new empty file, like you would enter them on the command line. As discussed in the previous chapter (see <xref linkend="sect_01_03" />), commands can be shell functions, shell built-ins, UNIX commands and other scripts.</para>
@ -199,9 +203,7 @@ And this is a number:
I'm giving you back your prompt now.
+ echo
</screen>
<note><title>Future Bash Features</title>
<para>There is now a full-fledged debugger for Bash, available at <ulink url="http://bashdb.sourceforge.net">SourceForge</ulink>. Right now however, you need a patched version of bash-2.05. The new debugging features might become available in bash-3.0.</para>
</note>
<para>There is now a full-fledged debugger for Bash, available at <ulink url="http://bashdb.sourceforge.net">SourceForge</ulink>. These debugging features are available in most modern versions of Bash, starting from 3.x.</para>
</sect2>
<sect2 id="sect_02_03_02"><title>Debugging on part(s) of the script</title>

View File

@ -259,7 +259,7 @@ CFLAGS=-O2 -fomit-frame-pointer
COLORTERM=gnome-terminal
CXXFLAGS=-O2 -fomit-frame-pointer
DISPLAY=:0
DOMAIN=hq.xalasys.com
DOMAIN=hq.garrels.be
e=
TOR=vi
FCEDIT=vi
@ -275,7 +275,7 @@ HISTFILESIZE=5000
history_control=ignoredups
HISTSIZE=2000
HOME=/nethome/franky
HOSTNAME=octarine.hq.xalasys.com
HOSTNAME=octarine.hq.garrels.be
INPUTRC=/etc/inputrc
IRCNAME=franky
JAVA_HOME=/usr/java/j2sdk1.4.0
@ -309,7 +309,7 @@ PATH=/nethome/franky/bin.Linux:/nethome/franky/bin:/usr/local/bin:/usr/local/sbi
PS1=\[\033[1;44m\]franky is in \w\[\033[0m\]
PS2=More input>
PWD=/nethome/franky
SESSION_MANAGER=local/octarine.hq.xalasys.com:/tmp/.ICE-unix/22106
SESSION_MANAGER=local/octarine.hq.garrels.be:/tmp/.ICE-unix/22106
SHELL=/bin/bash
SHELL_LOGIN=--login
SHLVL=2
@ -341,7 +341,7 @@ YACC=bison -y
<para>Below is a diff file made by comparing <command>printenv</command> and <command>set</command> output, after leaving out the functions which are also displayed by the <command>set</command> command:</para>
<screen>
<prompt>franky ~&gt;</prompt> <command>diff <filename>set.sorted</filename> <filename>printenv.sorted</filename></command> | <command>grep <parameter>"&lt;"</parameter></command> | <command>awk <parameter>'{ print $2 }'</parameter></command>
BASE=/nethome/franky/.Shell/hq.xalasys.com/octarine.aliases
BASE=/nethome/franky/.Shell/hq.garrels.be/octarine.aliases
BASH=/bin/bash
BASH_VERSINFO=([0]="2"
BASH_VERSION='2.05b.0(1)-release'
@ -676,8 +676,8 @@ bzip2 /var/tmp/home_franky.tar
scp /var/tmp/home_franky.tar.bz2 bordeaux:/opt/backup/franky &gt; /dev/null 2&gt;&amp;1
# Create a timestamp in a logfile.
date &gt; /home/franky/log/home_backup.log
echo backup succeeded &gt; /home/franky/log/home_backup.log
date &gt;&gt; /home/franky/log/home_backup.log
echo backup succeeded &gt;&gt; /home/franky/log/home_backup.log
</screen>
<para>First of all, you are more likely to make errors if you name files and directories manually each time you need them. Secondly, suppose <emphasis>franky</emphasis> wants to give this script to <emphasis>carol</emphasis>, then carol will have to do quite some editing before she can use the script to back up her home directory. The same is true if <emphasis>franky</emphasis> wants to use this script for backing up other directories. For easy recycling, make all files, directories, usernames, servernames etcetera variable. Thus, you only need to edit a value once, without having to go through the entire script to check where a parameter occurs. This is an example:</para>
<screen>
@ -708,8 +708,8 @@ bzip2 $TARFILE
scp $BZIPFILE $SERVER:$REMOTEDIR &gt; /dev/null 2&gt;&amp;1
# Create a timestamp in a logfile.
date &gt; $LOGFILE
echo backup succeeded &gt; $LOGFILE
date &gt;&gt; $LOGFILE
echo backup succeeded &gt;&gt; $LOGFILE
</screen>
<note><title>Large directories and low bandwidth</title>
@ -887,7 +887,7 @@ Thu Feb 6 10:06:20 CET 2003
<para>Constants with a leading 0 (zero) are interpreted as octal numbers. A
leading <quote>0x</quote> or <quote>0X</quote> denotes hexadecimal. Otherwise, numbers take the form <quote>[BASE'#']N</quote>, where <quote>BASE</quote> is a decimal number between 2 and 64 representing the arithmetic base, and N is a number in that base. If <quote>BASE'#'</quote> is omitted, then base 10 is used. The digits greater than 9 are represented by the lowercase letters, the uppercase letters, <quote>@</quote>, and <quote>_</quote>, in that order. If <quote>BASE</quote> is less than or equal to 36, lowercase and uppercase letters may be used interchangably to represent numbers between 10 and 35.</para>
<para>Operators are evaluated in order of precedence. Sub-expressions in parentheses are evaluated first and may override the precedence rules above.</para>
<para>Wherever possible, Bash users should try to use the syntax with angular brackets:</para>
<para>Wherever possible, Bash users should try to use the syntax with square brackets:</para>
<cmdsynopsis><command>$[ EXPRESSION ]</command></cmdsynopsis>
<para>However, this will only calculate the result of <emphasis>EXPRESSION</emphasis>, and do no tests:</para>
<screen>
@ -949,8 +949,6 @@ alias ping='ping -vc1'
alias sb='ssh blubber'
alias sl='ls'
alias ss='ssh octarine'
alias sss='ssh -C server1.us.xalasys.com'
alias sssu='ssh -C -l root server1.us.xalasys.com'
alias tar='gtar'
alias tmp='cd /tmp'
alias unaliasall='unalias -a'

View File

@ -122,7 +122,7 @@ This is a line not containing any errors.
<prompt>sandy ~&gt;</prompt>
</screen>
<para>Note that the last dot needs to be escaped in order to actually match. In our example the expression just matches any character, including the last dot.</para>
</sect2>
<sect2 id="sect_05_02_03"><title>Ranges of lines</title>
<para>This time we want to take out the lines containing the errors. In the example these are lines 2 to 4. Specify this range<indexterm><primary>sed</primary><secondary>ranges of lines</secondary></indexterm> to address, together with the <command>d</command> command:</para>

View File

@ -66,7 +66,9 @@ contain function definitions, loops, conditions and other programming constructs
<prompt>kelly@octarine ~/test&gt;</prompt>
</screen>
<para>This command printed the fifth column of a long file listing, which contains the file size, and the last column, the name of the file. This output is not very readable unless you use the official way of referring to columns, which is to separate the ones that you want to print with a comma. In that case, the default output separater character, usually a space, will be put in between each output field.</para>
<note><title>Local configuration</title>
<para>Note that the configuration of the output of the <command>ls <option>-l</option></command> command might be different on your system. Display of time and date is dependent on your locale setting.</para>
</note>
</sect2>
<sect2 id="sect_06_02_02"><title>Formatting fields</title>

View File

@ -79,7 +79,7 @@
</tbody>
</tgroup>
</table>
<para>The <command>[</command> (or <command>test</command>) built-in evaluates conditional expressions using a set of rules based on the number of arguments. More information about this subject can be found in the Bash documentation. Just like the <command>if</command> is closed with <command>fi</command>, the opening angular bracket should be closed after the conditions have been listed.</para>
<para>The <command>[</command> (or <command>test</command>) built-in evaluates conditional expressions using a set of rules based on the number of arguments. More information about this subject can be found in the Bash documentation. Just like the <command>if</command> is closed with <command>fi</command>, the opening square bracket should be closed after the conditions have been listed.</para>
</sect3>
<sect3 id="sect_07_01_01_02"><title>Commands following the then statement</title>
<para>The <command>CONSEQUENT-COMMANDS</command> list that follows the <command>then</command> statement can be any valid UNIX command, any executable program, any executable shell script or any shell statement, with the exception of the closing <command>fi</command>. It is important to remember that the <command>then</command> and <command>fi</command> are considered to be separated statements in the shell. Therefore, when issued on the command line, they are separated by a semi-colon.</para>
@ -448,7 +448,7 @@ This is not a leap year.
</textobject>
</mediaobject>
</figure>
<para>We use the double brackets for testing<indexterm><primary>arithmetic expression</primary><secondary>testing</secondary></indexterm> an arithmetic expression, see <xref linkend="sect_03_04_05" />. This is equivalent to the <command>let</command> statement. You will get stuck using angular brackets here, if you try something like <command>$[$year % 400]</command>, because here, the angular brackets don't represent an actual command by themselves.</para>
<para>We use the double brackets for testing<indexterm><primary>arithmetic expression</primary><secondary>testing</secondary></indexterm> an arithmetic expression, see <xref linkend="sect_03_04_05" />. This is equivalent to the <command>let</command> statement. You will get stuck using square brackets here, if you try something like <command>$[$year % 400]</command>, because here, the square brackets don't represent an actual command by themselves.</para>
<para>Among other editors, <command>gvim</command> is one of those supporting colour schemes according to the file format; such editors are useful for detecting errors in your code.</para>
</sect2>

View File

@ -144,13 +144,13 @@ Usage of the feed script: ./feed.sh food-on-menu animal-name
<row><entry>\t</entry><entry>Horizontal tab.</entry></row>
<row><entry>\v</entry><entry>Vertical tab.</entry></row>
<row><entry>\\</entry><entry>Backslash.</entry></row>
<row><entry>\ONNN</entry><entry>The eight-bit character whose value is the octal value NNN (zero to three octal digits).</entry></row>
<row><entry>\0NNN</entry><entry>The eight-bit character whose value is the octal value NNN (zero to three octal digits).</entry></row>
<row><entry>\NNN</entry><entry>The eight-bit character whose value is the octal value NNN (one to three octal digits).</entry></row>
<row><entry>\xHH</entry><entry>The eight-bit character whose value is the hexadecimal value (one or two hexadecimal digits).</entry></row>
</tbody>
</tgroup>
</table>
<para>For more information about the <command>printf</command> command and the way it allows you to format output, see the Bash info pages.</para>
<para>For more information about the <command>printf</command> command and the way it allows you to format output, see the Bash info pages. Keep in mind that there might be differences between different versions of Bash.</para>
</sect2>
</sect1>
@ -611,7 +611,7 @@ Transaction(s) Complete
<listitem><para>Compress the backup using any compression tool. Inform the user that the script is doing this, because it might take some time, during which the user might start worrying if no output appears on the screen.</para></listitem>
<listitem><para>Print a message informing the user about the size of the compressed backup.</para></listitem>
</itemizedlist>
<para>See <command>info tar</command> or <ulink url="http://tille.xalasys.com/training/tldp/c4540.html#sect_09_01_01">Introduction to Linux</ulink>, chapter 9: <quote>Preparing your data</quote> for background information.</para>
<para>See <command>info tar</command> or <ulink url="http://tille.garrels.be/training/tldp/c4540.html#sect_09_01_01">Introduction to Linux</ulink>, chapter 9: <quote>Preparing your data</quote> for background information.</para>
</listitem>
<listitem><para>Write a script called <filename>simple-useradd.sh</filename> that adds a local user to the system. This script should:</para>
<itemizedlist>

View File

@ -102,7 +102,7 @@
>
<title>Copyright and License</title>
<para>
Copyright (c) 2003 through 2008 Eric Meyerhoff.
Copyright (c) 2003 through 2009 Eric Meyerhoff.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
@ -1662,3 +1662,4 @@ their use in free software.</para>
</para>
</appendix>
</article>

File diff suppressed because it is too large Load Diff