Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ksh inherits readonly exported variables from the parent, breaking scripts #1505

Open
vlmarek opened this issue Mar 11, 2025 · 1 comment
Open

Comments

@vlmarek
Copy link

vlmarek commented Mar 11, 2025

$ ksh --version
  version         sh (AT&T Research) 93u+m/1.0.0-beta.2 2021-12-17

I know, not the latest version so I'm terribly sorry if I report already fixed issue.

$ cat aaa
#!/usr/bin/ksh
VAR=yes
typeset -p VAR

$ chmod +x aaa

$ ksh -c 'readonly VAR=foo ; export VAR; ./aaa' 
./aaa: line 1: VAR: is read only


# similarly integer variables

$ ksh -c 'typeset -i VAR=123; export VAR; ./aaa'
typeset -x -i VAR=0

I would expect the new process inherit the exported variable, but not the type of variable. The script can protect himself against integer variables by running typeset VAR=yes which is not reasonable (to me) to do for any and all variables used. I don't know if there is a way to un-readonly a variable at all.

@McDutchie
Copy link
Contributor

McDutchie commented Mar 14, 2025

Hi, you reported this to the inactive AT&T repo and this is not where current ksh 93u+m development happens. Please upgrade to the latest release and report any bugs to https://github.com/ksh93/ksh. But yes, this issue has long since been fixed.

In the ksh 93u+m/1.0.x release series, we need to keep inheriting variable attributes through the environment for backward compatibility, but I've disabled it for readonly because scripts have no way to unset that attribute (see ksh93@7954855), and I've also disabled it for all attributes in POSIX mode, i.e., when ksh is invoked as sh (see ksh93@00d4396). In the dev branch (which will become the ksh 93u+m/1.1.x release series), this misfeature has been removed completely (see ksh93@f215b10).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants