Bash 原始类型

标签 bash types

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/

相关文章:

linux - 如何同时触发多个nohup脚本?

php - 无法从 PHP 向 TMUX session 发送命令

types - MiniDumpWriteDump 及其 MINIDUMP_TYPE 类型

c - 结构类型转换

c# - 普通类型和匿名类型有什么区别?

ruby-on-rails - Rails STI : How to change mapping between class name & value of the 'type' column

linux - 将交互式 bash session 通过管道传输到文件

linux - 如何在 linux 中传入读取的 bash 变量并将其作为消息发送到 git commit 中?

Bash - 如何避免命令 "eval set --"评估变量

objective-c - 为什么运行时允许将数组中的 NSDictionary 赋值给 NSString 变量?