mirror of https://github.com/tLDP/LDP
corrected typos, more user remarks
This commit is contained in:
parent
3b5078a8cb
commit
55f0adab52
|
@ -851,7 +851,7 @@ Thu Feb 6 10:06:20 CET 2003
|
|||
<sect2 id="sect_03_04_05"><title>Arithmetic expansion</title>
|
||||
<para>Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is:</para><cmdsynopsis><command>$(( EXPRESSION ))</command></cmdsynopsis>
|
||||
<para>The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially. All tokens in the expression undergo parameter expansion, command substitution, and quote removal. Arithmetic substitutions may be nested.</para>
|
||||
<para>Evaluation of arithmetic expressions is done in fixed-width integers with no check for overflow - although division by zero is trapped and recognized as an error. The operators are the same as in the C programming language. In order of decreasing precedence, the list looks like this:</para>
|
||||
<para>Evaluation of arithmetic expressions is done in fixed-width integers with no check for overflow - although division by zero is trapped and recognized as an error. The operators are roughly the same as in the C programming language. In order of decreasing precedence, the list looks like this:</para>
|
||||
<table id="table_03_04" frame="all">
|
||||
<title>Arithmetic operators</title>
|
||||
<tgroup cols="2" align="left" colsep="1" rowsep="1">
|
||||
|
@ -868,7 +868,7 @@ Thu Feb 6 10:06:20 CET 2003
|
|||
<row><entry>+ and -</entry><entry>addition, subtraction</entry></row>
|
||||
<row><entry><< and >></entry><entry>left and right bitwise shifts</entry></row>
|
||||
<row><entry><=, >=, < and ></entry><entry>comparison operators</entry></row>
|
||||
<row><entry>== and !==</entry><entry>equality and inequality</entry></row>
|
||||
<row><entry>== and !=</entry><entry>equality and inequality</entry></row>
|
||||
<row><entry>&</entry><entry>bitwise AND</entry></row>
|
||||
<row><entry>^</entry><entry>bitwise exclusive OR</entry></row>
|
||||
<row><entry>|</entry><entry>bitwise OR</entry></row>
|
||||
|
@ -904,7 +904,7 @@ leading <quote>0x</quote> or <quote>0X</quote> denotes hexadecimal. Otherwise,
|
|||
</sect2>
|
||||
<sect2 id="sect_03_04_07"><title>Word splitting</title>
|
||||
<para>The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.</para>
|
||||
<para>The shell treats each character of <varname>$IFS</varname> as a delimiter, and splits the results of the other expansions into words on these characters. If <varname>IF</varname> is unset, or its value is exactly <quote>'<space><tab><newline>'</quote>, the default, then any sequence of <varname>IFS</varname> characters serves to delimit words. If <varname>IFS</varname> has a value other than the default, then sequences of the whitespace characters <quote>space</quote> and <quote>Tab</quote> are ignored at the beginning and end of the word, as long as the whitespace character is in the value of <varname>IFS</varname> (an <varname>IFS</varname> whitespace character). Any character in <varname>IFS</varname> that is not <varname>IFS</varname> whitespace, along with any adjacent <varname>IF</varname> whitespace characters, delimits a field. A sequence of <varname>IFS</varname> whitespace characters is also treated as a delimiter. If the value of <varname>IFS</varname> is null, no word splitting occurs.</para>
|
||||
<para>The shell treats each character of <varname>$IFS</varname> as a delimiter, and splits the results of the other expansions into words on these characters. If <varname>IFS</varname> is unset, or its value is exactly <quote>'<space><tab><newline>'</quote>, the default, then any sequence of <varname>IFS</varname> characters serves to delimit words. If <varname>IFS</varname> has a value other than the default, then sequences of the whitespace characters <quote>space</quote> and <quote>Tab</quote> are ignored at the beginning and end of the word, as long as the whitespace character is in the value of <varname>IFS</varname> (an <varname>IFS</varname> whitespace character). Any character in <varname>IFS</varname> that is not <varname>IFS</varname> whitespace, along with any adjacent <varname>IF</varname> whitespace characters, delimits a field. A sequence of <varname>IFS</varname> whitespace characters is also treated as a delimiter. If the value of <varname>IFS</varname> is null, no word splitting occurs.</para>
|
||||
<para>Explicit null arguments (<quote>""</quote> or <quote>''</quote>) are retained. Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed. If a parameter with no value is expanded within double quotes, a null argument results and is retained.</para>
|
||||
<note><title>Expansion and word splitting</title><para>If no expansion occurs, no splitting is performed.</para></note>
|
||||
</sect2>
|
||||
|
|
|
@ -52,7 +52,7 @@ contain function definitions, loops, conditions and other programming constructs
|
|||
</figure>
|
||||
<para>In the output of <command>ls <option>-l</option></command>, there are 9 columns. The <command>print</command> statement uses these fields as follows:</para>
|
||||
<screen>
|
||||
<prompt>kelly@octarine ~/test></prompt> <command>ls <option>-l</option> | awk <parameter>'{ print $9 $5 }'</parameter></command>
|
||||
<prompt>kelly@octarine ~/test></prompt> <command>ls <option>-l</option> | awk <parameter>'{ print $5 $9 }'</parameter></command>
|
||||
160orig
|
||||
121script.sed
|
||||
120temp_file
|
||||
|
|
|
@ -175,7 +175,7 @@ not a local account
|
|||
<prompt>anny ></prompt> <command>echo <varname>$num</varname></command>
|
||||
201
|
||||
|
||||
<prompt>anny ></prompt> <command>if <parameter>[ "num" > 150 ]</parameter></command>
|
||||
<prompt>anny ></prompt> <command>if <parameter>[ "$num" -gt "150" ]</parameter></command>
|
||||
<prompt>More input></prompt> <command>then echo ; echo <parameter>"you've worked hard enough for today."</parameter></command>
|
||||
<prompt>More input></prompt> <command>echo ; fi</command>
|
||||
|
||||
|
@ -211,9 +211,10 @@ fi
|
|||
</screen>
|
||||
<para>With Bash, you can shorten this type of construct. The compact equivalent of the above test is as follows:</para>
|
||||
<screen>
|
||||
[ "$(whoami)" != 'root' ] && echo you are using a non-privileged account
|
||||
[ "$(whoami)" != 'root' ] && ( echo you are using a non-privileged account; exit 1 )
|
||||
</screen>
|
||||
<para>Regular expressions may also be used:</para>
|
||||
<para>Similar to the <quote>&&</quote> expression which indicates what to do if the test proves true, <quote>||</quote> specifies what to do if the test is false.</para>
|
||||
<para>Regular expressions may also be used in comparisons:</para>
|
||||
<screen>
|
||||
<prompt>anny ></prompt> <command><varname>gender</varname>=<parameter>"female"</parameter></command>
|
||||
|
||||
|
@ -223,6 +224,12 @@ Pleasure to meet you, Madame.
|
|||
|
||||
<prompt>anny ></prompt>
|
||||
</screen>
|
||||
<note><title>Real Programmers</title>
|
||||
<para>Most programmers will prefer to use the <command>test</command> built-in command, which is equivalent to using square brackets for comparison, like this:</para>
|
||||
<screen>
|
||||
test "$(whoami)" != 'root' && (echo you are using a non-privileged account; exit 1)
|
||||
</screen>
|
||||
</note>
|
||||
<para>See the info pages for Bash for more information on pattern matching with the <quote>(( EXPRESSION ))</quote> and <quote>[[ EXPRESSION ]]</quote> constructs.</para>
|
||||
</sect3>
|
||||
</sect2>
|
||||
|
|
Loading…
Reference in New Issue