<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Test if variable is set in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261329#M714971</link>
    <description>Thanks for that one Jean-Luc, you're right.  I obviously got a bit too excited at suddenly and unexpectedly finding some time to ITRC :)</description>
    <pubDate>Wed, 28 Apr 2004 08:53:36 GMT</pubDate>
    <dc:creator>Mark Grant</dc:creator>
    <dc:date>2004-04-28T08:53:36Z</dc:date>
    <item>
      <title>Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261314#M714956</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;What is the best way to test if a variable has been set? (ksh)&lt;BR /&gt;&lt;BR /&gt;Like:&lt;BR /&gt;if (variable set?)&lt;BR /&gt;   do something&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Thx</description>
      <pubDate>Wed, 28 Apr 2004 04:51:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261314#M714956</guid>
      <dc:creator>Wim Korten</dc:creator>
      <dc:date>2004-04-28T04:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261315#M714957</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;You could test if the variable has any lenght with test :&lt;BR /&gt;&lt;BR /&gt;[ -z "$var" ] &amp;amp;&amp;amp; echo "length of string var is zero" &lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Nicolas</description>
      <pubDate>Wed, 28 Apr 2004 04:56:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261315#M714957</guid>
      <dc:creator>Nicolas Dumeige</dc:creator>
      <dc:date>2004-04-28T04:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261316#M714958</link>
      <description>Doing 'echo $parameter' and 'echo $?' &lt;BR /&gt;&lt;BR /&gt;like here:&lt;BR /&gt;&lt;BR /&gt;[ring]//usr/include/sys:echo $PWD&lt;BR /&gt;/usr/include/sys&lt;BR /&gt;[ring]//usr/include/sys:echo $?&lt;BR /&gt;0&lt;BR /&gt;[ring]//usr/include/sys:echo $rest&lt;BR /&gt;sh: rest: Parameter not set.&lt;BR /&gt;[ring]//usr/include/sys:echo $?&lt;BR /&gt;1&lt;BR /&gt;[ring]//usr/include/sys:&lt;BR /&gt;&lt;BR /&gt;exit status 1 returns if command exit status wasn't ok (ie parameter doesn't exist).&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 04:57:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261316#M714958</guid>
      <dc:creator>Zeev Schultz</dc:creator>
      <dc:date>2004-04-28T04:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261317#M714959</link>
      <description>Try&lt;BR /&gt;&lt;BR /&gt;echo ${variable}&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;if [ ${variable) = ""&lt;BR /&gt;then&lt;BR /&gt;echo "null"&lt;BR /&gt;else&lt;BR /&gt;{do something)&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 04:59:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261317#M714959</guid>
      <dc:creator>Jason Morgan_4</dc:creator>
      <dc:date>2004-04-28T04:59:11Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261318#M714960</link>
      <description>You can check the varaible length this is close. try this script :&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;A1="abcd"&lt;BR /&gt;unset A2&lt;BR /&gt;A3=""&lt;BR /&gt;&lt;BR /&gt;if [[ ! -z $A1 ]]; then&lt;BR /&gt;  echo "A1 is set"&lt;BR /&gt;else&lt;BR /&gt;  echo "A1 is not set"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [[ ! -z $A2 ]]; then&lt;BR /&gt;  echo "A2 is set"&lt;BR /&gt;else&lt;BR /&gt;  echo "A2 is not set"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [[ ! -z $A3 ]]; then&lt;BR /&gt;  echo "A3 is set"&lt;BR /&gt;else&lt;BR /&gt;  echo "A3 is not set"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;&lt;BR /&gt;A1 is set&lt;BR /&gt;A2 is not set&lt;BR /&gt;A3 is not set&lt;BR /&gt;&lt;BR /&gt;In fact A3 is set (and empty).&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Wed, 28 Apr 2004 04:59:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261318#M714960</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-04-28T04:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261319#M714961</link>
      <description>if [ $VAR ]&lt;BR /&gt;then&lt;BR /&gt;execute&lt;BR /&gt;else&lt;BR /&gt;echo .....&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Kaps</description>
      <pubDate>Wed, 28 Apr 2004 05:13:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261319#M714961</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2004-04-28T05:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261320#M714962</link>
      <description>If I understand all your replies correctly, there is no command to check on the existance op a variable, like you can do test -f for existance of a file.&lt;BR /&gt;&lt;BR /&gt;In my case I want to check if the LANG variable is set. Is there a difference in behavior between:&lt;BR /&gt;1) no LANG variable set&lt;BR /&gt;2) LANG variable set to nothing (empty string)&lt;BR /&gt;&lt;BR /&gt;THX&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 07:15:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261320#M714962</guid>
      <dc:creator>Wim Korten</dc:creator>
      <dc:date>2004-04-28T07:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261321#M714963</link>
      <description>Hi Wim,&lt;BR /&gt;&lt;BR /&gt;env command will list vars. so&lt;BR /&gt;TEST=`env | grep -q LANG`&lt;BR /&gt;if [ $? -ne 0 ]&lt;BR /&gt;then&lt;BR /&gt; echo "LANG is not set"&lt;BR /&gt;else&lt;BR /&gt; echo "LANG is $LANG"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;&lt;BR /&gt;Gideon</description>
      <pubDate>Wed, 28 Apr 2004 07:29:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261321#M714963</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2004-04-28T07:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261322#M714964</link>
      <description>Hi Gideon,&lt;BR /&gt;&lt;BR /&gt;I was looking at env also, but what if env returns:&lt;BR /&gt;...&lt;BR /&gt;X=LANGUAGE&lt;BR /&gt;NLS_LANG=DUTCH_THE NETHERLANDS.WE8ISO8859P15&lt;BR /&gt;LANG=Dutch&lt;BR /&gt;...&lt;BR /&gt;How can if find only the LANG variable?</description>
      <pubDate>Wed, 28 Apr 2004 07:41:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261322#M714964</guid>
      <dc:creator>Wim Korten</dc:creator>
      <dc:date>2004-04-28T07:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261323#M714965</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;env | grep ^LANG the ^states the line must start with LANG&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;&lt;BR /&gt;Gideon</description>
      <pubDate>Wed, 28 Apr 2004 07:56:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261323#M714965</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2004-04-28T07:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261324#M714966</link>
      <description>Wim,&lt;BR /&gt;&lt;BR /&gt;The shell deal with memory allocation on its own. Therefore, the declaration of a shell variable or the test of its existence can just take the form a value lookup. If you ask the value of a non-existent variable, the shell will tel you it's value is NULL (nothing) but it won't give you any error.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Nicolas&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 08:07:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261324#M714966</guid>
      <dc:creator>Nicolas Dumeige</dc:creator>
      <dc:date>2004-04-28T08:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261325#M714967</link>
      <description>This is a common question, especially if you use set -u (abort if an undefined variabnle is accessed). Here's how I do it:&lt;BR /&gt;&lt;BR /&gt;set -u&lt;BR /&gt; &lt;BR /&gt;# Set any variables that might not be defined with a default&lt;BR /&gt;# value.  That way, we can leave set -u and still check unset values&lt;BR /&gt; &lt;BR /&gt;  UNSET=IamNOTset&lt;BR /&gt;  DT=${DT:-$UNSET}&lt;BR /&gt;  VUE=${VUE:-$UNSET}&lt;BR /&gt; &lt;BR /&gt;# now check if the variable was ever set:&lt;BR /&gt; &lt;BR /&gt;if [ "$VUE" = $UNSET -o "$DT" = $UNSET ]&lt;BR /&gt;then&lt;BR /&gt; ... setup for non-Xwindow stuff&lt;BR /&gt;else&lt;BR /&gt; ... setup for Xwindows&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;# In case this is a 'sourced' script,&lt;BR /&gt;# return the unset variables backup to&lt;BR /&gt;# their original state:&lt;BR /&gt; &lt;BR /&gt;[ $DT = $UNSET ] &amp;amp;&amp;amp; unset DT&lt;BR /&gt;[ $VUE = $UNSET ] &amp;amp;&amp;amp; unset VUE&lt;BR /&gt; &lt;BR /&gt;---&lt;BR /&gt;The key to handling an unset variable is to use the shell contstruct ${VAR_NAME:-something} which ensures that the variable is defined with a unique value (IamNOTset) so it can be tested later.</description>
      <pubDate>Wed, 28 Apr 2004 08:30:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261325#M714967</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-04-28T08:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261326#M714968</link>
      <description>Othwerwise you can force the value if not set (or nul value) :&lt;BR /&gt;${A1:="zxy"}&lt;BR /&gt;will initialise A1 if not set (or is null) with "zxy"&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Wed, 28 Apr 2004 08:39:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261326#M714968</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-04-28T08:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261327#M714969</link>
      <description>One nasty little construct I've seen is as follows.&lt;BR /&gt;&lt;BR /&gt;[ "A$VAR" = "A" ] &amp;amp;&amp;amp; echo "$VAR is not set"</description>
      <pubDate>Wed, 28 Apr 2004 08:46:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261327#M714969</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-04-28T08:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261328#M714970</link>
      <description>Mark,&lt;BR /&gt;&lt;BR /&gt;I think if VAR is set but empty this would return "not set"&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Wed, 28 Apr 2004 08:50:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261328#M714970</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-04-28T08:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261329#M714971</link>
      <description>Thanks for that one Jean-Luc, you're right.  I obviously got a bit too excited at suddenly and unexpectedly finding some time to ITRC :)</description>
      <pubDate>Wed, 28 Apr 2004 08:53:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261329#M714971</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-04-28T08:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Test if variable is set</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261330#M714972</link>
      <description>I'll go for:&lt;BR /&gt;&lt;BR /&gt;if ( env|grep -q ^LANG= ); then&lt;BR /&gt;   unset LANG&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;THX All for your replies!&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Apr 2004 10:47:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/test-if-variable-is-set/m-p/3261330#M714972</guid>
      <dc:creator>Wim Korten</dc:creator>
      <dc:date>2004-04-28T10:47:40Z</dc:date>
    </item>
  </channel>
</rss>

