<?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: std in &amp;amp; read problem in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205392#M10309</link>
    <description>pdksh behaves in the same manner.&lt;BR /&gt;&lt;BR /&gt;In both bash and ksh, you can also do the var=$(cut -d " " -f2,3,6) method.&lt;BR /&gt;&lt;BR /&gt;What's odd is that while 'cut -d " " -f 2,3,6 | read var' doesn't work, the following does:&lt;BR /&gt;&lt;BR /&gt;cut -d " " -f 2,3,6 | while read var; do echo $var;done&lt;BR /&gt;&lt;BR /&gt;I'm still working on trying to figure *that* one out..&lt;BR /&gt;&lt;BR /&gt;I don't have a HPUX box handy, does anybody have what the IFS is for that? ("echo $IFS | od -x" or thorugh hexdump or something).&lt;BR /&gt;&lt;BR /&gt;Both bash and ksh work with the while in there.  My thought is it has something to do with the IFS, but.. need more experimentation.</description>
    <pubDate>Mon, 01 Mar 2004 19:00:55 GMT</pubDate>
    <dc:creator>Stuart Browne</dc:creator>
    <dc:date>2004-03-01T19:00:55Z</dc:date>
    <item>
      <title>std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205388#M10305</link>
      <description>hey ,&lt;BR /&gt;&lt;BR /&gt;I am trying following command on HP-UX,&lt;BR /&gt;#date |cut -d " " -f 2,3,6 |read var&lt;BR /&gt;#echo $var&lt;BR /&gt;&amp;amp; it is showing me the value of filtered &lt;BR /&gt;date command.&lt;BR /&gt;&lt;BR /&gt;But when I am trying the following command on &lt;BR /&gt;Linux ,&lt;BR /&gt;#echo $var ,is not showing any things.&lt;BR /&gt;why?&lt;BR /&gt;&lt;BR /&gt;Amit singh</description>
      <pubDate>Mon, 01 Mar 2004 03:46:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205388#M10305</guid>
      <dc:creator>amit singh_3</dc:creator>
      <dc:date>2004-03-01T03:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205389#M10306</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You're using a different shell on Linux (Bash) than on HP-UX (ksh). You can install pdksh on Linux to also get a korn shell (ksh) there, or you could look into bash. Follow this link for more info: &lt;A href="http://www.tldp.org/LDP/abs/html/" target="_blank"&gt;http://www.tldp.org/LDP/abs/html/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Anyway, try this one:&lt;BR /&gt;# var=`date |cut -d " " -f 2,3,6`&lt;BR /&gt;# echo $var&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;&lt;BR /&gt;Robert</description>
      <pubDate>Mon, 01 Mar 2004 04:24:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205389#M10306</guid>
      <dc:creator>Robert Binkhorst</dc:creator>
      <dc:date>2004-03-01T04:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205390#M10307</link>
      <description>I like what you are trying to do but you are going about it the wrong way.  "date" has a "format" field which will output the date or bits of the date any how you like.&lt;BR /&gt; &lt;BR /&gt;var=`date +"%d %m %y"`&lt;BR /&gt; &lt;BR /&gt;Will get you what you want.&lt;BR /&gt; &lt;BR /&gt;The reason your thing didn't work on Linux is because thre is no field 6 from "date" on linux .&lt;BR /&gt; &lt;BR /&gt;THe above command will work on HPUX and Linux</description>
      <pubDate>Mon, 01 Mar 2004 04:27:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205390#M10307</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-01T04:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205391#M10308</link>
      <description>Ooops.  There is a field 6 in the Linux "date".&lt;BR /&gt; &lt;BR /&gt;However, "read" on Linux does not read from a pipe.  It should do though *scratches head*, but doesn't.</description>
      <pubDate>Mon, 01 Mar 2004 04:30:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205391#M10308</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-03-01T04:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205392#M10309</link>
      <description>pdksh behaves in the same manner.&lt;BR /&gt;&lt;BR /&gt;In both bash and ksh, you can also do the var=$(cut -d " " -f2,3,6) method.&lt;BR /&gt;&lt;BR /&gt;What's odd is that while 'cut -d " " -f 2,3,6 | read var' doesn't work, the following does:&lt;BR /&gt;&lt;BR /&gt;cut -d " " -f 2,3,6 | while read var; do echo $var;done&lt;BR /&gt;&lt;BR /&gt;I'm still working on trying to figure *that* one out..&lt;BR /&gt;&lt;BR /&gt;I don't have a HPUX box handy, does anybody have what the IFS is for that? ("echo $IFS | od -x" or thorugh hexdump or something).&lt;BR /&gt;&lt;BR /&gt;Both bash and ksh work with the while in there.  My thought is it has something to do with the IFS, but.. need more experimentation.</description>
      <pubDate>Mon, 01 Mar 2004 19:00:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205392#M10309</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-01T19:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205393#M10310</link>
      <description>I poked a SCO OSR box, and it behaves in the same manner as the HP-UX shell mentioned above.&lt;BR /&gt;&lt;BR /&gt;The IFS is the same as the Linux box..&lt;BR /&gt;&lt;BR /&gt;The mystery continues..</description>
      <pubDate>Mon, 01 Mar 2004 19:19:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205393#M10310</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-01T19:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205394#M10311</link>
      <description>Ahh, and here's the kicker!&lt;BR /&gt;&lt;BR /&gt;This has to do with the way bash/pdksh deal with pipelined commands.&lt;BR /&gt;&lt;BR /&gt;From the man page of 'bash':&lt;BR /&gt;&lt;BR /&gt;Each  command in a pipeline is executed as a separate process (i.e., in a subshell).  &lt;BR /&gt;&lt;BR /&gt;Translation:&lt;BR /&gt;&lt;BR /&gt;As the 'read' is in a pipe, a sub-shell is created.  The sub-shell thus has a private environment space, and can't be propergated back *up* the environment tree to make it into your current environment.&lt;BR /&gt;&lt;BR /&gt;So, either using "var=`command`", or "var=$(command)" are the only ways to fill a variable from the output of another command.&lt;BR /&gt;&lt;BR /&gt;*Wheee!* :) love a good mystery ;)</description>
      <pubDate>Mon, 01 Mar 2004 19:44:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205394#M10311</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-01T19:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: std in &amp; read problem</title>
      <link>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205395#M10312</link>
      <description>And the continuation of a good mystery, is a solution!&lt;BR /&gt;&lt;BR /&gt;Whee!!&lt;BR /&gt;&lt;BR /&gt;Reading through the advanced bash scripting guide (whoa, head spin), it brings up this lovely solution..&lt;BR /&gt;&lt;BR /&gt;It took me 3-4 reads to understand what the hell was going on, but once figured out, it makes sense..&lt;BR /&gt;&lt;BR /&gt;Anyway!:&lt;BR /&gt;&lt;BR /&gt;read var &amp;lt; &amp;lt;(date | cut -d " " -f 2,3,6) ; echo $var&lt;BR /&gt;&lt;BR /&gt;This introduces the variable 'var' to to the current environment, not to a subshell as it would using |'s.&lt;BR /&gt;&lt;BR /&gt;This is a 'bash' solution, and am unsure if it would work in a 'pdksh' or posix 'ksh' environment.&lt;BR /&gt;&lt;BR /&gt;Hope this helps! :)&lt;BR /&gt;&lt;BR /&gt;(Note: brief explanation..&lt;BR /&gt;&lt;BR /&gt;&amp;lt;(COMMAND)&lt;BR /&gt;&lt;BR /&gt;Basically it says that the output of 'command' will get thrown to a file descriptor.  As the above does a '&amp;lt; &amp;lt;(COMMAND)', it says take the output of 'COMMAND', and shove it into the STDIN of the read.  Thus you get the effect of a pipe, without creating a subshell.)</description>
      <pubDate>Thu, 11 Mar 2004 00:23:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/std-in-amp-read-problem/m-p/3205395#M10312</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-03-11T00:23:17Z</dc:date>
    </item>
  </channel>
</rss>

