View Full Version : [SOLVED] Pattern matching in bash doesn't seem to work in a script

Paddy Landau
October 5th, 2009, 04:29 PM
I'm having a big problem with pattern matching in Bash.

Consider the following two lines, which I type into a terminal.

echo ${zn//+([[:digit:]])/} # Remove all digitsThe output is a single 'x', which is what I expect.

However, if I copy those exact lines into a script, as follows...

echo ${zn//+([[:digit:]])/} # Remove all digitsThen the output from the script is '2560x1024'.

Why the difference?

October 5th, 2009, 04:48 PM
extglob (extended pattern matching) is probably disabled in the subshell started by the script and is enabled in your regular shell:
enable it with:
shopt -s extglob


you can also use your regular shell by starting the script with source or .

Paddy Landau
October 5th, 2009, 04:54 PM
+1 -- Thank you! I would never have worked that out myself.