regex - Check bash script argument against pattern, and replace a character in it -


i need write bash script checks if first argument supplied script matches glob pattern, in javascript regexp express

^[a-za-z0-9]+\.[a-za-z]{2,}$ 

in other words: starts 1 or more alphabets/digits, followed 1 period, followed 2 or more alphabets, , ends. else should fail test.

then need replace period in argument underscore.

so far can check if argument empty:

case $1 in   '') echo "no argument supplied" >&2; exit 1 ;; esac 

i figure pattern test need negated , put after '' check in case statement, have no clue how construct it. direct or online resources appreciated.

i possible how can change valid argument supplied replace single period in underscore.

same regex works in bash also. consider snippet:

re='^[a-za-z0-9]+\.[a-za-z]{2,}$' s='abc123.xy'  [[ $s =~ $re ]] && echo "${s/./_}" abc123_xy 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -