Fix $SHLVL

Due to being read-only, SHLVL wasn't being incremented properly for
recursive invocations of fish.
This commit is contained in:
Kevin Ballard 2014-08-22 18:05:28 -07:00
parent 71ab40e536
commit 130619d6b0
3 changed files with 8 additions and 1 deletions

View file

@ -443,7 +443,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
L"LINES", L"LINES",
L"COLUMNS", L"COLUMNS",
L"PWD", L"PWD",
L"SHLVL", //L"SHLVL", // will be inserted a bit lower down
L"FISH_VERSION", L"FISH_VERSION",
}; };
for (size_t i=0; i < sizeof ro_keys / sizeof *ro_keys; i++) for (size_t i=0; i < sizeof ro_keys / sizeof *ro_keys; i++)
@ -549,6 +549,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
} }
} }
env_set(L"SHLVL", nshlvl_str.c_str(), ENV_GLOBAL | ENV_EXPORT); env_set(L"SHLVL", nshlvl_str.c_str(), ENV_GLOBAL | ENV_EXPORT);
env_read_only.insert(L"SHLVL");
/* Set up the HOME variable */ /* Set up the HOME variable */
if (env_get_string(L"HOME").missing_or_empty()) if (env_get_string(L"HOME").missing_or_empty())

View file

@ -233,4 +233,8 @@ echo $testu
echo Missing: $testu echo Missing: $testu
../fish -c 'echo Missing: $testu' ../fish -c 'echo Missing: $testu'
# test SHLVL
# use a subshell to ensure a clean slate
env SHLVL= ../fish -c 'echo SHLVL: $SHLVL; ../fish -c \'echo SHLVL: $SHLVL\''
true true

View file

@ -21,3 +21,5 @@ Testing Universal Startup
2 2
Missing: Missing:
Missing: Missing:
SHLVL: 1
SHLVL: 2