Friday, January 2, 2015

Linux -- SQLPLUS backspace (^H) problem & fix - vt100,vt220

When you working with sqlplus in Linux , you will see that you cant use backspace to erase characters..
"sqlplus" does not handle the backspace character as it should , and displays ^H characters instead..
So, If you want to delete characters in sqlplus , you need to use shift+backspace ...

[appvis@erpdemo scripts]$ sqlplus apps/apps
SQL*Plus: Release 10.1.0.5.0 - Production on Fri Jan 2 11:29:23 2015
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select * from v$instance;
^H

To able to use only the backspace button to erase characters in sqlplus,
you basically need to add; stty erase ^H in your .bash_profile

stty gives you to opportunity to change the terminal line settings..
So , when you issue stty erase ^H in your .bash_profile (this file sourced everytime you login or switch user), you make your shell to erase the last character when it sees ^H  typed.

Okay, setting erase char as explained above is a good workaround for you.
Lets dig a little deeper;

env|grep TERM
TERM=vt100
ORACLE_TERM=vt220

So our terminal uses vt100 right ...  vt100 terminal sends '^H' (0x08) when the backspace key is hit..
In vt220 , The X-term emulation is different..

Look what is said; X-term behaviour was that control-H could not be used by applications just like other control-shortcuts by GUI applications ..

VT220

The disadvantage of the X-term behaviour was that control-H could not be used by applications just like other control-shortcuts by GUI applications (e.g. control-F for find, or perhaps control-H for help).
For this reason, the behaviour was changed again, to the following mapping, which is now the default in most Linux distributions:
KeystrokeGlyph on keyboardASCII Character(s)TTY representationExpected application behaviour
Control-HBS (8, 0x08)^H(Passed on to application)
BackspaceDEL (127, 0x7F)^?Erase to the left
DeleteESC (27, 0x1B) + [3~ ("\e[3~")^[[3~Erase to the right

So VT220 handles ^H diffrently...

Lets find the files that has vt220 inside them;
cd $ORACLE_HOME
 grep -R vt220 *

Apache/Apache/php/lib/php/build/shtool:            xterm|xterm*|vt220|vt220*)
Binary file bin/frmbld matches
Binary file forms/admin/terminal/fmrcvt220.res matches
inventory/filemap/forms/admin/terminal/files.map:fmrcvt220.res::{"component","oracle.developer.forms.compiler","10.1.2.0.2"},
inventory/Components21/oracle.developer.forms.compiler/10.1.2.0.2/fastCopyLog.xml:    <FILE STAGE_LOCATION="fmrcvt220.res"> %ORACLE_HOME%/forms/admin/terminal/fmrcvt220.res </FILE>
Binary file lib/libsosdw.so matches
Binary file lib/libsosd.a matches
Binary file lib/libfrmjapi.so.0 matches
Binary file lib/libsosdw.a matches
Binary file lib/libsosd.so.0 matches
Binary file lib/libfrmjapi.so matches
Binary file lib/libsosd.so matches
Binary file lib/libsosdw.so.0 matches

Hmm.. We have some so files which have vt220 inside, but unfortnetaly none of them are used by the sqlplus.. In fact, when I use strace to see the syscalls that sqlplus made, I dont see a syscall or file read that might affect the terminal setting.
So in this case; we need to speak the langage what sqlplus understands..

Okay... Now comes the solution :)

The solution comes from the terminal software ( SSH Secure Shell client in this case) 
Here, I check "Backspace sends Delete" checkbox and this fixes the problem.


Why does "Backspace sends Delete" fix the problem?

When I check "Backspace send Delete",  my SSH Secure Shell client starts to send "^?" not "^H", that 's what fixes the problem..

No comments :

Post a Comment

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.