<?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: error handling in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169217#M897012</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can also use 'trap ERR' or '||'. See man sh-posix.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;trap "echo no file found" ERR&lt;BR /&gt;cat file 2&amp;gt;&amp;amp;-&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;cat file 2&amp;gt;&amp;amp;1 || echo no file found&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
    <pubDate>Wed, 21 Jan 2004 03:42:02 GMT</pubDate>
    <dc:creator>Jean-Louis Phelix</dc:creator>
    <dc:date>2004-01-21T03:42:02Z</dc:date>
    <item>
      <title>error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169213#M897008</link>
      <description>hi,&lt;BR /&gt;  i would like to know any error handling mechanism in unix scripting i.e when i used the cat command if there as no file,then it throws an error.is there any methood to catch that error,if so please let me know.&lt;BR /&gt;&lt;BR /&gt;THANKING YOU,&lt;BR /&gt;&lt;BR /&gt;HARI KRISHNA</description>
      <pubDate>Wed, 21 Jan 2004 00:36:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169213#M897008</guid>
      <dc:creator>harikrishna</dc:creator>
      <dc:date>2004-01-21T00:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169214#M897009</link>
      <description>you can check for whether the file exists and then open the file &lt;BR /&gt;&lt;BR /&gt;like&lt;BR /&gt;&lt;BR /&gt;if [ -f /&lt;DIR&gt;/&lt;FILENAME&gt; ]&lt;BR /&gt;then&lt;BR /&gt;cat &lt;FILENAME&gt;&lt;BR /&gt;else&lt;BR /&gt;echo file not present&lt;BR /&gt;fi&lt;/FILENAME&gt;&lt;/FILENAME&gt;&lt;/DIR&gt;</description>
      <pubDate>Wed, 21 Jan 2004 00:51:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169214#M897009</guid>
      <dc:creator>T G Manikandan</dc:creator>
      <dc:date>2004-01-21T00:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169215#M897010</link>
      <description>I have extracted following info from Shell's User Guide for HP9000 Servers:&lt;BR /&gt;&lt;BR /&gt;When a function or a command terminates, it sets a flag indicating the status&lt;BR /&gt;of the termination. In other words, if the function or command was successful&lt;BR /&gt;in executing, it returns a value indicating its success. The values (or error&lt;BR /&gt;codes) normally used are listed in the exit section. These values are only&lt;BR /&gt;conventions; shell scripts normally use these conventions, but programs in&lt;BR /&gt;general do not.&lt;BR /&gt;&lt;BR /&gt;When you execute a shell command incorrectly, you usually get an error&lt;BR /&gt;message. What usually happens is the shell command returns an error code.&lt;BR /&gt;If the error code is, say, 2, you will receive a message indicating a syntax error&lt;BR /&gt;has occurred.&lt;BR /&gt;&lt;BR /&gt;You can return error codes from your shell programs and functions in two&lt;BR /&gt;ways. The exit statement can return any value you specify by using the&lt;BR /&gt;following format:&lt;BR /&gt;&lt;BR /&gt;exit n&lt;BR /&gt;&lt;BR /&gt;where n can be an integer from 0 to 255. You can return error codes from&lt;BR /&gt;functions by using the return statement:&lt;BR /&gt;return n&lt;BR /&gt;&lt;BR /&gt;To check the return value of the last command you executed, you can use a&lt;BR /&gt;parameter called $?.&lt;BR /&gt;&lt;BR /&gt;sks</description>
      <pubDate>Wed, 21 Jan 2004 01:06:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169215#M897010</guid>
      <dc:creator>Sanjay Kumar Suri</dc:creator>
      <dc:date>2004-01-21T01:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169216#M897011</link>
      <description>It depends on what you want to do if an error occurs. A method might be to test the exit code of every command in your shell script by using a function you send your commands to which checks the exit code. But then you would have the same error handling for every command you run, which is sometimes not what you want.&lt;BR /&gt;&lt;BR /&gt;You could also define a function that checks $? and is called after every command with possible error-exit codes. This is the way the SG package control scripts use, for instance. It would look something like this:&lt;BR /&gt;&lt;BR /&gt;function test_exitcode {&lt;BR /&gt;   ec=$?&lt;BR /&gt;   if $ec&lt;BR /&gt;   then&lt;BR /&gt;      echo "Command returned non-null exitcode. This is not right. Exiting."&lt;BR /&gt;      exit&lt;BR /&gt;   fi&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;In your case, your script would start with the function definition and then:&lt;BR /&gt;&lt;FIRSTPART of="" the="" script=""&gt;&lt;BR /&gt;cat &lt;FILE&gt;&lt;BR /&gt;test_exitcode&lt;BR /&gt;&lt;REST of="" script=""&gt;&lt;/REST&gt;&lt;/FILE&gt;&lt;/FIRSTPART&gt;</description>
      <pubDate>Wed, 21 Jan 2004 01:47:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169216#M897011</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-01-21T01:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169217#M897012</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can also use 'trap ERR' or '||'. See man sh-posix.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;trap "echo no file found" ERR&lt;BR /&gt;cat file 2&amp;gt;&amp;amp;-&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;cat file 2&amp;gt;&amp;amp;1 || echo no file found&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Wed, 21 Jan 2004 03:42:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/error-handling/m-p/3169217#M897012</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2004-01-21T03:42:02Z</dc:date>
    </item>
  </channel>
</rss>

