Seems like a bit of sloppy programming on behalf of the bash source coders. Can't help but think that this bug has revealed how unsophisticated and vulnerable the importing of exported variables and functions in bash is, and that there is more trouble to come.
Have to wait for the release of babash (Born Again Born Again SHell)
I love a good explosion in a punctuation factory, and seeing that there are going to be a lot of old legacy systems lying around that are going to take some effort or a while to patch I thought I'd have a go at trying to come up with a work around for this problem.
My understanding is that the problem stems from the command line parser which executes poorly when spawning a new shell in conjunction with preserving exported functions.
So my approach is to help with the parsing by cleaning up the functions before they are exported.
After about one hours effort I came up with this basic approach:
# This function overloads (in C++ lingo) the export function
# Declare this in your scripts, or introduce in a wrapper,
# or add to bashrc.
#
# Disable bash's builtin export function before defining the new function.
enable -n export
# Define the new export function
export() {
# Step 1: Disable the bash builtin export function
enable -n export
# Step 2: Clean any exported function of nasties before export
# - lots of room for improvement here, this is just one basic idea.
pruned_variable=`echo "$*" | gawk 'BEGIN { RS="}" ; isafunc=0 ; prev_rec="" }
{ if(index($0, "()")) isafunc=1 ;
printf("%s", prev_rec) ;
prev_rec = $0 }
END { if(isafunc) { print "};" } else { print $0 } }'`
# Step 3: Debug - uncomment to debug
#echo "$pruned_variable"
# Step 4: Now we can export the cleaned up function
enable -a export
builtin export "$pruned_variable"
enable -n export
}
# Now export the new export function for use in child processes.
enable -a export
builtin export -f export
enable -n export
I bet a few here can see a way of beating step 2, but this is really basic and here just to give you an idea. This bit has been deliberately left lean and mean and more parsing/cleaning effort would be required for it to be implemented on a serious old legacy system.
I've tested this with basic examples I've found on the net and it works fine for my old unix implementations.
If you are running newer systems then you are much better off installing the latest bash patches.