什么[[$ something = {{*]]在bash中做什么?

时间:2015-07-31 23:16:20

标签: bash scripting

在一些shell脚本中找到此表达式。双花括号“{{*”是什么意思?

if [[ "$_DIR" = {{* ]]

我查看http://www.gnu.org/software/bash/manual/bash.html并尝试搜索,但无法找到解释。

1 个答案:

答案 0 :(得分:3)

这意味着:"如果$ _DIR"扩展为以" {{" ...

开头的字符串

因此,{{*实际上并不意味着要抨击任何东西,比你写的更多

for file in {{*; do printf '%s\n' "$file"; done

...意味着{{*比bash有更多的意义而且#34;所有名称以两个花括号开头的文件"。

搜索"模式匹配"在BashFAQ #31中了解有关[[的更多内容以及它如何扩展以提供test中不存在的功能,包括全局模式匹配和本机正则表达式支持。

或者,在the Conditional Constructs section of the bash manual中查找[[…]]

顺便提一句,POSIX sh相当于:

case $_DIR in
  {{*) echo "put the true branch here" ;;
  *)   echo "put the false branch here" ;;
esac