Protect sh alias and function unset code

"unalias" command raises an error on "sh" kind shell when alias to unset
is not defined. Shell code is added to drop this error message and
always return success.

Same methodology is applied when unsetting function on "sh" kind shell.
An error is raised on "zsh" shell when function is not defined.
Protection code is applied for all shell of the "sh" kind for
simplicity.
This commit is contained in:
Xavier Delaruelle
2024-01-18 20:35:33 +01:00
parent b686a00830
commit d8bbcddcb1
3 changed files with 8 additions and 2 deletions

View File

@@ -846,6 +846,7 @@ txt
ubuntu
umask
un
unalias
uname
uncomplete
undef

View File

@@ -116,6 +116,10 @@ Modules 5.4.0 (not yet released)
sub-commands.
* Lib: slightly adapt code of Modules Tcl extension library to properly build
against Tcl 9.0.
* Adapt alias unset shell code for *sh*-kind shells to avoid errors when alias
to unset is not defined.
* Adapt function unset shell code for *sh*-kind shells to avoid errors when
function to unset is not defined.
.. _5.3 release notes:

View File

@@ -353,7 +353,7 @@ proc renderSettings {} {
lappend g_shcode_out "unalias $var;"
}
sh {
lappend g_shcode_out "unalias $var;"
lappend g_shcode_out "unalias $var 2>/dev/null || true;"
}
fish {
lappend g_shcode_out "functions -e $var;"
@@ -386,7 +386,8 @@ proc renderSettings {} {
del {
switch -- [getState shelltype] {
sh {
lappend g_shcode_out "unset -f $funcname;"
lappend g_shcode_out "unset -f $funcname 2>/dev/null ||\
true;"
}
fish {
lappend g_shcode_out "functions -e $funcname;"