zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH] sh/ksh init: don't initialise lowercase parameters
Date: Tue, 28 Jan 2020 16:19:41 +0100	[thread overview]
Message-ID: <b7e2e8a2-87a9-49c9-77ff-e612285b7a30@inlv.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

In POSIX sh and in ksh, it's the convention that lowercase variable 
names are reserved for scripts, and uppercase names may be used by the 
shell or system. So most lowercase zsh parameters are not initialised 
when zsh is invoked as sh or ksh (through a symlink or the --emulate 
option).

However, there are two left that are initialised in sh/ksh mode: 
'histchars' and 'signals'. So this can conflict with POSIX scripts.

Also, if zsh is invoked as sh or ksh, 'histchars' is available whereas 
the 'HISTCHARS' equivalent is not. It seems quite obvious that this 
should be the other way around.

The attached patch makes zsh, when invoked as sh or ksh, not initialise 
'signals', and initialise 'HISTCHARS' instead of 'histchars'. It also 
updates the documentation.

-- 
modernish -- harness the shell
https://github.com/modernish/modernish

[-- Attachment #2: posixnames.patch --]
[-- Type: text/plain, Size: 3722 bytes --]

diff --git a/Doc/Zsh/compat.yo b/Doc/Zsh/compat.yo
index f1be15fee..d085dfaa7 100644
--- a/Doc/Zsh/compat.yo
+++ b/Doc/Zsh/compat.yo
@@ -19,7 +19,7 @@ tt(argv),
 tt(cdpath),
 tt(fignore),
 tt(fpath),
-tt(HISTCHARS),
+tt(histchars),
 tt(mailpath),
 tt(MANPATH),
 tt(manpath),
@@ -30,6 +30,7 @@ tt(PROMPT2),
 tt(PROMPT3),
 tt(PROMPT4),
 tt(psvar),
+tt(signals),
 tt(status),
 tt(watch).
 
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 8daf33d5e..5f772bb50 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -850,7 +850,7 @@ item(tt(SHLVL) <S>)(
 Incremented by one each time a new shell is started.
 )
 vindex(signals)
-item(tt(signals))(
+item(tt(signals) <Z>)(
 An array containing the names of the signals.  Note that with
 the standard zsh numbering of array indices, where the first element
 has index 1, the signals are offset by 1 from the signal number
@@ -1161,7 +1161,7 @@ with the tt(-u) attribute is referenced.  If an executable
 file is found, then it is read and executed in the current environment.
 )
 vindex(histchars)
-item(tt(histchars) <S>)(
+item(tt(histchars) <S> <Z>)(
 Three characters used by the shell's history and lexical analysis
 mechanism.  The first character signals the start of a history
 expansion (default `tt(!)').  The second character signals the
@@ -1173,8 +1173,8 @@ tt(histchars) to characters with a locale-dependent meaning will be
 rejected with an error message.
 )
 vindex(HISTCHARS)
-item(tt(HISTCHARS) <S> <Z>)(
-Same as tt(histchars).  (Deprecated.)
+item(tt(HISTCHARS) <S>)(
+Same as tt(histchars).
 )
 vindex(HISTFILE)
 item(tt(HISTFILE))(
diff --git a/NEWS b/NEWS
index af59cb4e6..9d96ef0d1 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,10 @@ has not changed, but code such as the following:
 should be changed either to use 'return' instead of 'exit', or to have
 the try/always block outside of any function.
 
+If the shell is invoked as sh or ksh (through a symlink or with the
+'--emulate' option), the 'HISTCHARS' parameter is now available instead
+of 'histchars', and the 'signals' parameter is not initialised.
+
 Changes from 5.6.2 to 5.7.1
 ---------------------------
 
diff --git a/Src/params.c b/Src/params.c
index 863b32600..699dc7ccd 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -309,7 +309,7 @@ IPDEF1("TTYIDLE", ttyidle_gsu, PM_READONLY_SPECIAL),
 #define IPDEF2(A,B,C) {{NULL,A,PM_SCALAR|PM_SPECIAL|C},BR(NULL),GSU(B),0,0,NULL,NULL,NULL,0}
 IPDEF2("USERNAME", username_gsu, PM_DONTIMPORT|PM_RESTRICTED),
 IPDEF2("-", dash_gsu, PM_READONLY_SPECIAL),
-IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
+IPDEF2("HISTCHARS", histchars_gsu, PM_DONTIMPORT),
 IPDEF2("HOME", home_gsu, PM_UNSET),
 IPDEF2("TERM", term_gsu, PM_UNSET),
 IPDEF2("TERMINFO", terminfo_gsu, PM_UNSET),
@@ -413,7 +413,7 @@ IPDEF8("MODULE_PATH", &module_path, "module_path", PM_DONTIMPORT|PM_RESTRICTED|P
 
 /* All of these have sh compatible equivalents.                */
 IPDEF1("ARGC", argc_gsu, PM_READONLY_SPECIAL),
-IPDEF2("HISTCHARS", histchars_gsu, PM_DONTIMPORT),
+IPDEF2("histchars", histchars_gsu, PM_DONTIMPORT),
 IPDEF4("status", &lastval),
 IPDEF7("prompt", &prompt),
 IPDEF7("PROMPT", &prompt),
@@ -935,8 +935,10 @@ createparamtable(void)
     setsparam("ZSH_ARGZERO", ztrdup(posixzero));
     setsparam("ZSH_VERSION", ztrdup_metafy(ZSH_VERSION));
     setsparam("ZSH_PATCHLEVEL", ztrdup_metafy(ZSH_PATCHLEVEL));
-    setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));
-    for (t = sigs; (*sigptr++ = ztrdup_metafy(*t++)); );
+    if (!EMULATION(EMULATE_SH|EMULATE_KSH)) {
+	setaparam("signals", sigptr = zalloc((SIGCOUNT+4) * sizeof(char *)));
+	for (t = sigs; (*sigptr++ = ztrdup_metafy(*t++)); );
+    }
 
     noerrs = 0;
 }

             reply	other threads:[~2020-01-28 15:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200128152042eucas1p20cbbeeb7cbe5f6abff08128ba8792661@eucas1p2.samsung.com>
2020-01-28 15:19 ` Martijn Dekker [this message]
2020-01-28 15:26   ` Peter Stephenson
2020-01-28 15:45     ` Martijn Dekker
2020-01-29  8:49   ` Daniel Shahaf
2020-01-29 18:36     ` Bart Schaefer
2020-01-29 21:35       ` Daniel Shahaf
2020-01-29 22:00         ` Bart Schaefer
2020-01-31  4:17           ` Daniel Shahaf
2020-01-31  4:31             ` Bart Schaefer
2020-02-01  9:42   ` Daniel Shahaf

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=b7e2e8a2-87a9-49c9-77ff-e612285b7a30@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /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).