Intercepting "Enter" key
Hi:
How could I intercept "enter" key using a case statement?
Thank you.
Re: Intercepting "Enter" key
apogeusistemas [at] gmail.com wrote:
> Hi:
> How could I intercept "enter" key using a case statement?
>
> Thank you.
That could mean just about anything. Prtovide some more details
including sample input and expected output.
Ed.
Re: Intercepting "Enter" key
On 2008-01-10, apogeusistemas [at] gmail.com wrote:
>
> How could I intercept "enter" key using a case statement?
LF=$( printf "\n" )
CR=$( printf "\r" )
case $KEY in
"$LF") echo Line feed entered ;;
"$CR") echo Carriage return entered ;;
esac
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Re: Intercepting "Enter" key
On Jan 10, 7:36 am, apogeusiste... [at] gmail.com wrote:
> Hi:
> How could I intercept "enter" key using a case statement?
What do you mean? Can you provide a code example of what you currently
have?
-Ed
--
(You can't go wrong with psycho-rats.)(http://mi.eng.cam.ac.uk/~er258)
/d{def}def/f{/Times s selectfont}d/s{11}d/r{roll}d f 2/m{moveto}d -1
r
230 350 m 0 1 179{1 index show 88 rotate 4 mul 0 rmoveto}for/s 12 d f
pop 235 420 translate 0 0 moveto 1 2 scale show showpage
Re: Intercepting "Enter" key
On Thu, 10 Jan 2008 13:01:53 -0500, Chris F.A. Johnson wrote:
> On 2008-01-10, apogeusistemas [at] gmail.com wrote:
>>
>> How could I intercept "enter" key using a case statement?
>
>
> LF=$( printf "\n" )
That won't work. Command substitution removes all the trailing LFs.
LF='
'
or:
eval "$(printf 'LF="\n"')"
or:
LF=$(printf '\n.'); LF=${LF%.}
....
--
Stephane
Re: Intercepting "Enter" key
In article
<dbdbb108-879f-43fc-8683-03bdb21736e9 [at] i72g2000hsd.googlegroups.com>,
apogeusistemas [at] gmail.com wrote:
> Hi:
> How could I intercept "enter" key using a case statement?
>
> Thank you.
Do you mean you want to detect when the user has typed an empty response
to a question?
read response
if [ -z "$response" ]
then echo Please type something
else echo "You typed '$response'"
fi
--
Barry Margolin, barmar [at] alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Re: Intercepting "Enter" key
apogeusiste... [at] gmail.com wrote:
> How could I intercept "enter" key using a case statement?
A general method from the Kornshell FAQ at
http://kornshell.com/doc/faq.html :
Q4. How can a write a ksh script that responds directly to each
character so that you user just has to enter y, not y<return>?
A4. There are two ways to do this. The easiest is to use:
read -n1 x
Alternatively, you could do:
function keytrap
{
.sh.edchar=${sh.edchar}$'\n'
}
trap keytrap KEYBD
and then:
read x
=Brian