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

Re: POSIX shell specification insight requested



Manoj Srivastava wrote:

On Tue, 2 Mar 2004 13:04:43 -0500, Branden Robinson <branden@debian.org>
said:
Is the following construction POSIXly correct?  foo=$(cat <<EOF Foo
bar baz quux.  EOF)

======================================================================
ISO/IEC 9945-2:1993(E)  Information Technology -- POSIX
IEEE Std 1003.2-1993    Part 2: Sheel and utilities

§ 3.6.3  Command substitution

...

lines 474-477

Within the $(command) form, all characters following the open
parenthesis to the  matching closing parenthesis constitute the
/command/. Any valid shell script can be used for /command/, except

 -- A script consisting solely of redirections produces unspecified
results ======================================================================
/solely/ being the key word here, as in:

foo=$(<a >b 2>&1)

	The here document is a redirection, hence the reults of that
command substitution are unspecified.

	manoj
nope. this:
foo=$(cat <<EOF
bab
cac
EOF)

is wrong 'cause the EOF should be alone in its line, so

foo=$(cat <<EOF)
bab
cac
EOF

should work, and so should

foo=$(cat <<EOF
bab
cac
EOF
)

the example in the posix spec says this works:

cat << eof1; cat << eof2
Hello
eof1
Manoj
eof2


[]s, HTH
Massa



Reply to: