Checking if an Environment Variable is Set in UNIX Shell

We had a task to write a script to check if certain environment variables, which should not be set, were set. This task was straightforward with C shell:

if $?GARBAGEENV then
echo "Unset GARBAGEENV on `hostname`"
endif

With K shell, we did not find anything built-in. So we used something innovative.

if test "isenvset${GARBAGEENV}" != "isenvset"; then
echo "Unset GARBAGEENV on `hostname`"
fi

If GARBAGEENV was set to N, isenvset${GARBAGEENV} would be evaluated as  isenvsetN (which is not equal to isenvset). If it was not set isenvset${GARBAGEENV} would be evaluated as isenvset.

Comments

Popular posts from this blog

OS/DB Migration - CMD. STR, TOC, EXT, R3load, DDLDBS.TPL and more

Fixing Inconsistent Table - Table activation fails due to inconsistency between DD and DB

301 Redirect Using SAP Web Dispatcher