Thursday, 15 May 2014

regex - Case insensitive condition in Bash -



regex - Case insensitive condition in Bash -

i using case in bash script, wondering regular expressions match lower case or upper case words cases.

ex:

case $name in john) echo "hi" ;; joe) echo "bye" ;; *) echo "nothing" ;; esac

i want match john if $name equal john.

thank you

you can use:

shopt -s nocasematch

testing:

s='john' shopt -s nocasematch [ "$s" == "john" ]] && echo "matched" || echo "no match" matched shopt -u nocasematch [ "$s" == "john" ]] && echo "matched" || echo "no match" no match

regex bash case condition

No comments:

Post a Comment