警告:未启用行编辑

Alf*_*red 27 bash

我发现这个有用的命令bind -x '"\C-r"':reset可以清除终端,但我想制作一个简单的 bash 脚本:

#!/bin/bash
bind -x '"\C-r"':reset
Run Code Online (Sandbox Code Playgroud)

输出:

alfred@alfred-laptop:~/bash$ ./bind 
./bind: line 2: bind: warning: line editing not enabled
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下:

  1. 我怎样才能解决这个问题?
  2. 什么warning: line editing not enabled意思?

Den*_*son 11

您需要获取该脚本的来源。做. ./bindorsource ./bind使该键绑定在当前会话中处于活动状态。

正常运行它,它没有终端,所以它会给你那个错误信息。此外,如果它要工作,它只会在脚本的持续时间内处于活动状态。

如果您希望该键绑定是持久的,请将该命令添加到您的~/.bashrc.

  • @alfredwesterveld:如果您不希望每次启动 shell 时都加载绑定,但您希望能够随时激活它而不必使用 `source` 或点 (`.`),请向您的`~/.bashrc`: `rbind() { bind -x '"\Cr"':reset; }` 然后你可以自己输入 `rbind` 作为命令,绑定将被激活。 (2认同)

小智 9

我有一个类似的消息,但我的来自一个在交互式(登录)shell 之外运行的脚本;它是一个通过 CGI 脚本运行的 shell 脚本。我的信息是:

/home/richard/.bash_profile: line 4: bind: warning: line editing not enabled
Run Code Online (Sandbox Code Playgroud)

虽然它实际上不在第 4 行,但bind该文件中唯一的内容是:

bind 'set completion-ignore-case on'
Run Code Online (Sandbox Code Playgroud)

这当然只有在启用行编辑时才有意义,即如果它是交互式 shell。


rus*_*tyx 8

只是想改进已接受的答案。

line editing not enabled在非交互式 shell 中运行时,您会得到“ ”,因为bind需要 TTY。

将您的命令包装bind在检查中,如下所示:

if [ -t 1 ]
then
    # standard output is a TTY
    bind -x '"\C-r"':reset
fi
Run Code Online (Sandbox Code Playgroud)