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

Re: Assigning to $0 (formerly: PATCH: funcstack[-1])



On Feb 15,  7:51am, Mikael Magnusson wrote:
}
} > So typeset will accept 0 as a valid name and -g as a valid option, but
} > can't actually set the global $0.
} 
} http://www.zsh.org/mla/workers/2015/msg01400.html Some time before
} that patch, assigning to $0 was always possible, but at some point it
} stopped working.

No, I think it was never possible to assign to the global $0 from inside
a function.

torch% print $ZSH_VERSION
4.2.0
torch% zero() { typeset -g 0=argzero; print $0 }
torch% print $0; zero; print $0
/bin/zsh
argzero
/bin/zsh
torch% 

This is because the "argzero" C global is handled independently of the
usual parameter scope code.

On Feb 15,  9:17am, Peter Stephenson wrote:
}
} > 1. POSIXARGZERO makes $0 report an error on assignment (read only?)
} 
} This seems to make the most sense.  Setting a value of $0 you're not
} going to see immediately is pointless.


diff --git a/Src/params.c b/Src/params.c
index 0233e2b..8bd8a8e 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -4158,7 +4158,9 @@ static void
 argzerosetfn(UNUSED(Param pm), char *x)
 {
     if (x) {
-	if (!isset(POSIXARGZERO)) {
+	if (isset(POSIXARGZERO))
+	    zerr("read-only variable: 0");
+	else {
 	    zsfree(argzero);
 	    argzero = ztrdup(x);
 	}



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