BASH: Pattern match not working -
i using bash 3.2. can execute following command line:
$ build_number=23332 $ if [[ $build_number != +([0-9]) ]] > > echo "bad build number ($build_number). no cpu time you!" > else > echo "build number ($build_number) numeric" > fi build number (2332) numeric"
if change build_number to
23332a`, returns:
bad build number (23332a). no cpu time you!
now, i'll try put shell script:
#! /bin/bash ... # # set options # while getopts :hu:j:b:p: option case $option in p) promotion_name="$optarg";; u) jenkins_url="$optarg";; j) job_name="$optarg";; b) build_number="$optarg" if [[ $build_number != +([0-9]) ]] error "build number must numeric" fi ;; h) printf "\n$usage\n" exit 0;; *) error "invalid argument";; esac done shift $(( $optind - 1 ))
when try execute program, following error:
$ ./promotion.sh -b 238d -jasdad ./promotion.sh: line 55: syntax error in conditional expression: unexpected token `(' ./promotion.sh: line 55: syntax error near `+([' ./promotion.sh: line 55: ` if [[ $build_number != +([0-9]) ]]'
so, doing wrong?
you need enable extended globbing:
shopt -s extglob
Comments
Post a Comment