This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bash heredoc on FD 3


On Sun, 02 Dec 2018 10:43:17, Steven Penny  wrote:
> Using this file:
> 
>     $ cat hello.sh
>     awk -f /dev/fd/3 3<<eof
>     BEGIN {
>       print "hello world"
>     }
>     eof
> 
> it runs as expected with Dash:
> 
>     $ dash hello.sh
>     hello world
> 
> However it fails with Bash:
> 
>     $ bash hello.sh
>     awk: fatal: can't open source file `/dev/fd/3' for reading (No such file or
>     directory)
> 
> I tried also with Debian and both Dash and Bash work as expected. What is
> causing Cygwin Bash to fail here?

File to which symlnk /dev/fd/3 refers has "gone"; different from Linux, where
the file is "deleted", but still "available".
(note: dash uses a different implementation)

I used fd 7 in testing. Below the output on Cygwin ... Observe the difference
when executed on Linux.

Henri

hello.sh:

#cat 7<<\EOF 0<&7 # works on both Linux and Cygwin
#cat 7<<\EOF 0<&7 /dev/fd/7 # fails on Cygwin
#ls 7<<\EOF 0<&7 -l /proc/self/fd /tmp /dev/fd/7
ls 7<<\EOF 0<&7 -lL /proc/self/fd /tmp /dev/fd/7
Hello world!
EOF
exit

# Using: ls 7<<\EOF 0<&7 -l /proc/self/fd /tmp /dev/fd/7

64-@@ bash hello.sh
lrwxrwxrwx  1 Henri None 0 Dec  4 12:37 /dev/fd/7 -> /tmp/sh-thd.3PSuc2

/proc/self/fd:
total 0
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 0 -> /tmp/sh-thd.3PSuc2
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 1 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 2 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 3 -> /proc/4972/fd
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 7 -> /tmp/sh-thd.3PSuc2

/tmp:
..

64-@@ dash hello.sh
lrwxrwxrwx  1 Henri None 0 Dec  4 12:37 /dev/fd/7 -> pipe:[4294969740]

/proc/self/fd:
total 0
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 0 -> pipe:[4294969740]
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 1 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 2 -> /dev/pty1
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 3 -> /proc/3740/fd
lrwxrwxrwx 1 Henri None 0 Dec  4 12:37 7 -> pipe:[4294969740]

/tmp:
..

# Using: ls 7<<\EOF 0<&7 -lL /proc/self/fd /tmp /dev/fd/7

64-@@ bash hello.sh
ls: cannot access '/dev/fd/7': No such file or directory
/proc/self/fd:
ls: cannot access '/proc/self/fd/0': No such file or directory
ls: cannot access '/proc/self/fd/7': No such file or directory
total 0
l????????? ? ?     ?         ?            ? 0
crw--w---- 1 Henri None 136, 1 Dec  4 12:39 1
crw--w---- 1 Henri None 136, 1 Dec  4 12:39 2
dr-xr-xr-x 2 Henri None      0 Dec  4 12:39 3
l????????? ? ?     ?         ?            ? 7

/tmp:
..

64-@@ dash hello.sh
prw-------  1 Henri None 0 Dec  4 12:40 /dev/fd/7

/proc/self/fd:
total 0
prw------- 1 Henri None      0 Dec  4 12:40 0
crw--w---- 1 Henri None 136, 1 Dec  4 12:40 1
crw--w---- 1 Henri None 136, 1 Dec  4 12:40 2
dr-xr-xr-x 2 Henri None      0 Dec  4 12:40 3
prw------- 1 Henri None      0 Dec  4 12:40 7

/tmp:
..

=====


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]