bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HERE document mystery


From: Com MN PG P E B Consultant 3
Subject: HERE document mystery
Date: Thu, 15 Dec 2005 14:21:07 +0100

Is this a bug, or just my misunderstanding about the scope of the "HERE"
operator (<<)?
Consider the following program:

echo THIS WORKS
cat <<GOOD | tr -d V= | grep '[0-9]*'
V=1234
abcd
GOOD
echo THIS DOES NOT WORK
foo=$(cat exp_test <<BAD | tr -d V= | grep '[0-9]*')
V=1234
abcd
BAD

When executed, it yields the following output:

THIS WORKS
1234
abcd
THIS DOES NOT WORK
exp_test: line 9: abcd: command not found
exp_test: line 10: BAD: command not found

Obviously, the lines which are supposed to belong to the second HERE
document, are not fed into
the pipe, when the pipe is part of a $(...) output substitution
operation.

Is this the way bash is supposed to behave? Is there an elegant
workaround? I would like to store
the value of such a pipe (of course the example given shows only the
principle) into a variable.
Of course I could do:

cat exp_test <<UGLY  | tr -d V= | grep '[0-9]*' >temp_file
V=1234
abcd
UGLY
foo=$(temp_file)
rm temp_file

but maybe there is a better solution.

Ronald




reply via email to

[Prev in Thread] Current Thread [Next in Thread]