我有一个变量$projectName
如何检查它是否以此字符串'testProject'开头
答案 0 :(得分:2)
您可以在BASH中使用此检查:
[[ "$projectName" == "testProject"* ]]
答案 1 :(得分:2)
您可以使用:
[[ "$projectName" =~ ^testProject ]] && echo "yes"
^
beginning of line
$ var="hello"
$ [[ "$var" =~ ^he ]] && echo "yes" || echo "no"
yes
$ var="ahello"
$ [[ "$var" =~ ^he ]] && echo "yes" || echo "no"
no