Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] sh/ksh init: don't initialise lowercase parameters



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
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;
 }


Messages sorted by: Reverse Date, Date, Thread, Author