<?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: expr grep question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791475#M781507</link>
    <description>The most likely thing I can think of is that the error message "syntax error on line 1" is going to the standard error (file descriptor 2) and not standar out (file descriptor 1).&lt;BR /&gt;&lt;BR /&gt;The pipe works only with standard out I think.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;echo $(expr "abc*60"|bc) 2&amp;gt;&amp;amp;1 | grep 'syntax'&lt;BR /&gt;&lt;BR /&gt;echo $?&lt;BR /&gt;&lt;BR /&gt;And see if you now get the desired results.</description>
    <pubDate>Fri, 19 May 2006 13:25:09 GMT</pubDate>
    <dc:creator>Patrick Wallek</dc:creator>
    <dc:date>2006-05-19T13:25:09Z</dc:date>
    <item>
      <title>expr grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791474#M781506</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;i execute the following statement and then see its output&lt;BR /&gt;&lt;BR /&gt;echo $(expr " 50 * 60 "|bc ) | grep 'syntax'&lt;BR /&gt;&lt;BR /&gt;echo $?&lt;BR /&gt;return 1 because it failed to find the word syntax.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But i get the same output for this too,&lt;BR /&gt;&lt;BR /&gt;echo $(expr " abc * 60 "|bc ) | grep 'syntax'&lt;BR /&gt;&lt;BR /&gt;echo $?&lt;BR /&gt;returns 1. ( but abc*60 throws  error msg saying "syntax error on line 1, teletype" )&lt;BR /&gt;&lt;BR /&gt;whats wrong ? &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 19 May 2006 13:13:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791474#M781506</guid>
      <dc:creator>intp</dc:creator>
      <dc:date>2006-05-19T13:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: expr grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791475#M781507</link>
      <description>The most likely thing I can think of is that the error message "syntax error on line 1" is going to the standard error (file descriptor 2) and not standar out (file descriptor 1).&lt;BR /&gt;&lt;BR /&gt;The pipe works only with standard out I think.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;echo $(expr "abc*60"|bc) 2&amp;gt;&amp;amp;1 | grep 'syntax'&lt;BR /&gt;&lt;BR /&gt;echo $?&lt;BR /&gt;&lt;BR /&gt;And see if you now get the desired results.</description>
      <pubDate>Fri, 19 May 2006 13:25:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791475#M781507</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2006-05-19T13:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: expr grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791476#M781508</link>
      <description>Patrick is correct; errors in UNIX go to stderr (file descriptor 2) and grep in looking at stdin (fdes 1). In any event, you are going about this all wrong. Why not get the status of the bc command directly:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;A=50&lt;BR /&gt;B=60&lt;BR /&gt;C=$(echo "${A} * ${B}" | bc)&lt;BR /&gt;STAT=${?}&lt;BR /&gt;if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "C = ${C}"&lt;BR /&gt;  else&lt;BR /&gt;    echo "Bc failed; status = ${STAT}" &amp;gt;&amp;amp;2&lt;BR /&gt;  fi&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;&lt;BR /&gt;You don't need both expr and bc; bc will work with both integers and floting-point values so it's probably a better choice.&lt;BR /&gt;</description>
      <pubDate>Fri, 19 May 2006 13:36:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791476#M781508</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-05-19T13:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: expr grep question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791477#M781509</link>
      <description>Not sure what you are trying to get at, so I'm purely guessing:&lt;BR /&gt;&lt;BR /&gt;# echo $(expr " abc * 60 "|bc ) | grep 'syntax'&lt;BR /&gt;&lt;BR /&gt;the above throws a syntax error because "abc" is undefined and if it were then put a $ sign before it to access its value:&lt;BR /&gt;&lt;BR /&gt;# abc=10&lt;BR /&gt;# echo $(expr " $abc * 60 "|bc ) | grep 'syntax'&lt;BR /&gt;&lt;BR /&gt;And if you wanted to switch stdout and stderr around then do:&lt;BR /&gt;&lt;BR /&gt;# abc=10&lt;BR /&gt;# echo $(expr " $abc * 60 "|bc ) 1&amp;gt;&amp;amp;2 2&amp;gt;&amp;amp;1| grep 'syntax'     &lt;BR /&gt;&lt;BR /&gt;hope it helps!</description>
      <pubDate>Fri, 19 May 2006 16:08:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/expr-grep-question/m-p/3791477#M781509</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-05-19T16:08:47Z</dc:date>
    </item>
  </channel>
</rss>

