<?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: Can I perform a &amp;quot;read&amp;quot; command from inside a &amp;quot;while read line&amp;quot; loop in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980433#M99971</link>
    <description>Yes, but you will not be able to read from stdin since that is already redirected.&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;   USERID=$(cut -d: -f1)&lt;BR /&gt;   echo "Delete user ${USERID}? (Yes/No) \c"&lt;BR /&gt;   read DUMMY &amp;lt; /dev/tty&lt;BR /&gt;   case ${DUMMY} in&lt;BR /&gt;      Yes) userdel -r ${USERID} ;;&lt;BR /&gt;   esac&lt;BR /&gt;done &amp;lt; /etc/passwd&lt;BR /&gt;&lt;BR /&gt;/dev/tty is the current terminal device.&lt;BR /&gt;&lt;BR /&gt;It would probably be a good idea to add this test BEFORE your while loop.&lt;BR /&gt;&lt;BR /&gt;if [[ ! -t 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "${0}: Not an interactive session" &amp;gt;&amp;amp;2&lt;BR /&gt;    exit 255&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;so that you do not execute your script in a non-interactive environment.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 23 May 2006 16:50:29 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2006-05-23T16:50:29Z</dc:date>
    <item>
      <title>Can I perform a "read" command from inside a "while read line" loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980432#M99970</link>
      <description>&lt;!--!*#--&gt;The following script processes (reads) every other line from my "/etc/passwd" file:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;   USERID=`cut -d: -f1`&lt;BR /&gt;   read DUMMY?"Delete user $USERID ?"&lt;BR /&gt;   case $DUMMY in&lt;BR /&gt;      Yes) userdel -r $USERID ;;&lt;BR /&gt;   esac&lt;BR /&gt;done &amp;lt; /etc/passwd&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Is there no way to use the "read DUMMY" inside a while loop that is reading lines from a file?</description>
      <pubDate>Tue, 23 May 2006 16:40:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980432#M99970</guid>
      <dc:creator>John Hall</dc:creator>
      <dc:date>2006-05-23T16:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can I perform a "read" command from inside a "while read line" loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980433#M99971</link>
      <description>Yes, but you will not be able to read from stdin since that is already redirected.&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;   USERID=$(cut -d: -f1)&lt;BR /&gt;   echo "Delete user ${USERID}? (Yes/No) \c"&lt;BR /&gt;   read DUMMY &amp;lt; /dev/tty&lt;BR /&gt;   case ${DUMMY} in&lt;BR /&gt;      Yes) userdel -r ${USERID} ;;&lt;BR /&gt;   esac&lt;BR /&gt;done &amp;lt; /etc/passwd&lt;BR /&gt;&lt;BR /&gt;/dev/tty is the current terminal device.&lt;BR /&gt;&lt;BR /&gt;It would probably be a good idea to add this test BEFORE your while loop.&lt;BR /&gt;&lt;BR /&gt;if [[ ! -t 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "${0}: Not an interactive session" &amp;gt;&amp;amp;2&lt;BR /&gt;    exit 255&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;so that you do not execute your script in a non-interactive environment.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 23 May 2006 16:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980433#M99971</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-05-23T16:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can I perform a "read" command from inside a "while read line" loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980434#M99972</link>
      <description>&lt;!--!*#--&gt;Hi John:&lt;BR /&gt;&lt;BR /&gt;You need separate file descriptors.  This is one variation:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;exec 3&amp;lt;&amp;amp;0&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;    USERID=`echo ${LINE}|cut -d: -f1`&lt;BR /&gt;    echo "Delete user $USERID ?"&lt;BR /&gt;    read -u3 DUMMY&lt;BR /&gt;    case $DUMMY in&lt;BR /&gt;       Yes) userdel -r $USERID ;;&lt;BR /&gt;    esac&lt;BR /&gt;done &amp;lt; /etc/passwd&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 23 May 2006 17:05:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980434#M99972</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-05-23T17:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Can I perform a "read" command from inside a "while read line" loop</title>
      <link>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980435#M99973</link>
      <description>Thanks guys!   The "read -u3 DUMMY" is cleaner since I do not have to test to see what the terminal device is.    However, I always like to know 2 ways to do everything so the "&amp;lt; /dev/tty" is helpful also.</description>
      <pubDate>Tue, 13 Jun 2006 11:55:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/can-i-perform-a-quot-read-quot-command-from-inside-a-quot-while/m-p/4980435#M99973</guid>
      <dc:creator>John Hall</dc:creator>
      <dc:date>2006-06-13T11:55:28Z</dc:date>
    </item>
  </channel>
</rss>

