简体   繁体   English

在 Linux 的 Db2 CLP 中使用箭头键?

[英]Using arrow keys within Db2 CLP in Linux?

When I run the Db2 CLP (command line processor) on Linux and remain in the CLP, the arrow keys do not work as expected.当我在 Linux 上运行 Db2 CLP(命令行处理器)并保留在 CLP 中时,箭头键无法按预期工作。

For example: Rather than showing me the previous command I executed, pressing the up arrow yields: ^[[A and pressing the left arrow yields: ^[[D.例如:与其显示我执行的上一个命令,不如按向上箭头产生:^[[A 并按向左箭头产生:^[[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.我在我的本地 cygwin 终端中使用 bash,该终端在 Windows 10 上运行,在我的远程 CentOS Linux 盒子上运行 bash,并使用 SSH 进行连接。 Are there configuration options to address this?是否有配置选项来解决这个问题?

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. Db2 交互式 CLP(默认提示 db2 =>)无法正确处理 linux shell 的向上和向下箭头键,我不知道修复方法。 Even when the default shell for the user is bash, the interactive Db2 clp does not recognize the up and down arrow keys.即使用户默认的 shell 为 bash,交互式 Db2 clp 也无法识别向上和向下箭头键。

Db2 Interactive CLP correctly handles up and down arrow keys on MS-Windows natively. Db2 Interactive CLP 正确处理 MS-Windows 上的向上和向下箭头键。

One workaround is to use the History command and the R (runcmd) together inside the Db2 interactive CLP.一种解决方法是在 Db2 交互式 CLP 中同时使用历史命令和 R (runcmd)。 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.例如,如果您在交互式 CLP 中运行 History 命令,它将显示在此 session(但不是之前的会话)期间到目前为止运行的命令,并且每个命令都有一个编号。 You can use R n (where n is the number) to repeat the command.您可以使用 R n(其中 n 是数字)重复该命令。 You can use edit n to edit the command before submitting.您可以在提交前使用 edit n 编辑命令。 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.您可以通过变量控制历史条目的数量、用于编辑历史的编辑器等,详细信息请参阅 Db2 知识中心。

Another workaround is to use the java based clpplus command, which on linux will correctly react to the up and down arrow keys.另一种解决方法是使用基于 java 的clpplus命令,该命令在 linux 上将正确响应向上和向下箭头键。

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.第三种解决方法是在 MS-Windows 本地使用交互式 CLP(但是需要在 MS-Windows 上安装合适的 Db2 客户端),并从那里管理远程数据库。 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.但是对于不需要等待 ssh session 打开、登录、运行这些东西并退出的快速东西来说很方便。

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.许多开发人员和 DBA 使用的第四个选项是永远不要使用 CLP 的交互模式,而只使用命令模式,然后使用 linux shell 的功能进行调用和编辑等。向上和向下箭头如果您为您最喜欢的编辑器适当地配置 shell 选项,键的行为就会正确。

The arrow keys don't work as expected in Db2 CLP.箭头键在 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.使用edit命令运行您喜欢的编辑器来编辑您最后调用的语句(或历史记录中的任何内容),并能够在之后运行此编辑后的命令。
Use history command to get the number of your statement previously invoked.使用history命令获取之前调用的语句的编号。 You may use this number in the runcmd or e[dit] commands, for example.例如,您可以在runcmde[dit]命令中使用此编号。
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 == ; ) or db2 -td@ (statement terminator == @ or use your preferred one).要能够在交互模式下使用多行命令,最好使用db2 -t (语句终止符 == ; )或db2 -td@ (语句终止符 == @或使用您喜欢的那个)进入交互模式).

As another workaround on Linux: you can install package rlwrap and then use作为 Linux 的另一种解决方法:您可以安装 package rlwrap 然后使用

rlwrap db2 -t

which will allow you to recall the command history using up and down arrow keys.这将允许您使用向上和向下箭头键调用命令历史记录。 Db2's native history-recall command, using r and e commands, continues to work as well.使用re命令的 Db2 本机 history-recall 命令也可以继续工作。

rlwrap v 0.43 July 19 2016 rlwrap v 0.43 2016 年 7 月 19 日

* WHAT IT IS: * 这是什么:

rlwrap is a 'readline wrapper', a small utility that uses the GNU readline library to allow the editing of keyboard input for any command. rlwrap 是一个“readline wrapper”,一个使用 GNU readline 库允许编辑任何命令的键盘输入的小实用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM