Why wildcard matching in bash gets different results in bash and source?

Viewed 32

I have a script case 11.2 in +([0-9])?(.+([0-9]))) echo aa;; *) echo bb;; esac

While using source test.sh it prints aa but while using bash test.sh it returns an error

test.sh: line 1: syntax error near unexpected token `('
test.sh: line 1: `case 11.2 in +([0-9])?(.+([0-9])))  echo aa;;   *)  echo bb;; esac'

An workaround is to use bash -i. But why they get different results in interactive and non-interactive mode?

1 Answers

The extended glob patterns (+(...), ?(...), +(...), etc.) require the extglob shell option to be set. Add shopt -s extglob at the beginning of the script.

Related