Sponsored Content
Full Discussion: how to test for backspace
Top Forums UNIX for Dummies Questions & Answers how to test for backspace Post 302398182 by karthigayan on Wednesday 24th of February 2010 02:23:30 AM
Old 02-24-2010
MySQL Use ASCII

There is no straight forward way to compare the backspace.But there are some other way like ,converting the character to ascii value and compare that with particular ascii value of the backspace.

ascii value of the backspace is 8.But when I print the ascii value of backspace in my system it prints 127.it is the ascii value of DEL.So I used 127 in my code.You just change that value to 8 if needed.

Code:
read -n 1 x
x=`echo $x | tr -d "\n" | od -An -t dC`
if [ $x  -eq 127 ]; then # Change the 127 to 8 if it need
echo "backspace detected"
else
echo "some other character"
fi

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Backspace erasing the prompt

My AIX has Korn Shell. I had set the prompt by providing assigning to PS1. If on the prompt I use backspace it erase the whatever appeared due to PS1. Can someone tell me how to forbid this erasing of prompt string, with this behaviour? Thanks in advance. (4 Replies)
Discussion started by: videsh77
4 Replies

2. HP-UX

Backspace stty inconsistency

I have this in my .profile: stty erase `tput kbs` which sets erase to ^H for a vt and ^? for an xterm. This has been fine up until now on all systems whether I login using a vt terminal emulator or an xterm. On this new system though, if I log in directly using an xterm, backspace doesn't... (1 Reply)
Discussion started by: Runrig
1 Replies

3. UNIX for Dummies Questions & Answers

Control + h and Backspace

Hello, I am a UNIX newbie. With that out of that way.. In order to delete a mistyped character, I need to press control+h to move the cursor to the left, and then overwrite it. If I try hitting the backspace key, it just brings me to a new prompt. Is there a way to change it so that my... (1 Reply)
Discussion started by: martinp973
1 Replies

4. Shell Programming and Scripting

Backspace Key From Within Script

I have a script that asks a user for a few question. I would like the users to be able to use the backspace key if they make a mistake. Right now when they try they get ^? instead of it backing up. As you can see here from a stty -a the backspace is set... speed 38400 baud; rows = 42;... (2 Replies)
Discussion started by: LRoberts
2 Replies

5. Solaris

Using backspace in solaris - help

Hi In solaris if i have to delete something from shell i need to use ctrl+H, coz if i use backspace it shows ^?. Can any one please tell me how to set backspace key so that i can delete any character directly instead of using Ctrl+h. Second Q is like in linux for going to recent command, i... (10 Replies)
Discussion started by: sarbjit
10 Replies

6. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

7. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

8. UNIX Desktop Questions & Answers

backspace in vi search

Hi gurus, i use vi editor. when I want search something I Type / (or ? if i want search backward), that is OK. But when i make mistake in searching string how can i delete character ? I tried bacskpase but did not work (gives just strange characters). Also tried shift+bacskspace but this only... (3 Replies)
Discussion started by: wakatana
3 Replies

9. Shell Programming and Scripting

echo backspace

Hello Forum: I am trying to find a meaning to this echo escape character: echo -e "\b" Can someone tell me or give me examples of the effect that this has when used. I know that \b is the backspace, but I cannot visualise it use like any other escape such as: echo -e "\n" Thanks. --Willie (10 Replies)
Discussion started by: willie
10 Replies

10. Solaris

[SOLVED] Backspace not working!!!!!

Hi friends, Hope u r doing well. It is a very strange problem that I've never faced when I used linux or freebsd. When a type a command in Solaris 10, and if I make a mistake, the backspace doesn't work, when I press the backspace key three times forexample, this is what I get, ^H ^H ^H. The same... (2 Replies)
Discussion started by: gabam
2 Replies
SHOWKEY(1)						      General Commands Manual							SHOWKEY(1)

NAME
showkey - examine the codes sent by the keyboard SYNOPSIS
showkey [-h|--help] [-a|--ascii] [-s|--scancodes] [-k|--keycodes] [-V|--version] DESCRIPTION
showkey prints to standard output either the scan codes or the keycode or the `ascii' code of each key pressed. In the first two modes the program runs until 10 seconds have elapsed since the last key press or release event, or until it receives a suitable signal, like SIGTERM, from another process. In `ascii' mode the program terminates when the user types ^D. When in scancode dump mode, showkey prints in hexadecimal format each byte received from the keyboard to the standard output. A new line is printed when an interval of about 0.1 seconds occurs between the bytes received, or when the internal receive buffer fills up. This can be used to determine roughly, what byte sequences the keyboard sends at once on a given key press. The scan code dumping mode is primarily intended for debugging the keyboard driver or other low level interfaces. As such it shouldn't be of much interest to the regular end-user. However, some modern keyboards have keys or buttons that produce scancodes to which the kernel does not associate a keycode, and, after finding out what these are, the user can assign keycodes with setkeycodes(8). When in the default keycode dump mode, showkey prints to the standard output the keycode number or each key pressed or released. The kind of the event, press or release, is also reported. Keycodes are numbers assigned by the kernel to each individual physical key. Every key has always only one associated keycode number, whether the keyboard sends single or multiple scan codes when pressing it. Using showkey in this mode, you can find out what numbers to use in your personalized keymap files. When in `ascii' dump mode, showkey prints to the standard output the decimal, octal, and hexadecimal value(s) of the key pressed, according to he present keymap. OPTIONS
-h --help showkey prints to the standard error output its version number, a compile option and a short usage message, then exits. -s --scancodes Starts showkey in scan code dump mode. -k --keycodes Starts showkey in keycode dump mode. This is the default, when no command line options are present. -a --ascii Starts showkey in `ascii' dump mode. -V --version showkey prints version number and exits. 2.6 KERNELS In 2.6 kernels key codes lie in the range 1-255, instead of 1-127. Key codes larger than 127 are returned as three bytes of which the low order 7 bits are: zero, bits 13-7, and bits 6-0 of the key code. The high order bits are: 0/1 for make/break, 1, 1. In 2.6 kernels raw mode, or scancode mode, is not very raw at all. Scan codes are first translated to key codes, and when scancodes are desired, the key codes are translated back. Various transformations are involved, and there is no guarantee at all that the final result corresponds to what the keyboard hardware did send. So, if you want to know the scan codes sent by various keys it is better to boot a 2.4 kernel. Since 2.6.9 there also is the boot option atkbd.softraw=0 that tells the 2.6 kernel to return the actual scan codes. SEE ALSO
loadkeys(1), dumpkeys(1), keymaps(5), setkeycodes(8) 1 Feb 1998 SHOWKEY(1)
All times are GMT -4. The time now is 05:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy