Consider the following GNU shell parameter expansion on a bash command line, which is explained here:
$ a='hello world example'
$ echo ${a//+( )/_}
hello_world_example
However, that very same parameter expansion no longer works in a bash script.
# !/usr/bin/env bash
a='hello world example'
echo "${a//+( )/_}"
It results in the unaltered string:
hello world example
I did already learn from a simpler parameter expansion that the double quotes " " after the echo command are required, although I do not know why.
However, what more needs to be done for this particular parameter expansion to work in a bash script? And why?