⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dblparens.html

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><HEAD><TITLE>The Double Parentheses Construct</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.57"><LINKREL="HOME"TITLE="Advanced Bash-Scripting Guide"HREF="index.html"><LINKREL="UP"TITLE="Variables Revisited"HREF="variables2.html"><LINKREL="PREVIOUS"TITLE="$RANDOM: generate random integer"HREF="randomvar.html"><LINKREL="NEXT"TITLE="Loops and Branches"HREF="loops.html"><METAHTTP-EQUIV="Content-Style-Type"CONTENT="text/css"><LINKREL="stylesheet"HREF="common/kde-common.css"TYPE="text/css"><METAHTTP-EQUIV="Content-Type"CONTENT="text/html; charset=iso-8859-1"><METAHTTP-EQUIV="Content-Language"CONTENT="en"><LINKREL="stylesheet"HREF="common/kde-localised.css"TYPE="text/css"TITLE="KDE-English"><LINKREL="stylesheet"HREF="common/kde-default.css"TYPE="text/css"TITLE="KDE-Default"></HEAD><BODYCLASS="SECT1"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#AA0000"VLINK="#AA0055"ALINK="#AA0000"STYLE="font-family: sans-serif;"><DIVCLASS="NAVHEADER"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="randomvar.html">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. Variables Revisited</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="loops.html">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="DBLPARENS">9.7. The Double Parentheses Construct</A></H1><P>Similar to the <AHREF="internal.html#LETREF">let</A> command,	  the <BCLASS="COMMAND">((...))</B> construct permits arithmetic	  expansion and evaluation. In its simplest form, <TTCLASS="USERINPUT"><B>a=$((	  5 + 3 ))</B></TT> would set <SPANCLASS="QUOTE">"a"</SPAN> to <SPANCLASS="QUOTE">"5 +	  3"</SPAN>, or 8. However, this double parentheses construct is	  also a mechanism for allowing C-type manipulation of variables	  in Bash.</P><DIVCLASS="EXAMPLE"><HR><ANAME="CVARS"></A><P><B>Example 9-30. C-type manipulation of variables</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# Manipulating a variable, C-style, using the ((...)) construct.   3&nbsp;   4&nbsp;   5&nbsp;echo   6&nbsp;   7&nbsp;(( a = 23 ))  # Setting a value, C-style, with spaces on both sides of the "=".   8&nbsp;echo "a (initial value) = $a"   9&nbsp;  10&nbsp;(( a++ ))     # Post-increment 'a', C-style.  11&nbsp;echo "a (after a++) = $a"  12&nbsp;  13&nbsp;(( a-- ))     # Post-decrement 'a', C-style.  14&nbsp;echo "a (after a--) = $a"  15&nbsp;  16&nbsp;  17&nbsp;(( ++a ))     # Pre-increment 'a', C-style.  18&nbsp;echo "a (after ++a) = $a"  19&nbsp;  20&nbsp;(( --a ))     # Pre-decrement 'a', C-style.  21&nbsp;echo "a (after --a) = $a"  22&nbsp;  23&nbsp;echo  24&nbsp;  25&nbsp;########################################################  26&nbsp;#  Note that, as in C, pre- and post-decrement operators  27&nbsp;#+ have slightly different side-effects.  28&nbsp;  29&nbsp;n=1; let --n &#38;&#38; echo "True" || echo "False"  # False  30&nbsp;n=1; let n-- &#38;&#38; echo "True" || echo "False"  # True  31&nbsp;  32&nbsp;#  Thanks, Jeroen Domburg.  33&nbsp;########################################################  34&nbsp;  35&nbsp;echo  36&nbsp;  37&nbsp;(( t = a&#60;45?7:11 ))   # C-style trinary operator.  38&nbsp;echo "If a &#60; 45, then t = 7, else t = 11."  39&nbsp;echo "t = $t "        # Yes!  40&nbsp;  41&nbsp;echo  42&nbsp;  43&nbsp;  44&nbsp;# -----------------  45&nbsp;# Easter Egg alert!  46&nbsp;# -----------------  47&nbsp;#  Chet Ramey apparently snuck a bunch of undocumented C-style constructs  48&nbsp;#+ into Bash (actually adapted from ksh, pretty much).  49&nbsp;#  In the Bash docs, Ramey calls ((...)) shell arithmetic,  50&nbsp;#+ but it goes far beyond that.  51&nbsp;#  Sorry, Chet, the secret is now out.  52&nbsp;  53&nbsp;# See also "for" and "while" loops using the ((...)) construct.  54&nbsp;  55&nbsp;# These work only with Bash, version 2.04 or later.  56&nbsp;  57&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV><P>See also <AHREF="loops.html#FORLOOPC">Example 10-12</A>.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLEWIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="randomvar.html">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="loops.html">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">$RANDOM: generate random integer</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="variables2.html">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Loops and Branches</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -