mainThe GNU Bourne-Again SHell - Support: sr #110743, odd behavior of process...


sr #110743: odd behavior of process substitution in `for` list

Submitter:  None
Submitted:  Mon 17 Oct 2022 01:25:30 AM UTC
Category:  None Priority:  5 - Normal
Severity:  2 - Minor Status:  Done
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux
* Mandatory Fields

Add a New Comment Rich Markup

Thu 20 Oct 2022 06:05:38 PM UTC, comment #1: 

Thanks for the report. Bash was too eager to close the process substitution file descriptors; it needs to wait until the for command completes.

It's a minor problem with a relatively easy fix. The fix will be in the next devel branch push.

Chet Ramey <chet>
Group administrator
Mon 17 Oct 2022 01:25:30 AM UTC, original submission:  

While playing around with process substitution I encountered the following corner case:

$ for i in <(echo 1) <(echo 2); do cat $i; done
cat: /dev/fd/62: No such file or directory

$ true; for i in <(echo 1) <(echo 2); do cat $i; done

I expected that either both `cat` invocations would succeed (as happens in the second command), or they would both fail (so the auxiliary FDs would be closed after evaluating the list of the `for` loop). For what it's worth, in `zsh` they both succeed.

The actual behavior is surprising for two reasons:

  • the second command behaves differently from the first
  • the first command closes the auxiliary FDs for the process substitution between the first and second loop iterations (this can be confirmed by running the shell with `strace -eclose`)

Note: as far as I can tell, this is not a race; extending the lifetime of the subprocesses with `sleep` makes no difference.

Anyway, is there a bug lurking here? I cannot, as a user, explain the fact why the two commands are different. But on the other hand this is a corner case that I feel noone should rely on for serious scripting, so it's a minor bug at worst.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-20 chet StatusNone Done

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code