skip to main content

SAP NetWeaver Newbie

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.

No comments:

Post a Comment

Email Subscription

Get every new post into your inbox by subscribing us.

Want a reason to subscribe?
1. This sitemap might convince you to subscribe.
2. We do not misuse email IDs. We respect privacy.

© 2008 - 2017 sapnwnewbie. All rights reserved.