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

Mar*_*ark 5 linux db2 ssh bash keymapping

当我在 Linux 上运行 Db2 CLP(命令行处理器)并保留在 CLP 中时,箭头键无法按预期工作。

例如:按向上箭头会产生:^[[A,按向左箭头会产生:^[[D,而不是显示我执行的上一个命令。

见下文:

[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
Run Code Online (Sandbox Code Playgroud)

我在 Windows 10 上运行的本地 cygwin 终端中使用 bash,在远程 CentOS Linux 机器上使用 bash,并使用 SSH 进行连接。是否有配置选项可以解决这个问题?

mao*_*mao 2

这提供了解决方法,而不是修复。

Db2 交互式 CLP(默认提示符 db2 =>)无法正确处理 Linux shell 的向上和向下箭头键,而且我不知道修复方法。即使用户的默认 shell 是 bash,交互式 Db2 clp 也无法识别向上和向下箭头键。

Db2 Interactive CLP 本身可以正确处理 MS-Windows 上的向上和向下箭头键。

一种解决方法是在 Db2 交互式 CLP 中同时使用 History 命令和 R (runcmd)。例如,如果您在交互式 CLP 中运行“历史记录”命令,它将显示此会话期间(但不包括之前的会话)迄今为止运行的命令,并且每个命令都有一个编号。您可以使用 R n(其中 n 是数字)重复该命令。您可以在提交之前使用 edit n 编辑命令。您可以通过变量控制历史记录中的条目数、用于编辑历史记录的编辑器等,有关详细信息,请参阅 Db2 知识中心。

另一种解决方法是使用基于 java 的clpplus命令,该命令在 Linux 上将正确响应向上和向下箭头键。

第三种解决方法是本地使用 MS-Windows 中的交互式 CLP(但是需要在 MS-Windows 上安装合适的 Db2 客户端),并从那里管理远程数据库。尴尬的。但对于快速操作来说很方便,您不需要等待 ssh 会话打开、登录、运行内容并退出。

许多开发人员和 DBA 使用的第四个选项是永远不要使用 CLP 的交互模式,而仅使用命令模式,然后使用 linux shell 的功能来实现调用和编辑等目的。向上和向下箭头如果您为您喜欢的编辑器正确配置了 shell 选项,则按键的行为会正确。