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

📄 dblparens.html

📁 Shall高级编程
💻 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.76b+"><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"><TABLESUMMARY="Header navigation table"WIDTH="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"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 9. Variables Revisited</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="loops.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="DBLPARENS"></A>9.7. The Double Parentheses Construct</H1><P><ANAME="DBLPARENSREF"></A></P><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	  <TTCLASS="USERINPUT"><B>a</B></TT> to <TTCLASS="USERINPUT"><B>5 + 3</B></TT>, or	  <TTCLASS="USERINPUT"><B>8</B></TT>. However, this double parentheses	  construct is also a mechanism for allowing C-style	  manipulation of variables in Bash, for example,	  <TTCLASS="VARNAME">(( var++ ))</TT>.</P><P><ANAME="PLUSPLUSREF"></A></P><DIVCLASS="EXAMPLE"><HR><ANAME="CVARS"></A><P><B>Example 9-33. C-style 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,   8&nbsp;              #+ with spaces on both sides of the "=".   9&nbsp;echo "a (initial value) = $a"  10&nbsp;  11&nbsp;(( a++ ))     #  Post-increment 'a', C-style.  12&nbsp;echo "a (after a++) = $a"  13&nbsp;  14&nbsp;(( a-- ))     #  Post-decrement 'a', C-style.  15&nbsp;echo "a (after a--) = $a"  16&nbsp;  17&nbsp;  18&nbsp;(( ++a ))     #  Pre-increment 'a', C-style.  19&nbsp;echo "a (after ++a) = $a"  20&nbsp;  21&nbsp;(( --a ))     #  Pre-decrement 'a', C-style.  22&nbsp;echo "a (after --a) = $a"  23&nbsp;  24&nbsp;echo  25&nbsp;  26&nbsp;########################################################  27&nbsp;#  Note that, as in C, pre- and post-decrement operators  28&nbsp;#+ have slightly different side-effects.  29&nbsp;  30&nbsp;n=1; let --n &#38;&#38; echo "True" || echo "False"  # False  31&nbsp;n=1; let n-- &#38;&#38; echo "True" || echo "False"  # True  32&nbsp;  33&nbsp;#  Thanks, Jeroen Domburg.  34&nbsp;########################################################  35&nbsp;  36&nbsp;echo  37&nbsp;  38&nbsp;(( t = a&#60;45?7:11 ))   # C-style trinary operator.  39&nbsp;#       ^  ^ ^  40&nbsp;echo "If a &#60; 45, then t = 7, else t = 11."  41&nbsp;echo "t = $t "        # Yes!  42&nbsp;  43&nbsp;echo  44&nbsp;  45&nbsp;  46&nbsp;# -----------------  47&nbsp;# Easter Egg alert!  48&nbsp;# -----------------  49&nbsp;#  Chet Ramey seems to have snuck a bunch of undocumented C-style  50&nbsp;#+ constructs into Bash (actually adapted from ksh, pretty much).  51&nbsp;#  In the Bash docs, Ramey calls ((...)) shell arithmetic,  52&nbsp;#+ but it goes far beyond that.  53&nbsp;#  Sorry, Chet, the secret is now out.  54&nbsp;  55&nbsp;# See also "for" and "while" loops using the ((...)) construct.  56&nbsp;  57&nbsp;# These work only with Bash, version 2.04 or later.  58&nbsp;  59&nbsp;exit 0</PRE></TD></TR></TABLE><HR></DIV><P>See also <AHREF="loops.html#FORLOOPC">Example 10-12</A> and <AHREF="numerical-constants.html#NUMBERS">Example 8-4</A>.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="randomvar.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="loops.html"ACCESSKEY="N">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"ACCESSKEY="U">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 + -