On Thu, 08 Sep 2016 10:08:23 -0400, Anthony Coulter wrote: > We can fix either the manual or ksh itself; this diff takes the latter > approach. It is tempting to do this with "typeset -ir PPID" but that > actually doesn't work: > > $ FOO=123 > $ typeset -ir FOO > ksh: FOO: is read only
Perhaps we should fix the above issue as well, other ksh versions don't throw an error there. Below is a simple fix, though a bit gross due to the magic 0x4. - todd Index: bin/ksh/var.c =================================================================== RCS file: /cvs/src/bin/ksh/var.c,v retrieving revision 1.55 diff -u -p -u -r1.55 var.c --- bin/ksh/var.c 30 Dec 2015 09:07:00 -0000 1.55 +++ bin/ksh/var.c 8 Sep 2016 15:20:20 -0000 @@ -661,6 +661,7 @@ typeset(const char *var, int set, int cl */ for (t = vpbase; t; t = t->u.array) { int fake_assign; + int error_ok = KSH_RETURN_ERROR; char *s = NULL; char *free_me = NULL; @@ -683,6 +684,10 @@ typeset(const char *var, int set, int cl t->type = 0; t->flag &= ~ALLOC; } + if (!(t->flag & RDONLY) && (set & RDONLY)) { + /* allow var to be initialized read-only */ + error_ok |= 0x4; + } t->flag = (t->flag | set) & ~clr; /* Don't change base if assignment is to be done, * in case assignment fails. @@ -692,7 +697,7 @@ typeset(const char *var, int set, int cl if (set & (LJUST|RJUST|ZEROFIL)) t->u2.field = field; if (fake_assign) { - if (!setstr(t, s, KSH_RETURN_ERROR)) { + if (!setstr(t, s, error_ok)) { /* Somewhat arbitrary action here: * zap contents of variable, but keep * the flag settings.