[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: weird bug in small for loop and here documents and bash-4.x
From: |
Mike Frysinger |
Subject: |
Re: weird bug in small for loop and here documents and bash-4.x |
Date: |
Mon, 22 Mar 2010 18:21:46 -0400 |
User-agent: |
KMail/1.13.1 (Linux/2.6.33.1; KDE/4.4.1; x86_64; ; ) |
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.