ok, the trouble is that we take the code, save it via `set`, and then restore it. the assumption is that what bash outputs is equivalent to the original code. bash-4 though does not provide equivalent code.
so here is the reduced test case: $ cat test.sh foo() { rm -f a b c for f in a b c; do cat <<-EOF >> ${f} file EOF done grep . a b c } $ . ./test.sh $ foo a:file b:file c:file $ set | sed -n '/^foo /,/^}/p' > test-set.sh $ . ./test-set.sh $ foo a:file $ cat test-set.sh foo () { rm -f a b c; for f in a b c; do cat >> ${f}; done <<-EOF file EOF grep --colour=auto . a b c } if another command is in the for loop, then the heredoc is correctly lined up the cat and not the end of the for loop. -mike
signature.asc
Description: This is a digitally signed message part.