diff --git a/src/env.cpp b/src/env.cpp index 0928367ab..fc11bcbd5 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -322,7 +322,7 @@ bool string_set_contains(const T &set, const wchar_t *val) { /// Check if a variable may not be set using the set command. static bool is_read_only(const wchar_t *val) { - const string_set_t env_read_only = {L"PWD", L"SHLVL", L"_", L"history", L"status", L"version"}; + const string_set_t env_read_only = {L"PWD", L"SHLVL", L"_", L"history", L"status", L"version", L"pid"}; return string_set_contains(env_read_only, val); } @@ -969,6 +969,9 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { wcstring version = str2wcstring(get_fish_version()); env_set_one(L"version", ENV_GLOBAL, version); + // Set the $pid variable (%self replacement) + env_set_one(L"pid", ENV_GLOBAL, to_string(getpid())); + // Set up SHLVL variable. Not we can't use env_get because SHLVL is read-only, and therefore was // not inherited from the environment. wcstring nshlvl_str = L"1";