Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 7 Mar 2021 15:13:14 -0700
From:      Bob Proulx <bob@proulx.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: which is "better" - /dev/fd or FIFO
Message-ID:  <20210307145622717830089@bob.proulx.com>
In-Reply-To: <YETXFrAz3D8DPvYe@ceres.local>
References:  <YEOMzXyvchUkMmdH@ceres.local> <20210306204633.3be9720a@gumby.homeunix.com> <YETXFrAz3D8DPvYe@ceres.local>

next in thread | previous in thread | raw e-mail | index | archive | help

--mTAnpWVoLNHHGNT2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

tech-lists wrote:
> Thanks for that. It explains partly why it's not enabled by default.
> But I wondered why it's there at all, what is the benefit of that
> functionality (if enabled) over what (in this case, bash-commander) it
> would use in its absence (presumably FIFO)

Twice now you have written /dev/fd or FIFO but I don't see any
connection between those two things.  I don't see a lot of things.
What am I missing?  How is the /dev/fd directory related to bash using
a FIFO?  And FIFO?  Where has a FIFO been mentioned in this thread?

As far as I can tell a default installation of FreeBSD supports the
system level use of /dev/fd and therefore there is no need to have
bash emulation code enabled.  Pretty sure.  Seems like to me.  I
didn't try all of the combinations to prove it.  This following is on
FreeBSD 12 RELEASE.  Since those are real files in the system then any
script for any shell or program may make use of them.

    rwp@outrage:/usr/home/rwp$ ll /dev/fd/
    total 0
    crw-rw-rw-  1 root  wheel  0x1c Feb  7 20:48 0
    crw-rw-rw-  1 root  wheel  0x1e Feb  7 20:48 1
    crw-rw-rw-  1 root  wheel  0x20 Feb  7 20:48 2

    rwp@outrage:/usr/home/rwp$ echo now is the time | cat /dev/fd/0
    now is the time

    rwp@outrage:/usr/home/rwp$ echo now is the time | cat /dev/stdin
    now is the time

Note that the use of /dev/fd is something that a script writer decides
they want to use or not.  It's a new thing in the grand scheme of
geological time and I personally both 1) only rarely ever see its use
in scripts and 2) rather disprove of it because it isn't really a
portable feature.  I have never felt the need to code using it myself.
So personally I would recommend not using it..  I always scrape those
out of scripts whenever I see that people have used them.  YMMV.

Note that bash will internally simulate /dev/fd if a real system one
is not provided.  Pretty sure anyway.  I have definitely used bash and
seen that feature noted even on systems without /dev/fd directory support.

    The /usr/local/share/doc/bash/NEWS file:

        i.  The redirection code now handles several filenames specially:
            /dev/fd/N, /dev/stdin, /dev/stdout, and /dev/stderr, whether or
            not they are present in the file system.

    The /usr/local/share/doc/bash/FAQ file:

        Bash-2.04 introduced the following new features:

        o The redirection code handles several filenames specially:  /dev/fd/N,
          /dev/stdin, /dev/stdout, /dev/stderr

That was bash-2.04 but in 12 Release:

    rwp@outrage:/usr/home/rwp$ type bash
    bash is hashed (/usr/local/bin/bash)

    rwp@outrage:/usr/home/rwp$ bash --version
    GNU bash, version 5.0.11(0)-release (i386-portbld-freebsd12.0)
    ...

So it has been a long time now...

Bob

--mTAnpWVoLNHHGNT2
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEY7Fmg4Qc49wl08brQhr6Jjh/mo4FAmBFT/YACgkQQhr6Jjh/
mo4XUw/9H0ICX7jlxV63P3+KPHZvWjQgV8u4w3B22gFpO2Zn3WowCFZRzZ8uvva4
P2otjNfBYng9lgOudkfQYOYzyf1KXZNMj9BRqJPvmMYb26iSurzLICkrYAerDouq
EnGR3A/wRcfNSGqkWcD2kzsGdcKPFcgnKaouICe3yAfubY9W2tHwS5P4jY4I6fby
cJHkzhc+7ill12Y22ucMi6a3TVD9asFvUp5nNDinwYE4tV7tmKOARvH7f3wBhaTy
5ZKVph9Ow/NmFMigv+GeAbfu/SR+uFfriNhWxHjnFdDqaY8dGIisS4K9wRHWAND1
H7yQaBs4F9N97rgvuz+LMg8vCSIxZP0MSJ6erq059b0LosVE/Qi5cfxq8LSn7ziG
kmEbtewjOtFeRwEFCWVSZ+2Ho+wC7JysXEHoN3X2h/v9WMOVTEWf+KrVM9Qvo3o9
n53ZB+bSo3o86vo8r1vFxfolE281KQLf0zzi/Jkx/3Hh7xBXVdSSbhe0lhIasTxX
IAK1UemUM/uVpk1gf2MAiu0xTjSmGXZJNx/96yDIe90OlKDNYU6MZSfRrBxQRHWH
q/Vn5DglokPEXbS32KTg71ASMeDyrnh+z3unUJGglg3wtaev6s9o8cpVtcLSJuh9
/myvg3PldHMqqMudH8IXZv89NyqxW/ySO1QdtDCE5pb7ZeYaa2Y=
=mMxZ
-----END PGP SIGNATURE-----

--mTAnpWVoLNHHGNT2--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20210307145622717830089>