Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: More typeset bugs: POSIX_BUILTINS
- X-seq: zsh-workers 47704
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: More typeset bugs: POSIX_BUILTINS
- Date: Mon, 30 Nov 2020 09:07:42 -0800
- Archived-at: <https://zsh.org/workers/47704>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-11/CAH%2Bw%3D7am9GWvvKVoqKNqFUS7WsMPjQKbuaSy7fMjfdE8R6br5w%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-oi1-f175.google.com) smtp.remote-ip=209.85.167.175; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=kj10RE6YtZ50T0M4tSYPCap4O0EklC09x3GDp5I1kcY=; b=zGaVqWaLwkHHPgSZGNJFmK9nluyekvWYD/BJPBzn8Rn57cN0SFtvlrEARx4LW0XpKW 76KUzL0niDYwrXRpjwrPnOM5HdVFvNliDO328ZN5OxDBWR51pl5EJrgyg8A5Jw10JIu9 nclhqbqGR5zQEXNF+azjquDcv9ZgauAhQG3VXH6gtJB0/NYdEgMP/rIUje/rf/E5ogqY hl9w/uFjwUyVaqihDt3apHbPPPs7WB47Drkhu34uBsV7KO77XLP9LShxysNAHo2Lf+d6 F4t34KKDcvpgcXvQe8C3VLXvqBM8OHcWnH6kS2JA/t/Pn6nfUikzNWqjrJuPUNqiwigt PdKw==
- In-reply-to: <CAH+w=7aZ40Dnff8+n+7xFqm_7Bg_OMr3oyKDc2nrLzAsSkoqmQ@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <CAH+w=7aYGZgF25Hypw=s31u5hfTT-Y+6pKzrCuD-1kB=1pShOg@mail.gmail.com> <20201129201246.z576arko6rlmr3pu@chazelas.org> <CAH+w=7aZ40Dnff8+n+7xFqm_7Bg_OMr3oyKDc2nrLzAsSkoqmQ@mail.gmail.com>
- Sender: zsh-workers-request@xxxxxxx
On Sun, Nov 29, 2020 at 12:18 PM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> Both bash and ksh ignore -p for readonly/export when there are any
> non-option arguments, and therefore create/assign the named variables.
In the event that we want to change this, patch attached.
The param_private.c diff should be applied either way.
diff --git a/Src/Modules/param_private.c b/Src/Modules/param_private.c
index 86416c5c5..24545819d 100644
--- a/Src/Modules/param_private.c
+++ b/Src/Modules/param_private.c
@@ -171,6 +171,7 @@ bin_private(char *nam, char **args, LinkList assigns, Options ops, int func)
{
int from_typeset = 1;
int ofake = fakelevel; /* paranoia in case of recursive call */
+ int hasargs = *args != NULL || (assigns && firstnode(assigns));
makeprivate_error = 0;
if (!OPT_ISSET(ops, 'P')) {
@@ -190,6 +191,9 @@ bin_private(char *nam, char **args, LinkList assigns, Options ops, int func)
}
ops->ind['g'] = 2; /* force bin_typeset() to behave as "local" */
+ if (OPT_ISSET(ops, 'p') || (!hasargs && OPT_ISSET(ops, '+'))) {
+ return bin_typeset("private", args, assigns, ops, func);
+ }
queue_signals();
fakelevel = locallevel;
diff --git a/Src/builtin.c b/Src/builtin.c
index 09eb3728c..3d52d563f 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2612,7 +2612,12 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
int on = 0, off = 0, roff, bit = PM_ARRAY;
int i;
int returnval = 0, printflags = 0;
- int hasargs;
+ int hasargs = *argv != NULL || (assigns && firstnode(assigns));
+
+ /* POSIXBUILTINS is set for bash/ksh and both ignore -p with args */
+ if ((func == BIN_READONLY || func == BIN_EXPORT) &&
+ isset(POSIXBUILTINS) && hasargs)
+ ops->ind['p'] = 0;
/* hash -f is really the builtin `functions' */
if (OPT_ISSET(ops,'f'))
@@ -2692,7 +2697,6 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
/* -p0 treated as -p for consistency */
}
}
- hasargs = *argv != NULL || (assigns && firstnode(assigns));
if (!hasargs) {
int exclude = 0;
if (!OPT_ISSET(ops,'p')) {
diff --git a/Src/params.c b/Src/params.c
index 122f5da7d..29c1653af 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5867,8 +5867,12 @@ printparamnode(HashNode hn, int printflags)
* don't.
*/
if (printflags & PRINT_POSIX_EXPORT) {
+ if (!(p->node.flags & PM_EXPORTED))
+ return;
printf("export ");
} else if (printflags & PRINT_POSIX_READONLY) {
+ if (!(p->node.flags & PM_READONLY))
+ return;
printf("readonly ");
} else if (locallevel && p->level >= locallevel) {
printf("typeset "); /* printf("local "); */
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index e7bf93794..8b3988151 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -620,7 +620,7 @@
print ${+pbro} >&2
(typeset -g pbro=3)
(pbro=4)
- readonly -p pbro >&2 # shows up as "readonly" although unset
+ readonly -p >&2 # shows up as "readonly" although unset
typeset -gr pbro # idempotent (no error)...
print ${+pbro} >&2 # ...so still readonly...
typeset -g +r pbro # ...can't turn it off
@@ -1050,23 +1050,21 @@
$ZTST_testdir/../Src/zsh --emulate sh -f -c '
PATH=/bin; export PATH; readonly PATH
- export -p PATH
+ export -p PATH # Should be a no-op, -p ignored
typeset -p PATH
readonly -p'
0: readonly/export output for exported+readonly+special when started as sh
->export PATH=/bin
>export -r PATH=/bin
>readonly PATH=/bin
function {
emulate -L sh
MANPATH=/bin; export MANPATH; readonly MANPATH
- export -p MANPATH
+ export -p MANPATH # Should be a no-op, -p ignored
typeset -p MANPATH
readonly -p
}
0: readonly/export output for exported+readonly+tied+special after switching to sh emulation
->export MANPATH=/bin
>export -rT MANPATH manpath=( /bin )
>readonly MANPATH=/bin
Messages sorted by:
Reverse Date,
Date,
Thread,
Author