How to check if a line starts from another in bash?

Very similar, but not duplicated: https://stackoverflow.com/a/16530/

I am in Git Bash 3.1 (at least what appears in the tooltip when entering Bash inside Git bash.

and $ test [["DEV-0" == D*]] || echo 'fail' $ test [["DEV-0" == D*]] || echo 'fail' printing fails.

if [['DEV-0-1' == DEV* ]]; then echo "yes"; says [[DEV-0-1: command not found I am trying to check if git branch returning something that starts with DEV. but I can not apply the answer. is it because all my attempts use the string literal on the left instead of the variable value?

I also tried this on ideone http://ideone.com/3IyEND

and no luck. Almost 14 years have passed since I was familiar with linux.

What am I missing for a line that starts with a test in bash?

+7
source share
2 answers

You missed the space:

  if [[ 'DEV-0-1' == DEV* ]]; then echo "yes"; fi ^^ 
+11
source

I will probably do the verification as follows:

 s1=DEV-0-1 s2=DEV if [ "${s1:0:${#s2}}" == "$s2" ]; then echo "yes" fi 
+6
source

All Articles