9

非常相似但不重复:https ://stackoverflow.com/a/2172367/57883

我在 Git Bash 3.1 中(至少当我在 git bash.

并且$ test [["DEV-0" == D*]] || echo 'fail'打印失败。

if [['DEV-0-1' == DEV* ]]; then echo "yes";[[DEV-0-1: command not found 我正在尝试测试是否git branch返回以 DEV 开头的内容。但我似乎无法应用答案。是因为我所有的尝试都在左侧使用字符串文字而不是变量值吗?

我也试过 ideone http://ideone.com/3IyEND

没有运气。自从我擅长使用 linux 提示符以来已经有 14 年了。

我在 bash 中以 test 开头的字符串缺少什么?

4

2 回答 2

12

你错过了一个空间:

 if [[ 'DEV-0-1' == DEV* ]]; then echo "yes"; fi
      ^^
于 2013-03-14T19:12:44.640 回答
6

我可能宁愿做这样的检查:

s1=DEV-0-1
s2=DEV

if [ "${s1:0:${#s2}}" == "$s2" ]; then
  echo "yes"
fi
于 2013-03-14T20:54:28.373 回答