Bash heredoc on FD 3
cyg Simple
cygsimple@gmail.com
Mon Dec 3 15:56:00 GMT 2018
On 12/3/2018 10:43 AM, cyg Simple wrote:
>
> On 12/2/2018 1:43 PM, 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?
>
> Same for me and interestingly:
>
> $ ls -ld /dev/fd/*
> ls: cannot access '/dev/fd/3': No such file or directory
> ls: cannot access '/dev/fd/31': No such file or directory
> lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:39 /dev/fd/0 -> /dev/pty2
> lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:39 /dev/fd/1 -> /dev/pty2
> lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:39 /dev/fd/2 -> /dev/pty2
And:
$ dash -c '/bin/ls -l /dev/fd/'
total 0
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 0 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 1 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 2 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 3 -> /proc/27356/fd
$ dash -c '/bin/ls -l /dev/fd/'
total 0
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 0 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 1 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 2 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:51 3 -> /proc/18740/fd
So in Bash the process is no longer available. Adding -d to the above:
$ dash -c '/bin/ls -ld /dev/fd/*'
/bin/ls: cannot access '/dev/fd/3': No such file or directory
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:50 /dev/fd/0 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:50 /dev/fd/1 -> /dev/pty2
lrwxrwxrwx 1 eboyd53 eboyd53 0 Dec 3 10:50 /dev/fd/2 -> /dev/pty2
--
cyg Simple
--
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
More information about the Cygwin
mailing list