10/12/23 14:11, Omar Polo пишет: > On 2023/10/11 19:10:43 +0000, Klemens Nanni <k...@openbsd.org> wrote: >> On Wed, Oct 11, 2023 at 03:44:47PM +0200, Omar Polo wrote: >>> -@@ -27,7 +27,7 @@ export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}" >>> +@@ -48,19 +48,21 @@ function make_native_path { >>> + # usage : add_path PATH_VAR [PATH]... >>> + function add_path { >>> + local path_var="$1" >>> ++ local val="" >>> + shift >>> + while [ -n "$1" ];do >>> + # >>> http://bashify.com/?Useful_Techniques:Indirect_Variables:Indirect_Assignment >>> +- if [[ -z ${!path_var} ]]; then >> The comment's link just tells me the domain is for sale and bash(1) does >> not document ${!name} (only ${!prefix*} and other forms); not sure what >> they do here, but it looks like a simple empty check suffices? > It's documented here: apparentely > > https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html > > : If the first character of parameter is an exclamation point (!), and > : parameter is not a nameref, it introduces a level of indirection > > The idea of this `add_path' is to take a variable name as the first > argument and append the rest of the arguments.
Thanks for the clue. >>> +- export ${path_var}="$(make_native_path "$1")" >>> ++ if [ -z "$val" ]; then >> ksh(1) has [[ and you should stick to that, there quoting is not needed >> compared to [ -- see the manual for differences. > I know the difference between [ and [[. I try to stick with the posix > sh subset even in a blatantly bash/ksh evironment, but can change to > the fancy [[ if you prefer. It just looked odd to downgrade from [[ to [ when you use bash/ksh in the shebang already and other lines in the same script already use [[, that's all. Your call. >>> ++ val="$(make_native_path "$1")" >>> + else >>> +- export ${path_var}="${!path_var}${delimiter}$(make_native_path >>> "$1")" >>> ++ val="${val}${delimiter}$(make_native_path "$1")" >>> + fi >>> + shift >>> + done >>> ++ export ${path_var}="$val" >> Instead of deferring the export, does it work if you just remove the two ! >> and leave the rest as-is? > Nope, because we loose the initial value. > > The alternative would have been to use eval to get the value of > $path_var (not the content of path_var but the content of the variable > named "$path_var"). No need to pull out eval (: Your original diff is OK kn, regardless of brackets.