<?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: awk exit status in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699331#M638552</link>
    <description>&lt;P&gt;just to be precise with my code as per my previous post&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;some_command | awk '&lt;/P&gt;&lt;P&gt;/retrive_this_value/&amp;nbsp; { # if the value is none ie blank then exit the program but it doesn't exit and goes further, i don't know how to check the blank character here , i tried "" but obviously that didn't work for me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; " $NF&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; FOUND=1&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;END {&lt;/P&gt;&lt;P&gt;if ( FOUND != 1 ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; Not assigned--exiting program"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 2&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}'&lt;/P&gt;&lt;P&gt;if [ $? -ne 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 2&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
    <pubDate>Sun, 24 Jun 2012 09:22:39 GMT</pubDate>
    <dc:creator>Nadie_1</dc:creator>
    <dc:date>2012-06-24T09:22:39Z</dc:date>
    <item>
      <title>Question with my awk section</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5698883#M638543</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2012 00:26:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5698883#M638543</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-10-06T00:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5698983#M638544</link>
      <description>&lt;P&gt;&amp;gt;all I need is either exit with 0 or non zero&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;END { if (FOUND != 1) {print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSM Server&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; Not configured"; exit 1}}'&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2012 05:59:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5698983#M638544</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-23T05:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699061#M638545</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the suggesstion I have tried putting exit 1 where u suggessted and simulated the&amp;nbsp;test again but script doesn't exist with non zero ??&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2012 11:39:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699061#M638545</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-23T11:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699217#M638546</link>
      <description>&lt;P&gt;&amp;gt;but script doesn't exit with non zero?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please paste your script so we can verify.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Jun 2012 23:12:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699217#M638546</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-23T23:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699293#M638549</link>
      <description>&lt;P&gt;&amp;gt; Above is the excerpt again, script itself works fine but doesn't exit with non zero code even when it is not registered.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't see my exit 1.&amp;nbsp; I also don't see what is after awk.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/usr/bin/dsmc q se | awk '&lt;/P&gt;&lt;P&gt;/Server Name/&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSM Server&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; " $NF&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; FOUND=1&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;END {&lt;/P&gt;&lt;P&gt;if ( FOUND != 1 ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSM Server&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; Not configured"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 1&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}'&lt;/P&gt;&lt;P&gt;if [ $? -ne 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 1&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;Here is set -x for your perusal,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see more than what you have in your script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;exit status is 1 but it still goes ahead&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have to check for it.&amp;nbsp; Or use "set -e".&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jun 2012 06:42:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699293#M638549</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-24T06:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699331#M638552</link>
      <description>&lt;P&gt;just to be precise with my code as per my previous post&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;some_command | awk '&lt;/P&gt;&lt;P&gt;/retrive_this_value/&amp;nbsp; { # if the value is none ie blank then exit the program but it doesn't exit and goes further, i don't know how to check the blank character here , i tried "" but obviously that didn't work for me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; " $NF&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; FOUND=1&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;END {&lt;/P&gt;&lt;P&gt;if ( FOUND != 1 ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp; Not assigned--exiting program"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 2&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}'&lt;/P&gt;&lt;P&gt;if [ $? -ne 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 2&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jun 2012 09:22:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699331#M638552</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-24T09:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699525#M638553</link>
      <description>&lt;P&gt;&amp;gt;this is great help, I have got what I wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are happy with the answers you were given, please click on the Kudos stars of each helpful post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;lspath -l hdisk1 -s Enabled|grep fscsi|grep Enabled&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can optimize this to one grep:&lt;/P&gt;&lt;P&gt;lspath -l hdisk1 -s Enabled | grep "Enabled.*fscsi"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can use "grep -c" to count and with a real shell should use $() vs ``:&lt;/P&gt;&lt;P&gt;DSKPATH=$(lspath -l $DISK -s Enabled | grep -c "Enabled.*fscsi") # this counts for 2 paths 1 per adapter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if [ $DSKPATH -lt 2 ]; then&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; echo "We don't have dual paths--exiting program now--"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; exit 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; fi&lt;/P&gt;&lt;P&gt;done&lt;/P&gt;&lt;P&gt;echo "We have dual paths for all disks"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;parameter&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # space - means there is no value assigned, and if it is true then simply exit the program)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could use:&lt;/P&gt;&lt;P&gt;if [ "$parameter" = "" ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;if the value is none ie blank then exit the program&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to check for an empty line, you can do:&lt;/P&gt;&lt;P&gt;/^#/ { exit 1}&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jun 2012 20:52:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699525#M638553</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-24T20:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699545#M638554</link>
      <description>&lt;P&gt;Thanks again , you have been great assist, I will test it and let you know if I have any hiccup but this should now resolve my hiccups :)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've clicked on start to assign points but it only seems to add 1 point, is this maximum we can assign ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;once i have tested it i will close this thread by marking as "accept this as solution", i may have to ask some more question tho...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jun 2012 22:41:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5699545#M638554</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-24T22:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5700977#M638556</link>
      <description>&lt;P&gt;&amp;gt;it only seems to add 1 point, is this maximum we can assign?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, one per post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;return 1 # not sure if this is where I need return or else where please correct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, this will work for functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;if [ "$NF" = "" ]; then # How to check - :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why bother?&amp;nbsp; If you don't get a good exit status (0), you didn't find what you wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you do want to check, you can just check in awk for:&lt;/P&gt;&lt;P&gt;if ($NF == ":")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;return 0 # Please correct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SInce you aren't in an awk function, I would just use:&amp;nbsp; exit 0&lt;/P&gt;&lt;P&gt;(In fact, awk will not let you use return unless you are in a function.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;# Main and do I need to execute my functions below?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2012 02:28:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5700977#M638556</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-26T02:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701063#M638557</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again few more quest, my questions are next to # below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;return 1 # not sure if this is where I need return or else where please correct, i will test this today tho&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, this will work for functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;if [ "$NF" = "" ]; then # How to check - :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why bother?&amp;nbsp; If you don't get a good exit status (0), you didn't find what you wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you do want to check, you can just check in awk for:&lt;/P&gt;&lt;P&gt;if ($NF == ":")&amp;nbsp; # So this check goes into the same place where I'm currently checking in my script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;return 0 # Please correct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SInce you aren't in an awk function, I would just use:&amp;nbsp; exit 0&lt;/P&gt;&lt;P&gt;# Even if I'm not in awk i need to check return 1 or return 0, so i can make it uniform in the script&lt;/P&gt;&lt;P&gt;I guess i can replace return 1 with exit 1 which i originally had but where to check return 0 tho ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;# Main and do I need to execute my functions below?&lt;/P&gt;&lt;P&gt;# The way i have stuff in my main, is this the correct way of checking it or am i missing anything such as executing function etc&amp;nbsp;? please correct&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 21:57:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701063#M638557</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-25T21:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701065#M638558</link>
      <description>&lt;P&gt;sorry in one of my comment i meant to say i can replace exit 1 which i originally has in my code with return 1 but where to place return 0 tho ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also pls correct me where to place return 1 and return 0 within awk function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then in my main if I need to execute my functions and then check status with if statement or the way i currently have in my script is OK ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help really this clarifies and helps me learn a lot&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2012 22:01:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701065#M638558</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-25T22:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701197#M638559</link>
      <description>&lt;P&gt;&amp;gt;# Even if I'm not in awk I need to check return 1 or return 0, so I can make it uniform in the script&lt;/P&gt;&lt;P&gt;&amp;gt;I guess I can replace return 1 with exit 1 which I originally had but where to check return 0 though?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are in an awk function, you can use return, to return a value.&amp;nbsp; If you want to exit awk, you use exit.&lt;/P&gt;&lt;P&gt;In a shell function, you can use return, unless you want to exit the script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;P&gt;&amp;gt;in one of my comment I meant to say I can replace exit 1 which I originally has in my code with return 1 but where to place return 0 though?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;gt;pls correct me where to place return 1 and return 0 within awk function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can only use exit, not return.&amp;nbsp; In your case, you only need "exit 1", since "exit 0" is done on a normal exit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;in my main if I need to execute my functions and then check status with if statement or the way I currently have in my script is OK?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's ok if you use a Posix shell but not ksh88.&lt;/P&gt;&lt;P&gt;Otherwise you need:&lt;/P&gt;&lt;P&gt;if [ ! check_tsm_reg ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or you could use:&lt;/P&gt;&lt;P&gt;check_tsk_reg || status=1&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Jun 2012 02:48:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701197#M638559</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-26T02:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701717#M638560</link>
      <description>&lt;P&gt;Thanks again, I will test it but if you can correct my script with your suggestion it will save me sometime as im doing many things, however im trying myself too to get this sorted ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;correct me if im wrong if I have exit 1 within awk function then it still exits the program rather then just exiting the awk function and continue with further instruction ie functions, i don't want to exit the program, i just want to capture return code 1 if error and then exit only after completing everything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also some_command display in the below format, if it is assigned it gives out some number and in this case i would like to return with rc 0&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;Online Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;: 3.00&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;If not assigned then it displays blank with ie&amp;nbsp;(colon space -)&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;Variable Memory Capacity Weight&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&amp;nbsp; - (colon space -) i really need to capture (dash) i think since if the memory is available then it still prints colon (:)&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;i can't capture this with&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;if [ "$NF" == "-" ]; then&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;print "online memory is not configured, return 1"&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;return 1 #( at this stage if it type exit 1 it will exit the program which i don't want it)&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;can you please kindly correct my script that I posted with proper code so i can write more functions once i get the funtion both awk and shell functions right I can write several more functions. Please correct me if im not capturing the return code properly in my script, as i want to exit with either 0 or 1 , since i set my variable $success to 0....&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;Much appreciate your help&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2012 09:32:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701717#M638560</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-26T09:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701719#M638561</link>
      <description>&lt;P&gt;by the way im using korn shell--thnx&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2012 09:33:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5701719#M638561</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-26T09:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5702401#M638562</link>
      <description>&lt;P&gt;&amp;gt;if I have exit 1 within awk function then it still exits the program rather then just exiting the awk function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right, it only exits awk.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;some_command display in the below format, if it is assigned it gives out some number and in this case I would like to return with rc 0&lt;BR /&gt;&amp;gt;Online Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 3.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't exit awk with "exit 1", it will exit with 0.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Variable Memory Capacity Weight&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&amp;nbsp; - (colon space -) I really need to capture (dash)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In awk, you check with:&lt;/P&gt;&lt;P&gt;if ($NF == "-")&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "online memory is not configured, return 1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 1&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then in your script, you check for the bad awk exit status and return from that function.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2012 18:46:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5702401#M638562</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-26T18:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5702563#M638563</link>
      <description>&lt;P&gt;Can you please give me an example based on my script template how we capture the status , i tested it with exit 1 but it exits the program, and when i put return it complains that return should be within awk statement etc ? although i think i've put return 1 within awk......but anyway we can use exit 1 within awk since you recon it won't exit the program but appreciate if u can&amp;nbsp; correct my code---thanks&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2012 21:47:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5702563#M638563</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-26T21:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5702605#M638564</link>
      <description>&lt;P&gt;&amp;gt;Can you please give me an example based on my script template how we capture the status&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm confused in your command output format.&amp;nbsp; You mentioned:&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;gt;Online Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;: 3.00&lt;/P&gt;&lt;P class="ecxMsoNormal"&gt;&amp;gt;If not assigned then it displays blank with ie&amp;nbsp;(colon space -)&lt;/P&gt;&lt;P&gt;&amp;gt;Variable Memory Capacity Weight&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&amp;nbsp; - (colon space -)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does the one "Some_command" produce both outputs?&amp;nbsp; Or there are two commands?&lt;/P&gt;&lt;P&gt;If you are only looking for "Variable Memory Capacity Weight" and need to check for "-", you can do:&lt;/P&gt;&lt;P&gt;Some_command | awk '&lt;/P&gt;&lt;P&gt;/Variable Memory Capacity Weight/ {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if ($NF == "-") next&amp;nbsp;&amp;nbsp; # see if better value later?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "Memory = " $NF&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; FOUND=1&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;END {&lt;/P&gt;&lt;P&gt;if ( FOUND != 1 ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print " Virtual Memory is not OK"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; exit 3&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}'&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jun 2012 23:52:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5702605#M638564</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-26T23:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5703901#M638567</link>
      <description>&lt;P&gt;&amp;gt;Online Virtual Memory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then why are you looking for: "^Variable Memory Capacity Weight"&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2012 16:31:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5703901#M638567</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-27T16:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5704133#M638568</link>
      <description>&lt;P&gt;sorry please ignore that, it should be read as "Virtual Online Memory"---my typo but in my actual script I have "Online Virtual Memory" instead of "Variable Capacity Weight"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;problem is that script doesn't pick up (-) if it's not assigned and doesn't return NON zero return code ?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2012 22:09:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5704133#M638568</guid>
      <dc:creator>Nadie_1</dc:creator>
      <dc:date>2012-06-27T22:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: awk exit status</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5704383#M638569</link>
      <description>&lt;P&gt;&amp;gt;MEMORY=`some_command | grep "^Variable Memory Capacity Weight" | awk -F: '{print $2}'`&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With -F:, you need to look for " -".&amp;nbsp; But better to only use the default delimiter and remove the grep:&lt;/P&gt;&lt;P&gt;MEMORY=$(some_command | awk '/^Virtual Online Memory/ {print $NF}')&lt;/P&gt;&lt;P&gt;if [ "$MEMORY" != "-" -a "$MEMORY" != "" ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; echo "memory is configured"&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; print "memory is not configured"&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jun 2012 05:03:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/question-with-my-awk-section/m-p/5704383#M638569</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-28T05:03:08Z</dc:date>
    </item>
  </channel>
</rss>

