<?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: ctrl-d in while statement in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742116#M101320</link>
    <description>This is not generally a good idea.  Control-D is usually mapped to EOF; you can do stty -a to see this.  Howevery, these values are all change able.  For example, it's possible to map control-D to intr (which is usually a control-c) and then you'd have problems.  &lt;BR /&gt;&lt;BR /&gt;Having said that, you can do this:&lt;BR /&gt;&lt;BR /&gt;char=""&lt;BR /&gt;while [[ $char -ne "^D" ]]&lt;BR /&gt;do&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt; stty raw;char=`dd if=/dev/tty count=1 2&amp;gt;/dev/null`;stty -raw&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and that may work for you.&lt;BR /&gt;&lt;BR /&gt;mark</description>
    <pubDate>Wed, 01 Mar 2006 16:34:15 GMT</pubDate>
    <dc:creator>Mark Greene_1</dc:creator>
    <dc:date>2006-03-01T16:34:15Z</dc:date>
    <item>
      <title>ctrl-d in while statement</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742113#M101317</link>
      <description>I want to write a while statement to take user input, until user hit ctrl-d, how do I do that?&lt;BR /&gt;&lt;BR /&gt;thank YOU</description>
      <pubDate>Wed, 01 Mar 2006 16:16:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742113#M101317</guid>
      <dc:creator>Gemini_2</dc:creator>
      <dc:date>2006-03-01T16:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: ctrl-d in while statement</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742114#M101318</link>
      <description>Hi Gemini:&lt;BR /&gt;&lt;BR /&gt;# while read LINE&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; echo "I read: ${LINE}"&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;...to stop, use CTL_D.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 01 Mar 2006 16:20:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742114#M101318</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-01T16:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: ctrl-d in while statement</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742115#M101319</link>
      <description>so easy, I complicated the problem.&lt;BR /&gt;&lt;BR /&gt;thank YOU</description>
      <pubDate>Wed, 01 Mar 2006 16:23:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742115#M101319</guid>
      <dc:creator>Gemini_2</dc:creator>
      <dc:date>2006-03-01T16:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: ctrl-d in while statement</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742116#M101320</link>
      <description>This is not generally a good idea.  Control-D is usually mapped to EOF; you can do stty -a to see this.  Howevery, these values are all change able.  For example, it's possible to map control-D to intr (which is usually a control-c) and then you'd have problems.  &lt;BR /&gt;&lt;BR /&gt;Having said that, you can do this:&lt;BR /&gt;&lt;BR /&gt;char=""&lt;BR /&gt;while [[ $char -ne "^D" ]]&lt;BR /&gt;do&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt; stty raw;char=`dd if=/dev/tty count=1 2&amp;gt;/dev/null`;stty -raw&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and that may work for you.&lt;BR /&gt;&lt;BR /&gt;mark</description>
      <pubDate>Wed, 01 Mar 2006 16:34:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742116#M101320</guid>
      <dc:creator>Mark Greene_1</dc:creator>
      <dc:date>2006-03-01T16:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: ctrl-d in while statement</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742117#M101321</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I agree with Mark.&lt;BR /&gt;Control chars can be problematic - especially for ttytype issues - even sessions themselves.&lt;BR /&gt;It's better to use standard alpha ASCII chars like "Q/q" for quit, "E/e" for exit, etc. Even whole words like quit or exit.&lt;BR /&gt;These are easily programable with case statements.&lt;BR /&gt;&lt;BR /&gt;My $0.02,&lt;BR /&gt;Jeff</description>
      <pubDate>Wed, 01 Mar 2006 16:46:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742117#M101321</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2006-03-01T16:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: ctrl-d in while statement</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742118#M101322</link>
      <description>Another technique is to check that the line is empty (user just pressed CR), something like this:&lt;BR /&gt; &lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;if [ -z "$LINE" ]&lt;BR /&gt;then&lt;BR /&gt; echo "User entered nothing, exiting..."&lt;BR /&gt; exit&lt;BR /&gt;fi&lt;BR /&gt;...process other $LINE contents...&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;Be sure to quote "$LINE" to properly handle a null input.</description>
      <pubDate>Wed, 01 Mar 2006 17:24:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ctrl-d-in-while-statement/m-p/3742118#M101322</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2006-03-01T17:24:49Z</dc:date>
    </item>
  </channel>
</rss>

