From 29a24869e403e7364301e6fd7c745d327ed2d8c6 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 8 Jul 2024 14:49:31 +0100 Subject: [PATCH] ash: restore value of imported variable on unexport Shell variables imported from the environment are marked with a special flag and backslashes in their values are (by default) replaced with forward slashes. Sometimes this may not be what we want. Modify the 'export' shell built-in so unexporting a variable of this type restores its original value from the environment and removes its special flag. It can then be re-exported. Adds 32 bytes. (GitHub issue #428) --- shell/ash.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shell/ash.c b/shell/ash.c index d9ab3feb51..64a8dd318b 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -15512,6 +15512,15 @@ exportcmd(int argc UNUSED_PARAM, char **argv) } #endif vp->flags = ((vp->flags | flag) & flag_off); +#if ENABLE_PLATFORM_MINGW32 + /* Unexporting a variable imported from the + * environment restores its original value and + * removes the VIMPORT flag. */ + if ((vp->flags & VIMPORT) && (flag_off == ~VEXPORT)) { + vp->flags &= ~VIMPORT; + p = getenv(name); + } else +#endif continue; } }