Just figured I'd share implementations of "setenv" and "unsetenv" that I made for Bourne-compatible shells.
Unfortunately at work I'm doomed to use "tcsh" for various reasons (like established infrastructure) and it's preprogrammed me to type things like "setenv" even when I'm in a shell that doesn't have it. I use "zsh" everywhere else, and I finally resolved to make "setenv" and "unsetenv" work correctly no matter what the shell is.
If you put the following in ".zshrc" (presumably this works in ".bashrc", etc. too) then you'll once again have "setenv" and "unsetenv" available.
setenv () {
if [ "x$1" = "x" ] ; then
echo "$0: environment variable name required" >&2
elif [ "x$2" = "x" ] ; then
echo "$0: environment variable value required" >&2
else
export $1=$2
fi
}
unsetenv () {
if [ "x$1" = "x" ] ; then
echo "$0: environment variable name required" >&2
else
unset $1
fi
}
I have seen environment managers that support both csh-style and sh-style environment setup, often by doing absolutely everything twice (in a way that is either error-prone or annoyingly indirect). In theory the functions above could avoid such complexity, too, if they were simply made part of each system's default configurations for Bourne-compatible shells.