Error Initialization of Environment Variables in Resource Configuration File GMXRC.bash
Summary
If SHELL
is bash
or zsh
, default environment variables like LD_LIBRARY_PATH
, PKG_CONFIG_PATH
, PATH
, MANPATH
will be muted if they are not set, i.e., "empty".
GROMACS version
GROMACS version: 2021.5
GROMACS version: 2022
Steps to reproduce
I have prepared a file to reproduce this error, please copy the following codes:
# Excerpt from build/${GMXPREFIX}/bin/GMXRC.bash
# line from 12-41
replace_in_path() {
# Parse PATH-like variable $1, and return a copy of it with any instances of $3 removed and $2 added to the beginning.
# If $3 is empty, do not remove anything.
local tmppath oldpath to_remove to_add old_shell_opts
oldpath="$1"
to_add="$2"
to_remove="$3"
if test -z "${oldpath}"; then
echo "${to_add}"
else
if test "${oldpath}" = ":"; then
echo "${to_add}:"
else
tmppath="${to_add}"
old_shell_opts="$-"
set -o noglob
set -- ${oldpath}"" # Will put tokens to $@, including empty ones
# If did not have noglob ("f") enabled before, disable it back
if test -n "${old_shell_opts##*f*}"; then
set +o noglob
fi
for i in "$@"; do
if test \( -z "${to_remove}" \) -o \( "$i" != "${to_remove}" \); then
tmppath="${tmppath}:${i}"
fi
done
echo "${tmppath}"
fi
fi
}
# reproducing and explanations
# works as expect
echo "test-1 =>>`replace_in_path 'old' 'remove1:remove2' 'add'`<<="
echo "test-2 =>>`replace_in_path 'add'`<=="
echo "test-3 =>>`replace_in_path ':' 'add'`<=="
# error! works not as expect
# it should return "add:" but NOT "add"
echo "test-4 =>>`replace_in_path '' 'add'`<=="
What is the current bug behavior?
In above codes excerption, testing in test-4
should echo
value add:
, in a way to expose environment variables when default value is empty, because #debian/ubuntu needs a : at the end
.
By the way, a little bit more knowledge, this error is caused by the preventing of shell-expansion in double quotes.
Note: double quotes in:
# line from 61 to 64
LD_LIBRARY_PATH=$(replace_in_path "${LD_LIBRARY_PATH}" "${GMXLDLIB}" "${OLD_GMXLDLIB}")
PKG_CONFIG_PATH=$(replace_in_path "${PKG_CONFIG_PATH}" "${GMXLDLIB}/pkgconfig" "${OLD_GMXLDLIB}/pkgconfig")
PATH=$(replace_in_path "${PATH}" "${GMXBIN}" "${OLD_GMXBIN}")
MANPATH=$(replace_in_path "${MANPATH}" "${GMXMAN}" "${OLD_GMXMAN}")
are the must in case of any of those variables has white spaces.
Possible fixes
# in file ${GMXPREFIX}/bin/GMXRC.bash
# line 20
change:
echo "${to_add}"
to:
echo "${to_add}:"
However, I do not know how the way this file is generated, thus, modification inside source cods should be made..