There is a script:
#!/bin/bash
s='1 2, 3 4,'
s0="$(echo ${s//,/ }|tr -s ' ')"
echo "s0: $s0"
d="'${s0//+([[:space:]])/"' '"}'"
echo "d: $d"
When I run this script output is:
$ ./test.sh
s0: 1 2 3 4
d: '1 2 3 4'
When I run the commands one by one in bash prompt, the $d variable is displayed properly:
$ s='1 2, 3 4,'
$ s0="$(echo ${s//,/ }|tr -s ' ')"
$ echo "s0: $s0"
s0: 1 2 3 4
$ d="'${s0//+([[:space:]])/"' '"}'"
$ echo "d: $d"
d: '1' '2' '3' '4'
$
Commands are run in bash:
$ type bash
bash is /bin/bash
$ echo $0
-bash
Why the $d during script run is set to '1 2 3 4' and not as expected '1' '2' '3' '4' ?