双括号可增加bash中的变量

Mic*_*ael 1 bash increment

假设我在bash中增加了一个变量。例如,

> i = 0; 为ls * .JPG中的f; 回显$ f $ i; ((i ++)); 做完了
a0.jpg 0
a1.jpg 1
...

现在我想知道为什么我需要那些双括号来增加i

axi*_*iom 5

双括号结构是支持算术运算的shell功能。相同的构造也可以用于循环和特殊的数值常量

同样,从第一个链接复制:

# -----------------
# Easter Egg alert!
# -----------------
#  Chet Ramey seems to have snuck a bunch of undocumented C-style
#+ constructs into Bash (actually adapted from ksh, pretty much).
#  In the Bash docs, Ramey calls (( ... )) shell arithmetic,
#+ but it goes far beyond that.
#  Sorry, Chet, the secret is out.
Run Code Online (Sandbox Code Playgroud)