Regex and if in shell script -


my programs starts services , store output in tmp variable , want match variable's content if starts fatal keyword or not? , if contains print port in use using echo command

for example if tmp contains fatal: exception in startup, exiting.

i can sed: echo $tmp | sed 's/^fatal.*/"port in use"/'

but want use builtin if match pattern. how can use shell built in features match regex?

posix shell doesn't have regular expression operator unix ere or pcre. have case keyword:

case "$tmp" in   fatal*) dosomethingdrastic;;   *) dosomethingnormal;; esac 

you didn't tag question bash, if have shell can other kinds of pattern matching or ere:

if [[ "$tmp" = fatal* ]];     … fi 

or

if [[ $tmp =~ ^fatal ]];     … fi 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -