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

What does [[ $something = {{* ]] do in bash?

在一些 shell 脚本中发现了这个表达式。双花括号星号“{{*”是什么意思?

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

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

这意味着:"if $_DIR" 扩展为以“{{”开头的字符串...

因此,{{* 实际上对 bash 根本没有任何意义,比你写

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

...意味着 {{* 对 bash 比 "all files whose names start with two curly braces" 更有意义。


BashFAQ #31 中搜索 "pattern matching" 以获取有关 [[ 的更多信息以及它如何扩展以提供 test 中不存在的功能,包括 glob 样式模式匹配和本机正则表达式支持。

或者,在 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