Skip to content

Commit

Permalink
ash: restore value of imported variable on unexport
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
rmyorston committed Jul 8, 2024
1 parent fff1c91 commit 29a2486
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions shell/ash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 29a2486

Please # to comment.