From 130619d6b07c691b1f34c56120020adaff09c49a Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Fri, 22 Aug 2014 18:05:28 -0700 Subject: [PATCH] Fix $SHLVL Due to being read-only, SHLVL wasn't being incremented properly for recursive invocations of fish. --- env.cpp | 3 ++- tests/test3.in | 4 ++++ tests/test3.out | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/env.cpp b/env.cpp index 91bc7ac80..353085b8b 100644 --- a/env.cpp +++ b/env.cpp @@ -443,7 +443,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) L"LINES", L"COLUMNS", L"PWD", - L"SHLVL", + //L"SHLVL", // will be inserted a bit lower down L"FISH_VERSION", }; 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_read_only.insert(L"SHLVL"); /* Set up the HOME variable */ if (env_get_string(L"HOME").missing_or_empty()) diff --git a/tests/test3.in b/tests/test3.in index 1bbacc0e3..56cceeb57 100644 --- a/tests/test3.in +++ b/tests/test3.in @@ -233,4 +233,8 @@ echo $testu 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 diff --git a/tests/test3.out b/tests/test3.out index d6cbdb9c8..50563c05b 100644 --- a/tests/test3.out +++ b/tests/test3.out @@ -21,3 +21,5 @@ Testing Universal Startup 2 Missing: Missing: +SHLVL: 1 +SHLVL: 2