<?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: Script error in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186033#M795950</link>
    <description>Changed the format of the test&lt;BR /&gt;&lt;BR /&gt;[ "A"$option = "A" ]&lt;BR /&gt;&lt;BR /&gt;This works.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;John.</description>
    <pubDate>Mon, 09 Feb 2004 06:05:25 GMT</pubDate>
    <dc:creator>John Flanagan</dc:creator>
    <dc:date>2004-02-09T06:05:25Z</dc:date>
    <item>
      <title>Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186026#M795943</link>
      <description>Until&lt;BR /&gt;  ----&lt;BR /&gt;  -----&lt;BR /&gt;  read option&lt;BR /&gt;[ !-n $option ]&lt;BR /&gt;do&lt;BR /&gt;  ----&lt;BR /&gt;  ----&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This works properly but gives the following error&lt;BR /&gt;iq.sh[23]: test: argument expected&lt;BR /&gt;If I hit enter the script is exited otherwise a serial number is entered and used in an sql script.  The results are correct except for the error being displayed.&lt;BR /&gt;&lt;BR /&gt;Redgards,&lt;BR /&gt;&lt;BR /&gt;John.</description>
      <pubDate>Mon, 09 Feb 2004 04:47:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186026#M795943</guid>
      <dc:creator>John Flanagan</dc:creator>
      <dc:date>2004-02-09T04:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186027#M795944</link>
      <description>if [ !-n $option] &lt;BR /&gt;do&lt;BR /&gt;--&lt;BR /&gt;--&lt;BR /&gt;done&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;OR&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Feb 2004 04:50:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186027#M795944</guid>
      <dc:creator>T G Manikandan</dc:creator>
      <dc:date>2004-02-09T04:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186028#M795945</link>
      <description>I think option is not set in the 1st place.&lt;BR /&gt;Hence the error message.&lt;BR /&gt;May be the logic should be reviewed&lt;BR /&gt;(inititialise option with an "invalid" option value)&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Mon, 09 Feb 2004 04:51:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186028#M795945</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-02-09T04:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186029#M795946</link>
      <description>I checked the construction :&lt;BR /&gt;Until &lt;BR /&gt;&lt;BR /&gt;The until construct is basically the same as the while construct except that the commands in the loop are executed until the conditions are true (instead of false like in the while loop). Here is the format:&lt;BR /&gt;&lt;BR /&gt;until command-list1&lt;BR /&gt;do&lt;BR /&gt;  command-list2&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;If the last command in command-list1 is unsuccessful, then the commands in command-list2 are executed. When the last command in command-list1 is successful, the until loop is terminated. Let's use the same operation in the while section to illustrate:&lt;BR /&gt;&lt;BR /&gt;until [ ! -r $1 ]&lt;BR /&gt;do&lt;BR /&gt;  cat $1 &amp;gt;&amp;gt; composite&lt;BR /&gt;done&lt;BR /&gt;Notice the subtle difference with the while loop. The ! negates the test conditions. We execute the loop until the condition is true (or successful). The while loop executes the commands while a condition is true (or successful). &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html" target="_blank"&gt;http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Feb 2004 04:58:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186029#M795946</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-02-09T04:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186030#M795947</link>
      <description>You often get this kind of problem with test when the variable you think you have isn't set.  And it won't be set if you just hit enter.&lt;BR /&gt; &lt;BR /&gt;A classic though ugly solution would be to change the test to something like&lt;BR /&gt; &lt;BR /&gt;[ "A"$option != "A" ]&lt;BR /&gt; &lt;BR /&gt;Other than that, it might just be that you need a space between the ! and the "-n"</description>
      <pubDate>Mon, 09 Feb 2004 05:04:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186030#M795947</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-02-09T05:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186031#M795948</link>
      <description>John,&lt;BR /&gt;&lt;BR /&gt;you should test [ -n "$option" ].&lt;BR /&gt;This will result in testing for "" in stead of nothing.&lt;BR /&gt;&lt;BR /&gt;Another hint:&lt;BR /&gt;&lt;BR /&gt;put in the beginning of the script:&lt;BR /&gt;set -u              # unset variable -&amp;gt; exit.&lt;BR /&gt;&lt;BR /&gt;(This will cause problems in this specific case though).&lt;BR /&gt;&lt;BR /&gt;JP.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Feb 2004 05:50:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186031#M795948</guid>
      <dc:creator>Jeroen Peereboom</dc:creator>
      <dc:date>2004-02-09T05:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186032#M795949</link>
      <description>The more I look at this, the more I'm sure that you just want that little space between the "!" and the "-n"</description>
      <pubDate>Mon, 09 Feb 2004 05:53:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186032#M795949</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-02-09T05:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186033#M795950</link>
      <description>Changed the format of the test&lt;BR /&gt;&lt;BR /&gt;[ "A"$option = "A" ]&lt;BR /&gt;&lt;BR /&gt;This works.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;John.</description>
      <pubDate>Mon, 09 Feb 2004 06:05:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186033#M795950</guid>
      <dc:creator>John Flanagan</dc:creator>
      <dc:date>2004-02-09T06:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Script error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186034#M795951</link>
      <description>This is a common situation when testing for null options. If nothing was entered, then option is null and your statement:&lt;BR /&gt; &lt;BR /&gt;[ ! -n $option ]&lt;BR /&gt; &lt;BR /&gt;is really&lt;BR /&gt; &lt;BR /&gt;[ ! -n ]&lt;BR /&gt; &lt;BR /&gt;which will be the case if you trace the execution using set -x. To tell the shell that there really is something to look at (including nothing), use the " characters around $option as in "$option" which now makes a null entry look like this:&lt;BR /&gt; &lt;BR /&gt;[ ! -n "" ]&lt;BR /&gt; &lt;BR /&gt;and that is a valid test condition. Similarly, you could test something like this:&lt;BR /&gt; &lt;BR /&gt;if [ "$option" -ne "" ]&lt;BR /&gt;then&lt;BR /&gt;...real option was entered&lt;BR /&gt;else&lt;BR /&gt;...nothing entered&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;Note that option="" is different than undefined. The default for POSIX shells is typically that an undefined variable looks like a null variable, but this can have grave consequences in sysadmin scripts (like when a spelling error causes the removal of an entire directory). Most script writers will put: set -u at the start of every script and thus, any spelling errors will stop the script when an undefined variable is used.&lt;BR /&gt; &lt;BR /&gt;There is even a way to handle unset variables when set -u is used:&lt;BR /&gt; &lt;BR /&gt;set -u&lt;BR /&gt;UNSET=IamNOTset&lt;BR /&gt;DT=${DT:-$UNSET}&lt;BR /&gt;VUE=${VUE:-$UNSET}&lt;BR /&gt;&lt;BR /&gt;if [ $VUE -ne $UNSET ]&lt;BR /&gt;then&lt;BR /&gt;...process code for VUE...&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;The :- construct will leave the variable untouched if it had been previously defined but change it to whatever follows :- if it was never defined. If necessary (such as in profile scripts), return the variable back to it's original state:&lt;BR /&gt; &lt;BR /&gt;[ $VUE = $UNSET ] &amp;amp;&amp;amp; unset VUE&lt;BR /&gt; &lt;BR /&gt;The text for UNSET is arbitrary, I just use IamNOTset since it is unlikely to be found in most variables.</description>
      <pubDate>Mon, 09 Feb 2004 10:33:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-error/m-p/3186034#M795951</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-02-09T10:33:58Z</dc:date>
    </item>
  </channel>
</rss>

