<?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 Help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212262#M678722</link>
    <description>&amp;gt;svo: but what he does is shorten the test command and if a look at 'man test' i find:&lt;BR /&gt;&lt;BR /&gt;No test(1) commands here?  [ ] is the shorthand for that.&lt;BR /&gt;(( )) is sh/ksh arithmetic expression evaluation.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I have as well never seen an explanation to use () for test&lt;BR /&gt;&lt;BR /&gt;You use () if you have to evaluate things other than operator precedence:&lt;BR /&gt;if [ $a -eq 1 -a \( $b -eq 1 -o $c -eq 1 \) ]; then&lt;BR /&gt;&lt;BR /&gt;And you can toss that and use C style:&lt;BR /&gt;if (( a == 1 &amp;amp;&amp;amp; (b == 1 || c == 1) )); then</description>
    <pubDate>Fri, 04 Dec 2009 12:48:08 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2009-12-04T12:48:08Z</dc:date>
    <item>
      <title>Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212255#M678715</link>
      <description>As someone who will admit i am utterly rubbish at scripting can someone possibly help with what i am guessing is not a difficult question..&lt;BR /&gt;&lt;BR /&gt;I have been asked to look at a test script someone did that checks for the existance of a file on a remote server. &lt;BR /&gt;&lt;BR /&gt;I have attached the script in a notepad document but i dont understand really what it is doing especially with the line that i think is trying to establish what the variable OK is..&lt;BR /&gt;&lt;BR /&gt;So if anyone would be kind enough to offer some guidance as to what this script is doing particulary round the section at the end of line 3 and then why the 2 IF statements have different brackets.&lt;BR /&gt;&lt;BR /&gt;Many Thanks</description>
      <pubDate>Wed, 02 Dec 2009 12:50:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212255#M678715</guid>
      <dc:creator>Acxiom Unix Team</dc:creator>
      <dc:date>2009-12-02T12:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212256#M678716</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;timestamp=$(date) # Put the actual date in a variabel&lt;BR /&gt;USER=sweb     # define username sweb&lt;BR /&gt;OK=$(remsh uk208 -l $USER "ls /census/script/jobsub 1&amp;gt;&amp;amp;2 &amp;amp;&amp;amp; echo ok || echo err") # list the file /census/script/jobsub on host uk208 via remshell if it is there, OK else err&lt;BR /&gt;if (( $? != 0 )) # this is crap it, it check for the errorlevel of the previous command with a wrong syntax, it should be if [[ $? -ne 0 ]]&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;feel free to ask, if you want to know more.&lt;BR /&gt;&lt;BR /&gt;Stephan</description>
      <pubDate>Wed, 02 Dec 2009 13:06:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212256#M678716</guid>
      <dc:creator>Stephan._1</dc:creator>
      <dc:date>2009-12-02T13:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212257#M678717</link>
      <description>timestamp is a variable that is assigned the current result of the date command. USER is a variable assigned the text string sweb.&lt;BR /&gt; &lt;BR /&gt;OK is a variable that is assigned the result of everything inside $(...). Inside $(...) there is a remsh command to server uk208 which logs in as user sweb. ERverything inside the double quotes "" is run on the remote system uk208. Ths ls command simply returns the status of the named file.&lt;BR /&gt; &lt;BR /&gt;The 2&amp;gt;&amp;amp;1 redirects error messages (such as file not found) to stdout rather than stderr. The &amp;amp;&amp;amp; and || are true and false conditions -- if the ls command is successful, then OK is returned as the value for $(...) and if not, then err is returned.&lt;BR /&gt; &lt;BR /&gt;The next line ((...)) is a bit non-standard but works OK. The ((...)) could be replaced with [[...]] as seen in the next test, or even [...] -- the results are the same in this context. The (( $?!= 0 )) tests the return code from remsh. If remsh fails, it could not connect or resolve the name uk208. If the return code from remsh ($?) is not zero then the message is sent using mailx with option -s being the subject of the email.&lt;BR /&gt; &lt;BR /&gt;The last test checks $OK ($OK means substitute the contents of the variable OK) and mails the failure message using mailx.&lt;BR /&gt; &lt;BR /&gt;In both tests, the return code from the script is -1 for problems and by default, 0 if the script reaches the bottom.</description>
      <pubDate>Wed, 02 Dec 2009 13:25:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212257#M678717</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2009-12-02T13:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212258#M678718</link>
      <description>Thanks guys for the help. &lt;BR /&gt;&lt;BR /&gt;I need to find some good places to learn this stuff as just get lost trying to understand what everything means...&lt;BR /&gt;&lt;BR /&gt;Any good sites/books/forums you can recommend?&lt;BR /&gt;&lt;BR /&gt;Thanks again.</description>
      <pubDate>Wed, 02 Dec 2009 13:42:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212258#M678718</guid>
      <dc:creator>Acxiom Unix Team</dc:creator>
      <dc:date>2009-12-02T13:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212259#M678719</link>
      <description>Hi Andrew:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I need to find some good places to learn this stuff as just get lost trying to understand what everything means...Any good sites/books/forums you can recommend?&lt;BR /&gt;&lt;BR /&gt;There are any number of good books on shell programming.  Avoid the C-shell ('csh') which is dysfunctional.  For HP-UX use the Posix shell ('/usr/bin/sh') which is the HP standard.  It's very close to the Korn88 shell ('/usr/bin/ksh').&lt;BR /&gt;&lt;BR /&gt;A free guide to begin with is:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.hp.com/en/B2355-90046/index.html" target="_blank"&gt;http://docs.hp.com/en/B2355-90046/index.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;An excellent site for examples and code is:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.shelldorado.com/" target="_blank"&gt;http://www.shelldorado.com/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 02 Dec 2009 13:54:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212259#M678719</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-02T13:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212260#M678720</link>
      <description>&amp;gt;svo: if (( $? != 0 ))&lt;BR /&gt;&amp;gt;with a wrong syntax, it should be if [[ $? -ne 0 ]]&lt;BR /&gt;&lt;BR /&gt;This syntax is perfectly valid.  It uses C syntax within (( )) for arithmetic expressions.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Bill: The next line ((...)) is a bit non-standard but works OK.&lt;BR /&gt;&lt;BR /&gt;This "if (())" is Posix standard, so no need to change it.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;as seen in the next test, or even [...] &lt;BR /&gt;&lt;BR /&gt;If using [[ ]] or [ ], that != should be replaced by -eq, for arithmetic compare.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;the return code from the script is -1 for problems &lt;BR /&gt;&lt;BR /&gt;This isn't really a good idea to use -1 for UNIX, since exit status is typically truncated to 0..255.</description>
      <pubDate>Thu, 03 Dec 2009 08:53:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212260#M678720</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-03T08:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212261#M678721</link>
      <description>I'm always willing to learn something new but what he does is shorten the test command and if a look at 'man test' i find:&lt;BR /&gt;&lt;BR /&gt;test(1)&lt;BR /&gt;&lt;BR /&gt; NAME&lt;BR /&gt;      test - condition evaluation command&lt;BR /&gt;&lt;BR /&gt; SYNOPSIS&lt;BR /&gt;      test expr&lt;BR /&gt;&lt;BR /&gt;      [ expr ]&lt;BR /&gt;&lt;BR /&gt; DESCRIPTION&lt;BR /&gt;The test command evaluates the expression expr and, if its value is True, returns a Zero (true) exit status; otherwise, a nonzero (false) exit status is returned.  test also returns a nonzero exit status if there are no arguments. &lt;BR /&gt;...&lt;BR /&gt;( expr )       Parentheses for grouping.&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;I have as well never seen an explanation to use () for test, but perhaps you can give me hand and point to some documentation.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance</description>
      <pubDate>Thu, 03 Dec 2009 14:35:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212261#M678721</guid>
      <dc:creator>Stephan._1</dc:creator>
      <dc:date>2009-12-03T14:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212262#M678722</link>
      <description>&amp;gt;svo: but what he does is shorten the test command and if a look at 'man test' i find:&lt;BR /&gt;&lt;BR /&gt;No test(1) commands here?  [ ] is the shorthand for that.&lt;BR /&gt;(( )) is sh/ksh arithmetic expression evaluation.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I have as well never seen an explanation to use () for test&lt;BR /&gt;&lt;BR /&gt;You use () if you have to evaluate things other than operator precedence:&lt;BR /&gt;if [ $a -eq 1 -a \( $b -eq 1 -o $c -eq 1 \) ]; then&lt;BR /&gt;&lt;BR /&gt;And you can toss that and use C style:&lt;BR /&gt;if (( a == 1 &amp;amp;&amp;amp; (b == 1 || c == 1) )); then</description>
      <pubDate>Fri, 04 Dec 2009 12:48:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212262#M678722</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-04T12:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212263#M678723</link>
      <description>Hmm, ok :-)&lt;BR /&gt;&lt;BR /&gt;So just to confuse me completely:&lt;BR /&gt;&lt;BR /&gt;test $? != 0&lt;BR /&gt;&lt;BR /&gt;[ $? -ne 0 ]&lt;BR /&gt;&lt;BR /&gt;[[ $? -ne 0 ]]&lt;BR /&gt;&lt;BR /&gt;(( $? != 0 ))&lt;BR /&gt;&lt;BR /&gt;is all correct syntax and give the same result? In my opinion i should go with one version in a script and not mix it up.&lt;BR /&gt;&lt;BR /&gt;Anyway thanks for the explanation.</description>
      <pubDate>Fri, 04 Dec 2009 13:59:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212263#M678723</guid>
      <dc:creator>Stephan._1</dc:creator>
      <dc:date>2009-12-04T13:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212264#M678724</link>
      <description>&amp;gt;svo: So just to confuse me completely:&lt;BR /&gt;&amp;gt;test $? != 0&lt;BR /&gt;&lt;BR /&gt;This isn't valid for all possible cases.  I.e. it is a string compare.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;[ $? -ne 0 ] [[ $? -ne 0 ]] (( $? != 0 ))&lt;BR /&gt;&amp;gt;is all correct syntax and give the same result?&lt;BR /&gt;&lt;BR /&gt;These are valid.  The first is more efficient than: test $? -ne 0</description>
      <pubDate>Sat, 05 Dec 2009 02:28:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212264#M678724</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-05T02:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212265#M678725</link>
      <description>&amp;gt; This isn't valid for all possible cases. I.e. it is a string compare.&lt;BR /&gt;&lt;BR /&gt;One of the reasons i would love to have an edit button here, that was too much !0 and -ne for me i saw it as i cross checked the posting of course after submitting.&lt;BR /&gt;&lt;BR /&gt;Once more thanks for the explanations, the syntax with (()) was completly new for me.</description>
      <pubDate>Mon, 07 Dec 2009 11:03:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212265#M678725</guid>
      <dc:creator>Stephan._1</dc:creator>
      <dc:date>2009-12-07T11:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212266#M678726</link>
      <description>I got the assistance i required...Thanks</description>
      <pubDate>Mon, 07 Dec 2009 13:27:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5212266#M678726</guid>
      <dc:creator>Acxiom Unix Team</dc:creator>
      <dc:date>2009-12-07T13:27:02Z</dc:date>
    </item>
  </channel>
</rss>

