zsh-workers
 help / color / mirror / code / Atom feed
From: Alexandre Duret-Lutz <duret_g@epita.fr>
To: zsh-workers@math.gatech.edu
Subject: *suggestion* for NULLCMD and emulate [ck]sh
Date: 08 Feb 2000 11:54:31 +0100	[thread overview]
Message-ID: <mvbog9sotg8.fsf@phobos.lrde.epita.fr> (raw)

I'm sure this must have already been discussed on the list,
but I couldn't find anything on this in the archive.

When doing redirections with no file, shells can show three behaviours:

> file

is equivalent to 

[k]sh)     : > file
csh)       forbiden
zsh)       $NULLCMD > file

Zsh can emulate the to first by setting NULLCMD to ':' or unsetting NULLCMD.

The documentation say 

       The standard Bourne shell behaviour is obtained by setting
       NULLCMD and READNULLCMD to `:'.  This is the default  when
       zsh is emulating sh or ksh.

which is quite wrong.  This is the default only when zsh is *started*
as sh or ksh, since the builtin `emulate' won't modify the parameter
NULLCMD.

What I would like zsh do is:

~/tmp/tmp % > foo                                                      11:30 #1
bar
~/tmp/tmp % emulate sh                                                 11:31 #2
~/tmp/tmp % > foo                                                      11:31 #3
~/tmp/tmp % emulate csh                                                11:31 #4
~/tmp/tmp % > foo                                                      11:31 #5
zsh: redirection with no command
~/tmp/tmp %                                                            Err 1 #6

Presently this is not the case.

I thought this could be accomplished by adding two options to zsh,
one would tell wether the NULLCMD parameter should be considered 
or not by the exec.c code, and the other could say what the
default behaviour (sh or csh) when NULLCMD is unset.

We would have

               [k]sh  csh  zsh
IGNORE_NULLCMD   on   on   off
SH_NULLCMD       on   off  off

I'm not sure this is the right way to handle this. You will
certainly have better ideas.  Anyway, the patch below is my
attempt to implement this.

Index: Src/zsh.h
--- Src/zsh.h Thu, 03 Feb 2000 00:03:47 +0100 Alexandre
+++ Src/zsh.h Tue, 08 Feb 2000 11:47:38 +0100 Alexandre
@@ -1301,6 +1301,7 @@
     HUP,
     IGNOREBRACES,
     IGNOREEOF,
+    IGNORENULLCMD,
     INCAPPENDHISTORY,
     INTERACTIVE,
     INTERACTIVECOMMENTS,
@@ -1352,6 +1353,7 @@
     SHFILEEXPANSION,
     SHGLOB,
     SHINSTDIN,
+    SHNULLCMD,
     SHOPTIONLETTERS,
     SHORTLOOPS,
     SHWORDSPLIT,
Index: Src/options.c
--- Src/options.c Fri, 31 Dec 1999 13:32:44 +0100 Alexandre
+++ Src/options.c Tue, 08 Feb 2000 11:47:39 +0100 Alexandre
@@ -134,6 +134,7 @@
 {NULL, "hup",		      OPT_EMULATE|OPT_ZSH,	 HUP},
 {NULL, "ignorebraces",	      OPT_EMULATE|OPT_SH,	 IGNOREBRACES},
 {NULL, "ignoreeof",	      0,			 IGNOREEOF},
+{NULL, "ignorenullcmd",	      OPT_EMULATE|OPT_NONZSH,	 IGNORENULLCMD},
 {NULL, "incappendhistory",    0,			 INCAPPENDHISTORY},
 {NULL, "interactive",	      OPT_SPECIAL,		 INTERACTIVE},
 {NULL, "interactivecomments", OPT_BOURNE,		 INTERACTIVECOMMENTS},
@@ -185,6 +186,7 @@
 {NULL, "shfileexpansion",     OPT_EMULATE|OPT_BOURNE,	 SHFILEEXPANSION},
 {NULL, "shglob",	      OPT_EMULATE|OPT_BOURNE,	 SHGLOB},
 {NULL, "shinstdin",	      OPT_SPECIAL,		 SHINSTDIN},
+{NULL, "shnullcmd",           OPT_EMULATE|OPT_BOURNE,	 SHNULLCMD},
 {NULL, "shoptionletters",     OPT_EMULATE|OPT_BOURNE,	 SHOPTIONLETTERS},
 {NULL, "shortloops",	      OPT_EMULATE|OPT_NONBOURNE, SHORTLOOPS},
 {NULL, "shwordsplit",	      OPT_EMULATE|OPT_BOURNE,	 SHWORDSPLIT},
Index: Src/init.c
--- Src/init.c Mon, 07 Feb 2000 17:48:28 +0100 Alexandre
+++ Src/init.c Tue, 08 Feb 2000 11:47:40 +0100 Alexandre
@@ -666,17 +666,8 @@
     mypid = (zlong) getpid();
     term  = ztrdup("");
 
-    /* The following variable assignments cause zsh to behave more *
-     * like Bourne and Korn shells when invoked as "sh" or "ksh".  *
-     * NULLCMD=":" and READNULLCMD=":"                             */
-
-    if (emulation == EMULATE_KSH || emulation == EMULATE_SH) {
-	nullcmd     = ztrdup(":");
-	readnullcmd = ztrdup(":");
-    } else {
-	nullcmd     = ztrdup("cat");
-	readnullcmd = ztrdup("more");
-    }
+    nullcmd     = ztrdup("cat");
+    readnullcmd = ztrdup("more");
 
     /* We cache the uid so we know when to *
      * recheck the info for `USERNAME'     */
Index: Src/exec.c
--- Src/exec.c Tue, 08 Feb 2000 10:59:23 +0100 Alexandre
+++ Src/exec.c Tue, 08 Feb 2000 11:48:13 +0100 Alexandre
@@ -1661,11 +1661,16 @@
 		    } else if (varspc) {
 			nullexec = 2;
 			break;
-		    } else if (!nullcmd || !*nullcmd ||
-			       (cflags & BINF_PREFIX)) {
+		    } else if (((!nullcmd || !*nullcmd || opts[IGNORENULLCMD])
+				&& !opts[SHNULLCMD]) 
+			       ||(cflags & BINF_PREFIX)) {
 			zerr("redirection with no command", NULL, 0);
 			errflag = lastval = 1;
 			return;
+		    } else if (!nullcmd || !*nullcmd || opts[IGNORENULLCMD]) {
+			if (!args)
+			    args = newlinklist();
+			addlinknode(args, dupstring(":"));
 		    } else if (readnullcmd && *readnullcmd &&
 			       ((Redir) peekfirst(redir))->type == READ &&
 			       !nextnode(firstnode(redir))) {
Index: Doc/Zsh/redirect.yo
--- Doc/Zsh/redirect.yo Fri, 31 Dec 1999 13:32:44 +0100 Alexandre
+++ Doc/Zsh/redirect.yo Tue, 08 Feb 2000 11:48:19 +0100 Alexandre
@@ -198,6 +198,8 @@
 sect(Redirections with no command)
 vindex(NULLCMD, use of)
 vindex(READNULLCMD, use of)
+pindex(IGNORE_NULLCMD, use of)
+pindex(SH_NULLCMD, use of)
 If a simple command consists of one or more redirection operators
 and zero or more parameter assignments, but no command name, and the
 parameter tt(NULLCMD) is not set, an error is caused.  If the parameter
@@ -212,6 +214,15 @@
 shows the contents of tt(file) on standard output, with paging if that is a
 terminal.  tt(NULLCMD) and tt(READNULLCMD) may refer to shell functions.
 
-The standard Bourne shell behaviour is obtained by setting tt(NULLCMD) and
-tt(READNULLCMD) to `tt(:)'.  This is the default when zsh is emulating bf(sh)
-or bf(ksh).
+The above default behaviour can be affected by the options
+tt(IGNORE_NULLCMD) and tt(SH_NULLCMD).  tt(SH_NULLCMD) forces the Bourne
+shell behaviour when the parameter tt(NULLCMD) is not set (i.e. the
+implicit command used with the redirections is `tt(:)'), while
+tt(IGNORE_NULLCMD) is used to obtain the same behaviour as if tt(NULLCMD)
+was unset.
+
+The standard Bourne shell behaviour is obtained by setting the options
+tt(IGNORE_NULLCMD) and tt(SH_NULLCMD).  This is the default when zsh is
+emulating bf(sh) or bf(ksh).  The tt(csh) behaviour can be obtained by
+setting only tt(IGNORE_NULLCMD), which is the default when emulating
+bf(csh).
Index: Doc/Zsh/options.yo
--- Doc/Zsh/options.yo Fri, 31 Dec 1999 13:32:44 +0100 Alexandre
+++ Doc/Zsh/options.yo Tue, 08 Feb 2000 11:48:21 +0100 Alexandre
@@ -533,6 +533,13 @@
 However, ten consecutive EOFs will cause the shell to exit anyway,
 to avoid the shell hanging if its tty goes away.
 )
+pindex(IGNORE_NULLCMD)
+vindex(NULLCMD, ignoring)
+vindex(READNULLCMD, ignoring)
+item(tt(IGNORE_NULLCMD) <C> <K> <S>)(
+The values of tt(NULLCMD) and tt(READNULLCMD) are not used when running
+redirections with no commands (see noderef(Redirection)).
+)
 pindex(INC_APPEND_HISTORY)
 cindex(history, incremental appending to a file)
 item(tt(INC_APPEND_HISTORY))(
@@ -977,6 +984,14 @@
 running - that is purely an indicator of whether on not commands are
 em(actually) being read from standard input.
 The value of this option cannot be changed anywhere other than the command line.
+)
+pindex(SH_NULLCMD)
+cindex(sh, redirections with no command)
+cindex(ksh, redirections with no command)
+item(tt(SH_NULLCMD) <K> <S>)(
+If the variable tt(NULLCMD) is unset or if the option tt(IGNORE_NULLCMD) 
+is set, this option make redirections with no command have the
+standard Bourn shell behaviour (see noderef(Redirection)).
 )
 pindex(SH_OPTION_LETTERS)
 cindex(sh, single letter options style)


-- 
Alexandre Duret-Lutz


             reply	other threads:[~2000-02-08 10:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-08 10:54 Alexandre Duret-Lutz [this message]
2000-02-08 18:07 ` Bart Schaefer
2000-02-08 22:42   ` Alexandre Duret-Lutz
2000-02-09 18:54     ` Bart Schaefer

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=mvbog9sotg8.fsf@phobos.lrde.epita.fr \
    --to=duret_g@epita.fr \
    --cc=zsh-workers@math.gatech.edu \
    /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).