<?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: scripts problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242405#M891165</link>
    <description>No problem. Here is a function that will work in POSIX or Korn shell:&lt;BR /&gt; &lt;BR /&gt;###########################################&lt;BR /&gt;function GetChar1&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;# Read 1 character and return as first argument&lt;BR /&gt;# example: GetChar1 MYCHAR&lt;BR /&gt;&lt;BR /&gt;  stty raw&lt;BR /&gt;  eval $1='"$(dd bs=1 count=1 2&amp;gt;/dev/null)"'&lt;BR /&gt;  stty cooked&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Just call this when you need one character.</description>
    <pubDate>Wed, 07 Apr 2004 09:04:39 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2004-04-07T09:04:39Z</dc:date>
    <item>
      <title>scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242400#M891160</link>
      <description>i am writing a shell script and i want to read a character from the standart input and put it in a  varaible without the need of Ã«nter" or newline.&lt;BR /&gt;&lt;BR /&gt;if some one knows how to do it it will be great&lt;BR /&gt;&lt;BR /&gt;thanx.</description>
      <pubDate>Wed, 07 Apr 2004 08:35:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242400#M891160</guid>
      <dc:creator>Maxim Rozin</dc:creator>
      <dc:date>2004-04-07T08:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242401#M891161</link>
      <description>Can't be done.  Sorry.&lt;BR /&gt; &lt;BR /&gt;There are no shell tools for this.  I once wrote a little C program which did this and returned the ascii value of the character pressed but can't find it :(&lt;BR /&gt; &lt;BR /&gt;You can do it in C and set the terminal to raw mode and a few other bits and bobs.  If you want to do it the simple way, a small C program that uses "curses".  Curses has a function to achieve this for you.</description>
      <pubDate>Wed, 07 Apr 2004 08:47:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242401#M891161</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-04-07T08:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242402#M891162</link>
      <description>My preferred way to do this is a small C program because it guarantees that you will reset the terminal and will automatically fold upper to lower case (or vice-versa), if desired:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;CH=$(onechar -L)&lt;BR /&gt;STAT=${?}&lt;BR /&gt;case ${STAT} in&lt;BR /&gt;0) echo "You pressed ${CH}"&lt;BR /&gt;;;&lt;BR /&gt;255) echo "This is an error" &amp;gt;&amp;amp;2&lt;BR /&gt;;;&lt;BR /&gt;*) echo "The ASCII value pressed is \c"&lt;BR /&gt;echo "${STAT} (dec)"&lt;BR /&gt;;;&lt;BR /&gt;esac&lt;BR /&gt;&lt;BR /&gt;The idea is if 0 is returned, a printable character is output on stdout, a return of 255 indicates an error, any other returns indicates that a non-pritable ASCII character was received and the return value is the decimal equivalent and no character is output to stdout.&lt;BR /&gt;&lt;BR /&gt;If you need to recognize function keys or arrow-keys then you really need to use curses. Man curses for details.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This is onechar.c. Compile it like this:&lt;BR /&gt;cc onechar.c -o onechar&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Apr 2004 08:53:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242402#M891162</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-07T08:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242403#M891163</link>
      <description>&lt;BR /&gt;Here is a pure shell method but I consider it much less robust:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;echo "Enter character: \c"&lt;BR /&gt;stty raw&lt;BR /&gt;CH=$(dd if=/dev/tty bs=1 count=1 2&amp;gt;/dev/null)&lt;BR /&gt;stty -raw&lt;BR /&gt;echo "You entered ${CH}"&lt;BR /&gt;&lt;BR /&gt;The reason this is not so nice is that no mechanism is present to easily recognize non-ASCII characters. Whatever you do, make sure that the second stty gets called because terminal settings affect not just the process but ALL processes for which this terminal is the controlling terminal.&lt;BR /&gt;&lt;BR /&gt;The C program makes certain that this is done and easily tells you when a control character was entered.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Apr 2004 08:58:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242403#M891163</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-07T08:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242404#M891164</link>
      <description>thanx,&lt;BR /&gt;&lt;BR /&gt;but i cannot see the c program</description>
      <pubDate>Wed, 07 Apr 2004 08:58:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242404#M891164</guid>
      <dc:creator>Maxim Rozin</dc:creator>
      <dc:date>2004-04-07T08:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242405#M891165</link>
      <description>No problem. Here is a function that will work in POSIX or Korn shell:&lt;BR /&gt; &lt;BR /&gt;###########################################&lt;BR /&gt;function GetChar1&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;# Read 1 character and return as first argument&lt;BR /&gt;# example: GetChar1 MYCHAR&lt;BR /&gt;&lt;BR /&gt;  stty raw&lt;BR /&gt;  eval $1='"$(dd bs=1 count=1 2&amp;gt;/dev/null)"'&lt;BR /&gt;  stty cooked&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Just call this when you need one character.</description>
      <pubDate>Wed, 07 Apr 2004 09:04:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242405#M891165</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-04-07T09:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242406#M891166</link>
      <description>The C source, onechar.c,  is an attachment to my first posting.</description>
      <pubDate>Wed, 07 Apr 2004 09:09:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242406#M891166</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-04-07T09:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242407#M891167</link>
      <description>Well guys, I'm impressed.&lt;BR /&gt; &lt;BR /&gt;I just sat here and re-coded a raw mode getc and found A.Clay got in there well before hand and then Bill comes along with a cute Korn version.&lt;BR /&gt; &lt;BR /&gt;I'll get my coat :)</description>
      <pubDate>Wed, 07 Apr 2004 09:20:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242407#M891167</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-04-07T09:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: scripts problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242408#M891168</link>
      <description>To amplify a bit on the shell method, I assume that a monkey is typing so every character is possible. That makes shell comparisons a bit tricky so I convert the character to hex and compare for things like control characters something like this:&lt;BR /&gt; &lt;BR /&gt;  GetChar1 "MYCHAR"&lt;BR /&gt;&lt;BR /&gt;# Search for an acceptable response. Since just CR&lt;BR /&gt;#   (or other control chars) might be entered, convert&lt;BR /&gt;#   MYCHAR to hex and test accordingly.&lt;BR /&gt;&lt;BR /&gt;  HEX=$(echo "$MYCHAR" \&lt;BR /&gt;       | xd \&lt;BR /&gt;       | head -1 \&lt;BR /&gt;       | awk '{print $2}' \&lt;BR /&gt;       | cut -c 1-2)&lt;BR /&gt;&lt;BR /&gt;# CR or CTRL-D?  Bail out.&lt;BR /&gt;&lt;BR /&gt;if [ "$HEX" = "0d" -o "$HEX" = "04" ]&lt;BR /&gt;then&lt;BR /&gt;   echo "\n\n"&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;...and so on...</description>
      <pubDate>Wed, 07 Apr 2004 10:31:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripts-problem/m-p/3242408#M891168</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-04-07T10:31:02Z</dc:date>
    </item>
  </channel>
</rss>

