regex - Regular expressions in a Bash case statement -


i using following script, uses case statement find server.

    #!/bin/bash server=$1; echo $server | egrep "ws-[0-9]+\.host\.com"; case $server in ws-[0-9]+\.host\.com) echo "web server" ;; db-[0-9]+\.host\.com) echo "db server" ;; bk-[0-9]+\.host\.com) echo "backup server" ;; *)echo "unknown server" ;; esac 

but not working. regex working egrep not case. sample o/p

./test-back.sh ws-23.host.com ws-23.host.com unknown server 

any idea ?

bash case not use regular expressions, shell pattern matching only.

therefore, instead of regex ws-[0-9]+\.host\.com should use pattern ws*.host.com (or ws-+([0-9]).host.com, looks bit advanced , i've never tried :-)


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -