bash 脚本中的基本类型是什么?我觉得这是一个简单的问题,但要找到答案却出奇地困难。我知道至少有数组,因为你可以执行诸如
for file in *.less
# code working with file
所以它看起来像 *.less 是一个数组。
还有,还有字符串类型,因为如果我有
a=y
b=z
c=$a+$b
echo $c
>> y+z
除此之外还有其他类型吗?非常感谢!
编辑:经过进一步研究,似乎还存在关联数组,可以通过以下方式声明
declare -A address
我从 here 得到的.有没有其他类型的例子?
最佳答案
这是一个有趣的问题,这是我的发现:
bash supports several programming primitives shared by most programming languages. It can perform choices (if then else, case), it can loop (for,while, until) and it has functions (function). http://dasher.wustl.edu/chem478/software/unix-tools/bash.html
Bash 变量是无类型的。
Unlike many other programming languages, Bash does not segregate its variables by "type." Essentially, Bash variables are character strings, but, depending on context, Bash permits arithmetic operations and comparisons on variables. The determining factor is whether the value of a variable contains only digits. http://tldp.org/LDP/abs/html/untyped.html
Bash 提供一维索引和关联数组变量。 http://www.gnu.org/software/bash/manual/html_node/Arrays.html#Arrays
关于Bash 原始类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18520951/