我正在使用 BASH 3.2。我可以从命令行执行以下命令:
$ build_number=23332
$ if [[ $build_number != +([0-9]) ]]
> then
> echo "Bad Build Number ($build_number). No CPU time for you!"
> else
> echo "Build Number ($build_number) is numeric"
> fi
Build Number (2332) is numeric"
如果我更改build_number to
23332a`,则返回:
Bad Build Number (23332a). No CPU time for you!
现在,我将尝试将其放入我的 shell 脚本中:
#! /bin/bash
...
#
# Set options
#
while getopts :hu:j:b:p: option
do
case $option in
p) promotion_name="$OPTARG";;
u) jenkins_url="$OPTARG";;
j) job_name="$OPTARG";;
b) build_number="$OPTARG"
if [[ $build_number != +([0-9]) ]]
then
error "Build Number must be numeric"
fi
;;
h) printf "\n$USAGE\n"
exit 0;;
*) error "Invalid Argument";;
esac
done
shift $(( $OPTIND - 1 ))
当我尝试执行我的程序时,我收到以下错误:
$ ./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]) ]]'
那么,我做错了什么?