<?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: Modify ksh script to accept input from file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674793#M102944</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;try this in 2nd script:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;if [ -t 0 ]&lt;BR /&gt;then&lt;BR /&gt;        echo I am not piped to, read parameter&lt;BR /&gt;        INFILE=$1&lt;BR /&gt;else&lt;BR /&gt;                while read line&lt;BR /&gt;                do&lt;BR /&gt;                        echo  processing std in from $line&lt;BR /&gt;                done&lt;BR /&gt;fi&lt;BR /&gt;~&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K</description>
    <pubDate>Fri, 18 Nov 2005 13:59:24 GMT</pubDate>
    <dc:creator>john korterman</dc:creator>
    <dc:date>2005-11-18T13:59:24Z</dc:date>
    <item>
      <title>Modify ksh script to accept input from file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674790#M102941</link>
      <description>I wrote a script (let's call it the 2nd script) to process a file, which was a required argument:&lt;BR /&gt;&lt;BR /&gt;...script [file]&lt;BR /&gt;&lt;BR /&gt;Inside the sciprt I check some stuff and go:&lt;BR /&gt;&lt;BR /&gt;...INFILE=$1&lt;BR /&gt;&lt;BR /&gt;and thenn operate on $INFILE.&lt;BR /&gt;&lt;BR /&gt;Now I find I want to pipe the output of another script (my 1st script) into my 2nd script.&lt;BR /&gt;&lt;BR /&gt;..first_script.ksh | second_script.ksh&lt;BR /&gt;&lt;BR /&gt;so that my 2nd script has no argument now.&lt;BR /&gt;&lt;BR /&gt;How do I modify the 2nd script to take standard input if no file is specified; or read a file if a file is specified?&lt;BR /&gt;&lt;BR /&gt;I tried:&lt;BR /&gt;&lt;BR /&gt;...INFILE=&amp;amp;0&lt;BR /&gt;&lt;BR /&gt;but that didn't do it...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Nov 2005 11:15:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674790#M102941</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-11-18T11:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Modify ksh script to accept input from file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674791#M102942</link>
      <description>Hi Stuart:&lt;BR /&gt;&lt;BR /&gt;Do something like this:&lt;BR /&gt;&lt;BR /&gt;[ -z "${1}" ] &amp;amp;&amp;amp; exec &amp;lt; /dev/tty || exec &amp;lt; ${1}&lt;BR /&gt;&lt;BR /&gt;...instead of :&lt;BR /&gt;&lt;BR /&gt;INFILE=$1&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 18 Nov 2005 11:32:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674791#M102942</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-11-18T11:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Modify ksh script to accept input from file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674792#M102943</link>
      <description>Stuart,&lt;BR /&gt;&lt;BR /&gt;Pipe stdin with xargs w/o changing code in the 2nd script to get the result...&lt;BR /&gt;&lt;BR /&gt;# first_script.ksh | xargs second_script.ksh&lt;BR /&gt;&lt;BR /&gt;...this way you don't need to change the definition of INFILE=$1.&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
      <pubDate>Fri, 18 Nov 2005 12:14:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674792#M102943</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2005-11-18T12:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Modify ksh script to accept input from file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674793#M102944</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;try this in 2nd script:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;if [ -t 0 ]&lt;BR /&gt;then&lt;BR /&gt;        echo I am not piped to, read parameter&lt;BR /&gt;        INFILE=$1&lt;BR /&gt;else&lt;BR /&gt;                while read line&lt;BR /&gt;                do&lt;BR /&gt;                        echo  processing std in from $line&lt;BR /&gt;                done&lt;BR /&gt;fi&lt;BR /&gt;~&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K</description>
      <pubDate>Fri, 18 Nov 2005 13:59:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674793#M102944</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2005-11-18T13:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Modify ksh script to accept input from file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674794#M102945</link>
      <description>I fear the real, correct answer to your question is going to reside in how you wrote the 2nd script.  If you make several references to the input file during your script you may have problems.&lt;BR /&gt;&lt;BR /&gt;You may only have to make very small changes to the script, you may have to do a major renovation, epically if you want to keep both capabilities.&lt;BR /&gt;&lt;BR /&gt;Another option, though somewhat less efficient, is to give your 2nd script a flag that takes piped input and just writes it to a temp file and then uses that tmp file name as the parameter for the input file.  I know thatâ  s kind of dirty and you have to remember to clean up the file at the end too but it requires less script renovation and the script works basically the same way for either piped or file name data.&lt;BR /&gt;&lt;BR /&gt;Howard</description>
      <pubDate>Mon, 21 Nov 2005 10:24:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674794#M102945</guid>
      <dc:creator>Howard Marshall</dc:creator>
      <dc:date>2005-11-21T10:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Modify ksh script to accept input from file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674795#M102946</link>
      <description>JRF led me to the correct answer:&lt;BR /&gt;&lt;BR /&gt;He wrote:&lt;BR /&gt;&lt;BR /&gt;[ -z "${1}" ] &amp;amp;&amp;amp; exec&lt;BR /&gt;The correct answer was:&lt;BR /&gt;&lt;BR /&gt;[ -z "${1}" ] &amp;amp;&amp;amp; exec&amp;lt;&amp;amp;0 || exec&amp;lt;${1}&lt;BR /&gt;&lt;BR /&gt;i.e. - take input from "stdin" if $1 zero, or from $1 if $1 is non-zero.&lt;BR /&gt;&lt;BR /&gt;Points not working - I'll do them tomorrow.</description>
      <pubDate>Mon, 05 Dec 2005 17:33:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/modify-ksh-script-to-accept-input-from-file/m-p/3674795#M102946</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2005-12-05T17:33:11Z</dc:date>
    </item>
  </channel>
</rss>

