From d8bbcddcb1b92243607dac66db36cc4c089efbf7 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Thu, 18 Jan 2024 20:35:33 +0100 Subject: [PATCH] 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. --- .hunspell.en.dic | 1 + NEWS.rst | 4 ++++ tcl/envmngt.tcl.in | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.hunspell.en.dic b/.hunspell.en.dic index 506bd486..a99eefd5 100644 --- a/.hunspell.en.dic +++ b/.hunspell.en.dic @@ -846,6 +846,7 @@ txt ubuntu umask un +unalias uname uncomplete undef diff --git a/NEWS.rst b/NEWS.rst index a1f049c8..7e9fc394 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -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: diff --git a/tcl/envmngt.tcl.in b/tcl/envmngt.tcl.in index 74c17336..d03c6656 100644 --- a/tcl/envmngt.tcl.in +++ b/tcl/envmngt.tcl.in @@ -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;"