<?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: simple script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622193#M925949</link>
    <description>Of course.  With +u "cd ${ADIR}" returns 0 even if ${ADIR} doesn't exist (the cd takes you to your home dir).  Not a good thing.&lt;BR /&gt;&lt;BR /&gt;Guess I wasn't thinking (what else is new).&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Darrell</description>
    <pubDate>Thu, 29 Nov 2001 17:09:04 GMT</pubDate>
    <dc:creator>Darrell Allen</dc:creator>
    <dc:date>2001-11-29T17:09:04Z</dc:date>
    <item>
      <title>simple script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622189#M925945</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;This is driving me crazy (short trip).  Here's a simple script:&lt;BR /&gt;&lt;BR /&gt;if [ "$DISPLAY" ]&lt;BR /&gt;then&lt;BR /&gt;        echo DISPLAY $DISPLAY&lt;BR /&gt;else&lt;BR /&gt;        term=`tty | cut -c6-`&lt;BR /&gt;        export DISPLAY=`who -u | grep "$term " | awk '{print $1}'`":0.0"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;It seems the script runs fine in a subshell (./script) but I know I have to run it in my current shell (. ./script) to get the desired result.  Here's the problem:&lt;BR /&gt;&lt;BR /&gt;When I run ". ./script" it fails with:&lt;BR /&gt;sh: DISPLAY: Parameter not set.&lt;BR /&gt;&lt;BR /&gt;It doesn't matter if my shell is specified in /etc/passwd as /sbin/sh, /usr/bin/sh, or /usr/bin/ksh.  I get the error regardless.&lt;BR /&gt;&lt;BR /&gt;Another oddity is that if I simply go into another shell after logging in, the script then works as desired.  Again, it doesn't matter which of the 3 shells I choose.&lt;BR /&gt;&lt;BR /&gt;Thanks for helping,&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 29 Nov 2001 15:23:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622189#M925945</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2001-11-29T15:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: simple script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622190#M925946</link>
      <description>This is one of the differences between an interactive shell and a shell script.&lt;BR /&gt;&lt;BR /&gt;Your .profile is sourced into your login (ie interactive) shell environment (ie not run as a shell script) which has the -u flag set to error on unknown variables. To see:&lt;BR /&gt;&lt;BR /&gt;$ print $wibble&lt;BR /&gt;sh: wibble: Parameter not set.&lt;BR /&gt;$ set +u&lt;BR /&gt;$ print $wibble&lt;BR /&gt;&lt;BR /&gt;$&lt;BR /&gt;&lt;BR /&gt;So to get round it either:&lt;BR /&gt;1) Set a variable before you use it. (Remember that even in quotes if a variable doesn't exist the shell *still* looks at it)&lt;BR /&gt;2) Use set +u like above, don't forget to unset it afterwards.&lt;BR /&gt;3) Use the shell construct:&lt;BR /&gt;   variable=${variable:-NOTSET}&lt;BR /&gt;(which states if variable is unset set it to NOTSET otherwise set it to the contents of variable)&lt;BR /&gt;&lt;BR /&gt;I'd advise using 3, this is a very good safety measure to use in any shell script!&lt;BR /&gt;&lt;BR /&gt;One other thing to remember is the difference between a non-existant variable and a blank one. eg:&lt;BR /&gt;$ echo $fred&lt;BR /&gt;sh: fred: Parameter not set.&lt;BR /&gt;$ fred=&lt;BR /&gt;$ echo $fred&lt;BR /&gt;&lt;BR /&gt;$&lt;BR /&gt;&lt;BR /&gt;dave</description>
      <pubDate>Thu, 29 Nov 2001 15:34:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622190#M925946</guid>
      <dc:creator>David Lodge</dc:creator>
      <dc:date>2001-11-29T15:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: simple script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622191#M925947</link>
      <description>Excellent Dave!&lt;BR /&gt;&lt;BR /&gt;I added "set +u" at the beginning of my script.&lt;BR /&gt;&lt;BR /&gt;Why would I want to use "set -u" anyway?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 29 Nov 2001 16:03:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622191#M925947</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2001-11-29T16:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: simple script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622192#M925948</link>
      <description>It's intended as a safety measure for shell users in case of a mistake, so that an error is returned instead of just going ahead and treating the variable like a blank string, eg:&lt;BR /&gt;&lt;BR /&gt;rm -rf /${ADIR}&lt;BR /&gt;mv /${ADIR} /tmp/backup&lt;BR /&gt;&lt;BR /&gt;imagine if you executed on of the above without ADIR set or accidently mistyped it as SDIR and pressed return without noticing?&lt;BR /&gt;&lt;BR /&gt;dave</description>
      <pubDate>Thu, 29 Nov 2001 16:45:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622192#M925948</guid>
      <dc:creator>David Lodge</dc:creator>
      <dc:date>2001-11-29T16:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: simple script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622193#M925949</link>
      <description>Of course.  With +u "cd ${ADIR}" returns 0 even if ${ADIR} doesn't exist (the cd takes you to your home dir).  Not a good thing.&lt;BR /&gt;&lt;BR /&gt;Guess I wasn't thinking (what else is new).&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 29 Nov 2001 17:09:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/simple-script/m-p/2622193#M925949</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2001-11-29T17:09:04Z</dc:date>
    </item>
  </channel>
</rss>

