Distribution of security fixes
Posted Aug 27, 2004 22:17 UTC (Fri) by
EricBackus (guest, #2816)
In reply to:
Distribution of security fixes by rwmj
Parent article:
Distribution of security fixes
Note that there's a similar problem with $PATH. Doing:
export PATH=$PATH:/usr/local/bin
could possibly give you an empty component in PATH, which we all know is a bad thing. Now, an empty PATH variable is probably less common than an empty LD_LIBRARY_PATH, but you never know...
Long ago, I wrong an "add_to_path" shell function, which only adds a path if the path exists and does the right thing if the current path is empty. It's not TOO complicated:
# Add a directory to PATH if it exists and is not already in PATH.
# PATH is $1, Directory is $2. If PATH does not exist, don't prepend
# a ":" since that adds the current directory to it. If optional $3
# is equal to "atstart", add the new component to the start of PATH,
# otherwise add it at end.
function add_to_path
{
if [ -d "$2" ]; then
p=`eval echo \"\\$$1\"`
echo "$p" | grep -- "$2" > /dev/null
if [ "$?" -ne 0 ]; then
if [ -z "$p" ]; then
eval $1=\""$2"\"
else
if [ "$3" = "atstart" ]; then
eval $1=\""$2:\$$1"\"
else
eval $1=\""\$$1:$2"\"
fi
fi
fi
fi
}
With that in place, your shell script can do:
add_to_path PATH /usr/local/bin
add_to_path LD_LIBRARY_PATH /usr/local/lib
add_to_path MANPATH /usr/local/man
And you ensure that things work correctly and efficiently.
(
Log in to post comments)