[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

'bash -n' - extended pattern matching - case buitin: problem with syntax check script



Good day!

I've been writing a bash function to check the syntax of other bash scripts (using ´bash -n'), before loading them with the ´source' builtin. Everything runs fine, until I use extended pattern matching in combination with the ´case' builtin.

System: Debian linux 4.0
Bash version: GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)

Here's my testing script:

The file (script) to be checked:
----------------------------------------------------------------------
#!/bin/bash
foo="${1}"
shopt -s extglob

case "${foo}" in
   foo) echo foo ;;
   bar) echo bar ;;
   +([[:digit:]])) echo extglob_test ;;
esac
----------------------------------------------------------------------

The syntax check function:
----------------------------------------------------------------------
#!/bin/bash
shopt -s extglob

syntax_check()
{
echo "checking syntax in ${1}"
"${SHELL}" -n "${1}" || { echo  "Syntax errors in \"${1}\"."; return 1; }
}

syntax_check $1

# running it normaly, returns NO ERROR:
./${1} 666
----------------------------------------------------------------------

OUTPUT:
eris:~/myscripts# ./syntax_check syntax_check_input
checking syntax in syntax_check_input
syntax_check_input: line 11: syntax error near unexpected token `('
syntax_check_input: line 11: `  +([[:digit:]])) echo extglob_test ;;'
eris:~/myscripts#

Running the script to be checked normaly, works fine, so I assume using extended pattern matching this way is legal.

My questions are:

1: Am I doing something wrong in the script?
2: If not, can we call this a bug?
3: If it's a bug, can someone tell me, if it exists in newer bash versions?

Thanks for your help!

Greets

Mart


Reply to: