I have a variable $projectName how can i check if it starts with this string 'testProject'
2 Answers
You can use this check in BASH:
[[ "$projectName" == "testProject"* ]]
1 Comment
KansaiRobot
Finally something that worked!
You can for example use:
[[ "$projectName" =~ ^testProject ]] && echo "yes"
^
beginning of line
Test
$ var="hello"
$ [[ "$var" =~ ^he ]] && echo "yes" || echo "no"
yes
$ var="ahello"
$ [[ "$var" =~ ^he ]] && echo "yes" || echo "no"
no
2 Comments
Alex Brodov
The 2nd example $ var="ahello" $ [[ "$var" =~ ^he ]] && echo "yes" Should return 'no' because it's not starting with 'he'
fedorqui
@user3502786 well it wasn't returning anything because
|| was not defined. I just did for better understanding.