【发布时间】:2014-11-11 19:39:03
【问题描述】:
我正在运行一些 Bash 条件脚本并发现如果我运行它:
#!/bin/bash
read foo
if [[ foo -eq 1 ]]; then
echo "A"
fi
if [[ foo -eq 2 ]]; then
echo "B"
fi
条件句在 Bash 4.2.25 下可以正常工作,无需使用 $foo。为什么不使用 $ 引用变量就可以工作?
【问题讨论】:
-
基本上是因为它是一个
bashbuilt-in command(与Bourne shell 或POSIX shell 相比),并且已经规定变量不需要在此前缀为$一个上下文。
标签: bash variables if-statement conditional