<?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: wc -l if an if statement in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180472#M162803</link>
    <description>if [[ $(wc -l somefile) -ne 30 ]]&lt;BR /&gt;then&lt;BR /&gt;  blah&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Note that a space between [[ and $(.. is required as well as the end. 30 ]].&lt;BR /&gt;&lt;BR /&gt;In Korn or POSIX the '[[ .. ]]' double brackets are preferred because they use the shell's internal test command rather than spawning a new process for test.&lt;BR /&gt;</description>
    <pubDate>Mon, 02 Feb 2004 13:56:16 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2004-02-02T13:56:16Z</dc:date>
    <item>
      <title>wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180469#M162800</link>
      <description>I am trying to write a script that would do a wc -l on a file, and if it is not equal to 30, yada yada..&lt;BR /&gt;&lt;BR /&gt;if [ `wc -l` somefile -ne 30 ]&lt;BR /&gt;then&lt;BR /&gt;   blah...&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;but I keep getting errors.&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Feb 2004 13:45:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180469#M162800</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-02-02T13:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180470#M162801</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I would try something like:&lt;BR /&gt;&lt;BR /&gt;NUM=`wc -l`&lt;BR /&gt;&lt;BR /&gt;if [ $NUM -ne 30 ]&lt;BR /&gt;then &lt;BR /&gt;    do something&lt;BR /&gt;else&lt;BR /&gt;    do something_different&lt;BR /&gt;&lt;BR /&gt;Hope this helps!&lt;BR /&gt;-Bryan</description>
      <pubDate>Mon, 02 Feb 2004 13:47:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180470#M162801</guid>
      <dc:creator>Bryan D. Quinn</dc:creator>
      <dc:date>2004-02-02T13:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180471#M162802</link>
      <description>Ooops forgot my ending fi...&lt;BR /&gt;&lt;BR /&gt;-Bryan</description>
      <pubDate>Mon, 02 Feb 2004 13:47:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180471#M162802</guid>
      <dc:creator>Bryan D. Quinn</dc:creator>
      <dc:date>2004-02-02T13:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180472#M162803</link>
      <description>if [[ $(wc -l somefile) -ne 30 ]]&lt;BR /&gt;then&lt;BR /&gt;  blah&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Note that a space between [[ and $(.. is required as well as the end. 30 ]].&lt;BR /&gt;&lt;BR /&gt;In Korn or POSIX the '[[ .. ]]' double brackets are preferred because they use the shell's internal test command rather than spawning a new process for test.&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Feb 2004 13:56:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180472#M162803</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-02-02T13:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180473#M162804</link>
      <description>It seems to me that yours will work if you put your ticks in the right place.&lt;BR /&gt;&lt;BR /&gt;`wc -l somefile`&lt;BR /&gt;&lt;BR /&gt;instead of:&lt;BR /&gt;&lt;BR /&gt;`wc -l` somefile</description>
      <pubDate>Mon, 02 Feb 2004 14:00:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180473#M162804</guid>
      <dc:creator>Todd McDaniel_1</dc:creator>
      <dc:date>2004-02-02T14:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180474#M162805</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You would get errors because 'wc -l somefile' will produce two fields and the way in which you are putting the ticks (the ticks should cover the entire command like `wc -l somefile`)&lt;BR /&gt;&lt;BR /&gt;$wc -l myfile&lt;BR /&gt;123 myfile&lt;BR /&gt;&lt;BR /&gt;So, you would need to do either of the following&lt;BR /&gt;&lt;BR /&gt;if [ $(wc -l myfile|awk '{print $1}') -ne 30 ]&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;if [ $(cat myfile|wc -l) -ne 30 ]&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Mon, 02 Feb 2004 14:01:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180474#M162805</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-02-02T14:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180475#M162806</link>
      <description>note:&lt;BR /&gt;&lt;BR /&gt;var=`wc -l somefile`&lt;BR /&gt;&lt;BR /&gt;is no longer convention for such scripts. New scripts probably should not be done that way. I suppose support in the shell for the methodology will someday be pulled.&lt;BR /&gt;&lt;BR /&gt;var=$(wc -l somefile)&lt;BR /&gt;&lt;BR /&gt;is the current convention.&lt;BR /&gt;&lt;BR /&gt;A. Clay's method looks simple and straightforward, Shridar's looks very slick.&lt;BR /&gt;&lt;BR /&gt;Nicely done.&lt;BR /&gt;&lt;BR /&gt;SEP&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Feb 2004 14:12:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180475#M162806</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2004-02-02T14:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180476#M162807</link>
      <description>Oops,&lt;BR /&gt;&lt;BR /&gt;that should be&lt;BR /&gt;&lt;BR /&gt;FNAME=somefile&lt;BR /&gt;if [[ $(cat ${FNAME} | wc -l) -ne 30 ]]&lt;BR /&gt;then&lt;BR /&gt;blah&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;and a still more robust version would first test for the existence of the file:&lt;BR /&gt;&lt;BR /&gt;FNAME=somefile&lt;BR /&gt;if [[ -r "${FNAME} ]]&lt;BR /&gt;then&lt;BR /&gt;  if [[ $(cat ${FNAME} | wc -l) -ne 30 ]]&lt;BR /&gt;    then&lt;BR /&gt;      blah&lt;BR /&gt;    fi&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Feb 2004 14:24:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180476#M162807</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-02-02T14:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180477#M162808</link>
      <description>Oops again. My first post should have been:&lt;BR /&gt;&lt;BR /&gt;NUM=`cat somefile | wc -l`&lt;BR /&gt;&lt;BR /&gt;if [ $NUM -ne 30 ]&lt;BR /&gt;then &lt;BR /&gt;do something&lt;BR /&gt;else&lt;BR /&gt;do something_different&lt;BR /&gt;&lt;BR /&gt;Sorry about that.&lt;BR /&gt;&lt;BR /&gt;-Bryan</description>
      <pubDate>Mon, 02 Feb 2004 15:39:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180477#M162808</guid>
      <dc:creator>Bryan D. Quinn</dc:creator>
      <dc:date>2004-02-02T15:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: wc -l if an if statement</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180478#M162809</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;another short solution:&lt;BR /&gt;&lt;BR /&gt;if [ $(wc -l &lt;SOMEFILE&gt;&lt;/SOMEFILE&gt;then bla&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Tue, 03 Feb 2004 07:23:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/wc-l-if-an-if-statement/m-p/3180478#M162809</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2004-02-03T07:23:50Z</dc:date>
    </item>
  </channel>
</rss>

