When I run the Db2 CLP (command line processor) on Linux and remain in the CLP, the arrow keys do not work as expected.
For example: Rather than showing me the previous command I executed, pressing the up arrow yields: ^[[A and pressing the left arrow yields: ^[[D.
See below:
[db2inst1@willow ~]$ db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 11.5.0.0
You can issue database manager commands and SQL statements from the command
prompt. For example:
db2 => connect to sample
db2 => bind sample.bnd
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => ^[[A
I am using bash in my local cygwin terminal which runs on Windows 10, bash on my remote CentOS Linux box, and using SSH to connect. Are there configuration options to address this?
3
Answers
This gives workarounds, not a fix.
The Db2 interactive CLP (with the default prompt db2 =>) does not properly handle the up and down arrow keys for linux shells, and I do not know a fix. Even when the default shell for the user is bash, the interactive Db2 clp does not recognize the up and down arrow keys.
Db2 Interactive CLP correctly handles up and down arrow keys on MS-Windows natively.
One workaround is to use the History command and the R (runcmd) together inside the Db2 interactive CLP. For example if you run the History command inside the interactive CLP it will show the commands run so far during this session (but not previous sessions), and each has a number. You can use R n (where n is the number) to repeat the command. You can use edit n to edit the command before submitting. You can control via variables the number of entries in the history, the editor used to edit the history etc, refer to the Db2 Knowledge Centre for details.
Another workaround is to use the java based
clpplus
command, which on linux will correctly react to the up and down arrow keys.A third workaround is to use the interactive CLP from MS-Windows natively (requires a suitable Db2-client to be installed on MS-Windows however), and administer the remote database from there. Awkward. But handy for quick stuff where you don’t need to wait for an ssh session to open , login, run the stuff and exit.
A fourth option , used by many developers and DBAs is to never use the interactive mode of the CLP and use only command-mode, and then use the features of your linux shell for the purposes of recall and editing etc. The up and down arrow keys behave correctly if you configure your shell options appropriately for your favourite editor.
The arrow keys don’t work as expected in Db2 CLP.
Use edit command to run your preferred editor to edit your last invoked statement (or whatever from history) with an ability to run this edited command afterwards.
Use history command to get the number of your statement previously invoked. You may use this number in the runcmd or
e[dit]
commands, for example.To have an ability to work with multi-line commands in the interactive mode, it’s better to enter the interactive mode with
db2 -t
(statement terminator ==;
) ordb2 -td@
(statement terminator ==@
or use your preferred one).As another workaround on Linux: you can install package rlwrap and then use
which will allow you to recall the command history using up and down arrow keys. Db2’s native history-recall command, using
r
ande
commands, continues to work as well.rlwrap v 0.43 July 19 2016