zsh-workers
 help / color / mirror / code / Atom feed
From: Zefram <zefram@fysh.org>
To: schaefer@candle.brasslantern.com (Bart Schaefer)
Cc: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: 3.0.6/3.1.6: Re: All sorts of file-descriptor strangeness
Date: Sun, 10 Oct 1999 14:35:56 +0100 (BST)	[thread overview]
Message-ID: <E11aJ8m-0004lr-00@crucigera.fysh.org> (raw)
In-Reply-To: <991010082734.ZM31398@candle.brasslantern.com> from Bart Schaefer at "Oct 10, 1999  8:27:34 am"

Bart Schaefer wrote:
>                      that is, both ">& foo" and "&> foo" are shorthand
>for "> foo 2>&1",

Not the main topic of this thread, but that's not quite true.  It *used*
to be that way, until someone pointed out that this gave ">& foo" the
wrong behaviour with multios.  Now >& (and &>) are handled specially:
they redirect both stdout (or other specified fd) and stderr to the
specified file.  More precisely, ">& foo" has the behaviour of "9>
foo >&9 2>&9 9>&-", where "9" is any spare file descriptor.  You can
see the difference thus:

% { echo out; echo err >&2; } > foo >& bar

This puts "out" into foo and bar, but "err" into bar only.  Replacing ">&
bar" with "> bar 2>&1" gives you "out" and "err" in both files.

The documentation needs to be fixed (patch to follow).

>} The number on the right, on the other
>} hand, can be as many digits long as you like, and can even have whitespace
>} in front of it, and still zsh happily converts it to an integer and tries
>} to dup() it.
...
>                                so although you can grab a copy of a one
>of the internal file descriptors, the worst thing you can do with it is
>clobber one or more of stdin/out/err with it.  So no fix is needed here.

This is something I've always been dubious about.  One of the things I
planned to do in my CFT was to implement a syntax allowing redirection of
arbitrary file describtors, rather than just fds 0 to 9.  A consequential
requirement would be that the shell gets its private fds out of the way
whenever the user refers to a specific fd number, so this phenomenon
of the shell's fds becoming visible to the user would never occur.
I designed the Elate shell to do this from the very start -- it's not
hard -- but there are some nasty issues involved in retrofitting it to
a shell not designed that way.

I think it would be better to enforce a strict distinction between the
user's fds and the shell's.  Since the situation at the moment is that
fds 0 to 9 are the user's, I think fds on the RHS of a dup redirection
should be limited to this range.  (Patch to follow.)

-zefram


  reply	other threads:[~1999-10-10 13:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-05  9:45 Bart Schaefer
1999-10-10  8:27 ` PATCH: 3.0.6/3.1.6: " Bart Schaefer
1999-10-10 13:35   ` Zefram [this message]
1999-10-10 15:54     ` Bart Schaefer
1999-10-10 16:39       ` PATCH: Re: PATCH: no more fd mixups Bart Schaefer
1999-10-10 17:53         ` Zefram
1999-10-10 21:11           ` PATCH: 3.0.6/3.1.6: Re: All sorts of file-descriptor strangeness Bart Schaefer
1999-10-11  8:12             ` Zefram
1999-10-10 17:41       ` Zefram
1999-10-10 14:35 PATCH: no more fd mixups Zefram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E11aJ8m-0004lr-00@crucigera.fysh.org \
    --to=zefram@fysh.org \
    --cc=schaefer@candle.brasslantern.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).