diff options
author | Kevin Ballard <kevin@sb.org> | 2014-07-12 14:05:42 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-07-12 14:07:55 -0700 |
commit | 2457997cd9c624034f28f1be218f93cdc60a3e58 (patch) | |
tree | f22631d0f695b2cea31aa4b7fcb61b641b2e391c /env.cpp | |
parent | d9bed68fe9af4502c62ff19bc27b0c4fca4034a6 (diff) |
set: Print an error when setting a special var in the wrong scope
When attempting to set a readonly or electric variable in the local or
universal scopes, print an appropriate error. Similarly, print an error
when setting an electric variable as exported. In most cases this is
simply a nicer error instead of the 'read-only' one, but for the 'umask'
variable it prevents `set -l umask 0023` from silently changing the
global value.
Diffstat (limited to 'env.cpp')
-rw-r--r-- | env.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -634,6 +634,15 @@ int env_set(const wcstring &key, const wchar_t *val, int var_mode) } } + if ((var_mode & (ENV_LOCAL | ENV_UNIVERSAL)) && (is_read_only(key) || is_electric(key))) + { + return ENV_SCOPE; + } + if ((var_mode & ENV_EXPORT) && is_electric(key)) + { + return ENV_SCOPE; + } + if ((var_mode & ENV_USER) && is_read_only(key)) { return ENV_PERM; |