我有一个变量$projectName
如何检查它是否以此字符串'testProject'开头
您可以在BASH中使用此检查:
[[ "$projectName" == "testProject"* ]]
You can for example use:
[[ "$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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.