#!/bin/bash

mkdir -p ~/gentoo-bug-873931 && cd ~/gentoo-bug-873931 || exit
rm -f -- *.log

f() (
	exec >"$1.log"
	printf 'extglob = '
	shopt -q extglob && printf 'on\n' || printf 'off\n'
	printf "BASHOPTS contains extglob = "
	case :$BASHOPTS: in
		*:extglob:*) printf 'true\n' ;;
		*) printf 'false\n' ;;
	esac
)

printf 'Test #1 (2 comsub levels; BASH_COMPAT unset)\n'
f 1a $(f 2 $(f 3)); f 1b
grep . *.log
printf '\n'

printf 'Test #2 (2 comsub levels; BASH_COMPAT=50)\n'
BASH_COMPAT=50
f 1a $(f 2 $(f 3)); f 1b
grep . *.log
printf '\n'

printf 'Test #3 (3 comsub levels; BASH_COMPAT=50)\n'
f 1a $(f 2 $(f 3 $(f 4))); f 1b
grep . *.log
printf '\n'
