how to use * in sh string comparison -
how correctly use * in sh? tried googling couldn't find anything. following echo ture. why that?
file="test test" if [ "$file" != "te"* ] echo true else echo false fi
to avoid potential problems, when using posix shell, should consider using old expr
regex or match expressions. choices are:
#!/bin/sh file="test test" if [ $(expr "$file" : "te.*") -gt 0 ] echo true else echo false fi
or
if [ $(expr substr "$file" 1 2) = "te" ] echo true else echo false fi
not elegant, proper tools shell. short explanation of each , expr
syntax each is:
string : regularexp : returns length of string if both sides match, returns 0 otherwise match string regularexp : same previous 1 substr string start length : returns substring of string starting start , consisting of length characters
Comments
Post a Comment