On 7/5/24 4:38 PM, Emanuele Torre wrote:

More funny things have been discovered since.

It has been brought up when discussing this in the #bash IRC channel of
irc.libera.chat, that if you run   eval '<file'   in $(), the contents
of file are output to stdout, in every version of bash since it was
introduced.

This is a consequence of using the same code for a number of things: the
same function handles command substitution, process substitution, running
traps, eval, mapfile, source, fc, and other things (basically any time you
take a string and evaluate it); there isn't enough detection of the
specific case of command substitution we're talking about here.


So you can for example use this to concatenate two files in pure bash;
like $(cat <f; cat <g):

Yeah, this is clearly not the intent of the feature, but more an accident
of the implementation and the different uses of this function leaking
into each other.

I have also noticed that if you source a file from $() and the last
logical line of that file contains only a simple command with only one
read-only stdin redirection, bash will also print out that file, again,
in all versions of bash with $(<):

I'm not sure how this can be considered anything but a bug, no matter how
long it's existed.

The best thing to do is probably to remove this (legacy) code from that
common function; with the re-implmentation of command substitution parsing
in bash-5.2, the documented usage doesn't go through that code path any
more.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to