From 980365735a71dcbfc7874682840bc22957f33a16 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 11 Apr 2021 11:07:44 +0200 Subject: [PATCH] If no uvars are available, fall back to global when setting Otherwise `set -U foo bar` if uvars aren't available would simply not set *anything*. --- src/builtin_set.cpp | 3 ++- src/env.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index 4896383c7..3284db02e 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -805,6 +805,7 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, c new_values = new_var_values_by_index(*split, argc, argv); } + bool have_shadowing_global = check_global_scope_exists(cmd, opts, split->varname, streams, parser); // Set the value back in the variable stack and fire any events. std::vector evts; int retval = env_set_reporting_errors(cmd, split->varname, scope, std::move(new_values), @@ -814,7 +815,7 @@ static int builtin_set_set(const wchar_t *cmd, set_cmd_opts_t &opts, int argc, c } if (retval != STATUS_CMD_OK) return retval; - return check_global_scope_exists(cmd, opts, split->varname, streams, parser); + return have_shadowing_global; } /// The set builtin creates, updates, and erases (removes, deletes) variables. diff --git a/src/env.cpp b/src/env.cpp index c9a087a17..ba75986a2 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -1170,10 +1170,12 @@ mod_result_t env_stack_impl_t::set(const wcstring &key, env_mode_flags_t mode, mod_result_t result{ENV_OK}; if (query.has_scope) { // The user requested a particular scope. - if (query.universal) { + // + // If we don't have uvars, fall back to using globals + if (query.universal && uvars()) { set_universal(key, std::move(val), query); result.uvar_modified = true; - } else if (query.global) { + } else if (query.global || (query.universal && !uvars())) { set_in_node(globals_, key, std::move(val), flags); result.global_modified = true; } else if (query.local) {