delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2018/12/05/01:55:28

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:message-id:from:reply-to:to:subject
:references:in-reply-to:content-type; q=dns; s=default; b=N58rJq
e6pLGaADylC9n3isn/qY0n+o14RY9KThKtVhDfl4xeOLBuR32Jppk8Es49JUq6MA
UoOP6+HPqd+LmSuDtYxbeCRwjZ/AixUU4QtGxhDs7UjBwg7Mu9athUw8T7LlGPb0
6i5pAugrGWlf+MMyRWVxOmMIoRrbp8ujLOOxk=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:message-id:from:reply-to:to:subject
:references:in-reply-to:content-type; s=default; bh=KRPQc4Xtjhse
hO7fha22y4fTAY0=; b=MuZKNFw3YCZSIXMhcmau0CzNwVIihUls1YmU65ryUYEF
TePuYaNr8XIbpJip+yTobyFKq1dUhcjMtA8kF22uQhDJe5VCqEgHWo6fnuxf2Ywv
idwOEnju4xn0/lDypT5fR+BtH0vPYV51Hvpyf7aIjisF3KT7QWJINLr9ETP0/xM=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=BAYES_05,GIT_PATCH_2,KAM_NUMSUBJECT,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=cygwincom, cygwin.com, UD:cygwin.com, eboyd53
X-HELO: lb2-smtp-cloud7.xs4all.net
Date: Wed, 05 Dec 2018 07:55:08 +0100
Message-ID: <a49f2bd94a42acbb383b917f2f96c3ac@smtp-cloud7.xs4all.net>
From: Houder <houder AT xs4all DOT nl>
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
Subject: Re: Bash heredoc on FD 3
References: <5c0427c5 DOT 1c69fb81 DOT d71e5 DOT c8ec AT mx DOT google DOT com> <c6d1ba2d6a7a0daa32aee92f806a30dd AT smtp-cloud7 DOT xs4all DOT net> <f720272e-c246-e807-d9a5-1cbccbd36a62 AT gmail DOT com>
In-Reply-to: <f720272e-c246-e807-d9a5-1cbccbd36a62@gmail.com>
User-Agent: mua.awk 0.99

On Tue, 4 Dec 2018 09:21:55, cyg Simple  wrote:

> Dash is faster in processing the data but can be made to fail if you
> add -d to the ls commands you're using. 

?

Oh, I believe you refer to:

    https://cygwin.com/ml/cygwin/2018-12/msg00035.html
    ( Re: Bash heredoc on FD 3 )

> 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

uhm, the facts are slightly different ...

/dev/fd is, well, a "moving target", it is symlnk to /proc/self/fd.

self refers to the "current process" ... it changes each time.

/proc/self/fd shows the open fd's of the current process ...

Currently, I am on Linux (Fedora) ...

@@ # currently I am executing the shell (bash)
@@ # self points to the procid of my bash ...

@@ printf "%s\n" /dev/fd/*
/dev/fd/0
/dev/fd/1
/dev/fd/10
/dev/fd/11
/dev/fd/2
/dev/fd/255
/dev/fd/3

@@ # however ls has NO open fd 3 if I invoke it like this:
@@ # (self points to the procid of my ls command)

@@ ls -ld /dev/fd/* # /dev/fd/* expands to the list above (bash)
ls: cannot access '/dev/fd/255': No such file or directory
ls: cannot access '/dev/fd/3': No such file or directory
lrwx------ 1 henri henri 64 Dec  5 07:26 /dev/fd/0 -> /dev/pts/0
lrwx------ 1 henri henri 64 Dec  5 07:26 /dev/fd/1 -> /dev/pts/0
lrwx------ 1 henri henri 64 Dec  5 07:26 /dev/fd/10 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:26 /dev/fd/11 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:26 /dev/fd/2 -> /dev/pts/0

@@ # ls HAS an open fd 3 if I invoke it like this:
@@ (# use strace to see it happen -- ls opens the directory)

@@ ls -lL /dev/fd # /dev/fd refers to /proc/self/fd
total 0
crw-------  1 henri tty   136, 0 Dec  5 07:38 0
crw-------  1 henri tty   136, 0 Dec  5 07:38 1
crw-rw----+ 1 root  video 226, 0 Dec  5 07:01 10
crw-rw----+ 1 root  video 226, 0 Dec  5 07:01 11
crw-------  1 henri tty   136, 0 Dec  5 07:38 2
dr-x------  2 henri henri      0 Dec  5 07:38 3
@@ ls -l /proc/self/fd
total 0
lrwx------ 1 henri henri 64 Dec  5 07:38 0 -> /dev/pts/0
lrwx------ 1 henri henri 64 Dec  5 07:38 1 -> /dev/pts/0
lrwx------ 1 henri henri 64 Dec  5 07:38 10 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:38 11 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:38 2 -> /dev/pts/0
lr-x------ 1 henri henri 64 Dec  5 07:38 3 -> /proc/2605/fd

Same w/ dash:

@@ dash
$ printf "%s\n" /dev/fd/*
/dev/fd/0
/dev/fd/1
/dev/fd/10
/dev/fd/11
/dev/fd/12
/dev/fd/17
/dev/fd/18
/dev/fd/2
/dev/fd/3
/dev/fd/55
$ ls -ld /dev/fd/*
ls: cannot access '/dev/fd/12': No such file or directory
ls: cannot access '/dev/fd/3': No such file or directory
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/0 -> /dev/pts/3
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/1 -> /dev/pts/3
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/10 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/11 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/17 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/18 -> /dev/dri/card0
lrwx------ 1 henri henri 64 Dec  5 07:25 /dev/fd/2 -> /dev/pts/3
lr-x------ 1 henri henri 64 Dec  5 07:25 /dev/fd/55 -> /home/b/henri/.local/share/baloo/index

=====


--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019