Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process substition in BASH fails. #164

Open
kherge opened this issue Dec 4, 2018 · 19 comments
Open

Process substition in BASH fails. #164

kherge opened this issue Dec 4, 2018 · 19 comments
Assignees

Comments

@kherge
Copy link

kherge commented Dec 4, 2018

Example Script

#!/usr/bin/env bash

while read LINE; do
    echo$LINEdone < <(echo hello)

Expected Result

$ hello

Actual Result

line 5: /dev/fd/62: No such file or directory

References

  1. http://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html#Process-Substitution
  2. https://stackoverflow.com/a/2443120
@tbodt
Copy link
Member

tbodt commented Dec 4, 2018

#148

@tbodt
Copy link
Member

tbodt commented Feb 1, 2019

What's missing now is the very weird (to me) linux behavior where pipe file descriptors appear to be broken symlinks but can actually be opened, and become a second file descriptor for the same pipe.

@xinity
Copy link

xinity commented Jun 18, 2020

@tbodt any hints to fix this ? as an example we can't leverage powerline10k or any advanced (and very useful features) of ZSH :(

Do you need more tests from us ?
let me know :)

Keep up the awesome work, discovered your app few days ago , NIFTY !!!!

@tbodt
Copy link
Member

tbodt commented Jun 18, 2020

The problem is well understood (#164 (comment)) but I am not quite sure how to solve it.

@ghost
Copy link

ghost commented Nov 20, 2020

This is pretty much over my head but I've been looking around a bit and I stumble upon microsoft/WSL#266 which addresses the same thing(?). I'm not sure if it's helpful, but maybe...

@tbodt
Copy link
Member

tbodt commented Nov 20, 2020

Yeah, WSL had the same problem. Not much info there about how they solved it though.

@kherge
Copy link
Author

kherge commented Nov 20, 2020

I apologize that this is also over my head, but maybe it's buried in one or more commits for their kernel? I tried to create a narrow search that could hopefully be a starting point.

@tbodt
Copy link
Member

tbodt commented Nov 20, 2020

The bug report linked is for WSL 1, which is not open source. This was never a problem in WSL 2.

@ghost
Copy link

ghost commented Nov 20, 2020

I wish I was a developer... For what it's worth I asked in the WSL issue if there would be any possibility for them to share how it was solved. I'm not sure how I'm able to help in any other way. The worst that can happen is no one answers or we get a no.

@makakin
Copy link

makakin commented May 29, 2021

Any solution to fix this issue?

@le0-VV
Copy link

le0-VV commented Feb 9, 2022

Is this thread still going? Came across this problem and is now mildly infuriating me

@luyui
Copy link

luyui commented Feb 10, 2022

What's missing now is the very weird (to me) linux behavior where pipe file descriptors appear to be broken symlinks but can actually be opened, and become a second file descriptor for the same pipe.

@tbodt just ran across this issue and dropped a dirty quick fix at #1716
The basic idea is to reuse adhoc_fd and avoid procfs handling the io, thus done some trick in struct mount *find_mount_and_trim_path(char *path) .
There might be rough edges though, but at least these substitution test cases now run without error.

@kamikaze3384

This comment was marked as off-topic.

@saagarjha

This comment was marked as off-topic.

@ryleu
Copy link

ryleu commented Oct 3, 2022

@tbodt there seems to be a solution now, so I'd like to bring this to your attention again.

@annpocoyo
Copy link

What’s weird is that the pipe still gets created.
As seen by running ls /proc/self/fd <(echo “test”), even if you make a symlink to /proc/self/fd from /dev/fd as seen by running ls /dev/fd <(echo “test”). Someone please merge the pull request

@kalebmckale
Copy link

@kalebmckale
Copy link

@annpocoyo: I'm seeing this on mine:

  File: '/dev/fd/63' -> 'anon_inode:[unknown]'
  Size: 0               Blocks: 0          IO Block: 0      symbolic link
Device: 0h/0d   Inode: 17732923551252482  Links: 0
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 1970-01-01 00:00:00.000000000 +0000
Modify: 1970-01-01 00:00:00.000000000 +0000
Change: 1970-01-01 00:00:00.000000000 +0000

when I run stat. The symlink is indeed created, but it's not linked to a pipe as it should be (from what I gather from a bunch of reading I've been doing).

More so, I noticed strangely that running processes in general are not being created as one would expect:

> sleep 1000 &
[1] 221
> lsof -p 221
COMMAND PID USER   FD      TYPE DEVICE   SIZE    NODE NAME
sleep   221 root  cwd   unknown                       /proc/221/cwd (readlink: No such file or directory)
sleep   221 root  rtd   unknown                       /proc/221/root (readlink: No such file or directory)
sleep   221 root  txt       REG    1,8 808104 4317863 /bin/busybox
sleep   221 root    0u      CHR  136,0              3 /dev/pts/0
sleep   221 root    1u      CHR  136,0              3 /dev/pts/0
sleep   221 root    2u      CHR  136,0              3 /dev/pts/0

I'm not sure this is exactly related but since I discovered this during my reading and research, I figured it might be useful?

@rrr9rrr
Copy link

rrr9rrr commented Nov 29, 2024

My testing results:

iPhone7nABEL:~# ls -la <(:) /proc/self/fd
lrwxrwxrwx 0 root root 0 Jan 1 1970 /dev/fd/63 -> 'anon_inode:[unknown]'

/proc/self/fd:
total 0
lrwxrwxrwx 0 root root 0 Jan 1 1970 0 -> /dev/pts/0
lrwxrwxrwx 0 root root 0 Jan 1 1970 1 -> /dev/pts/0
lrwxrwxrwx 0 root root 0 Jan 1 1970 2 -> /dev/pts/0
lrwxrwxrwx 0 root root 0 Jan 1 1970 3 -> /proc/35/fd
lrwxrwxrwx 0 root root 0 Jan 1 1970 63 -> 'anon_inode:[unknown]'
iPhone7nABEL:# ls -la <(:) /dev/fd
lrwxrwxrwx 1 root root 13 Nov 29 07:41 /dev/fd -> /proc/self/fd
lrwxrwxrwx 0 root root 0 Jan 1 1970 /dev/fd/63 -> 'anon_inode:[unknown]'
iPhone7nABEL:
#

iSH 1.3.2 (Build 494)
A66EDE32-51A8-4043-9EC9-DE96DAE58FC7
540F69ED-EB2C-48AA-8F45-05E2B93FDD68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests