zsh-workers
 help / color / mirror / code / Atom feed
* Globbing in redirections
@ 1996-06-06 14:54 Zefram
  1996-06-06 16:25 ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Zefram @ 1996-06-06 14:54 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

This patch makes redirection behave a little more like ksh.
It disables globbing on filenames in redirections, but only when
multios are disabled.  (Globbed redirections are a very useful way
to generate multios.)  Note that behaviour is still not exactly
like ksh, as brace expansion is still done.  But ksh seems to treat
brace expansion as part of globbing: compare "echo ~{root,nobody}"
in the two shells.  (KSH_BRACES, anyone?)

This patch as written relies on my recent large options patch,
that changed the NO_MULTIOS option into MULTIOS.  If you haven't
applied that, change "isset(MULTIOS)" to "unset(NOMULTIOS)".

 -zefram

      Index: Doc/zshmisc.man
      *** zshmisc.man	1996/06/06 01:45:20	1.5
      --- zshmisc.man	1996/06/06 02:05:26
      ***************
      *** 512,517 ****
      --- 512,532 ----
        .PP
        writes the date to the file "foo", and also pipes it to cat.
        .PP
      + If the
      + .B MULTIOS
      + option is set, the word after a redirection operator is also subjected
      + to filename generation (globbing).  Thus
      + .RS
      + .PP
      + .B : > *
      + .RE
      + .PP
      + will truncate all files in the current directory,
      + assuming there's at least one.
      + (Without the
      + .B MULTIOS
      + option, it would create an empty file called "*".)
      + .PP
        If the user tries to open a file descriptor for reading more than once,
        the shell opens the file descriptor as a pipe to a process that copies
        all the specified inputs to its output in the order
      Index: Src/glob.c
      *** glob.c	1996/06/06 01:45:30	1.8
      --- glob.c	1996/06/06 02:06:51
      ***************
      *** 862,868 ****
            addlinknode(fake, fn->name);
            /* ...which undergoes all the usual shell expansions. */
            prefork(fake, 0);
      !     if (!errflag)
        	globlist(fake);
            if (errflag)
        	return 0;
      --- 862,869 ----
            addlinknode(fake, fn->name);
            /* ...which undergoes all the usual shell expansions. */
            prefork(fake, 0);
      !     /* Globbing is only done for multios. */
      !     if (!errflag && isset(MULTIOS))
        	globlist(fake);
            if (errflag)
        	return 0;

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMbY/BHD/+HJTpU/hAQFX1AP8DZcutSWVln2VufviHDskuXPr5MbP5wTi
S2YhTOYPCQ/JCfh2BeQTZXw/k/TNM5vSQC7EawulBEOB42ClMQJdo5IRrReh0HUP
tQNptWP7YVm879YKHp26ka8vl2tmrcqC0J0M3mEqAEFQ124AMRvsJ4cG1bOV1vDz
BiZusin6gj4=
=kDm+
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Globbing in redirections
  1996-06-06 14:54 Globbing in redirections Zefram
@ 1996-06-06 16:25 ` Zoltan Hidvegi
  1996-06-06 16:36   ` Zefram
  0 siblings, 1 reply; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-06-06 16:25 UTC (permalink / raw)
  To: Zefram; +Cc: Zsh workers list

> This patch makes redirection behave a little more like ksh.
> It disables globbing on filenames in redirections, but only when
> multios are disabled.  (Globbed redirections are a very useful way
> to generate multios.)  Note that behaviour is still not exactly
> like ksh, as brace expansion is still done.  But ksh seems to treat
> brace expansion as part of globbing: compare "echo ~{root,nobody}"
> in the two shells.  (KSH_BRACES, anyone?)

No, that's a different problem.  In zsh filename expansion is performed
after most other substitutions while POSIX says that it must be the first
expansion which must be done before $ susbstitutions.  In zsh I can use

USER=hzoli ; echo ~$USER

but this does not work in a POSIX compilant shell.  I'll move filename
expansion before the other substitutions if zsh is invoked as sh/ksh.  Or
maybe an option should control this?  I personally think that the best
would be to do filename expansions first even if zsh is invoked as zsh but
I'm sure that it will break some scripts.  Does anyone have such a script?

Zoltan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Globbing in redirections
  1996-06-06 16:25 ` Zoltan Hidvegi
@ 1996-06-06 16:36   ` Zefram
  1996-06-06 16:48     ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Zefram @ 1996-06-06 16:36 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: A.Main, zsh-workers

>No, that's a different problem.  In zsh filename expansion is performed
>after most other substitutions while POSIX says that it must be the first
>expansion which must be done before $ susbstitutions.  In zsh I can use
>
>USER=hzoli ; echo ~$USER
>
>but this does not work in a POSIX compilant shell.  I'll move filename
>expansion before the other substitutions if zsh is invoked as sh/ksh.  Or
>maybe an option should control this?  I personally think that the best
>would be to do filename expansions first even if zsh is invoked as zsh but
>I'm sure that it will break some scripts.  Does anyone have such a script?

I don't actually have a script that does this, but it's very nice
behaviour, and I do use it from time to time.  I think we should have
another option for this, which would have options
OPT_EMULATE|OPT_BOURNE.  Note that zsh actually follows csh behaviour,
so this really should be OPT_BOURNE and not OPT_NONZSH.  (If you've
never heard of these options, you'll need to check the patch in article
1275.)

However, my original point stands.  ksh doesn't do brace expansion in
redirections.  We need to split up prefork() somewhere -- is there
another function that would be more appropriate to use in this case?
We need all expansions except for brace expansion and globbing, but
prefork() does everything except globbing.

-zefram



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Globbing in redirections
  1996-06-06 16:36   ` Zefram
@ 1996-06-06 16:48     ` Zoltan Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-06-06 16:48 UTC (permalink / raw)
  To: Zefram; +Cc: A.Main, zsh-workers

> However, my original point stands.  ksh doesn't do brace expansion in
> redirections.  We need to split up prefork() somewhere -- is there
> another function that would be more appropriate to use in this case?
> We need all expansions except for brace expansion and globbing, but
> prefork() does everything except globbing.

prefork has a flags argument.  The easiest solution for this case is eg. if
bit is 3 set than do not do brace expansion.

Zoltan



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-06-06 16:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-06-06 14:54 Globbing in redirections Zefram
1996-06-06 16:25 ` Zoltan Hidvegi
1996-06-06 16:36   ` Zefram
1996-06-06 16:48     ` Zoltan Hidvegi

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