BASH:像Kornshell一样编辑历史记录

时间:2011-10-25 20:35:28

标签: bash

假设我在BASH或Kornshell中执行以下命令:

$ foo | while read line
> do
>    echo "Line = '$line'"
> done

如果我设置vi,并在Kornshell中进行编辑,我会得到:

foo | while read line
do
     echo "Line = '$line'"
done

如果我设置vi,并在BASH中编辑它,我会得到:

foo | while read line;do;    echo "Line = '$line'";done

有没有办法在BASH中以与Kornshell相同的方式进行命令行编辑?

2 个答案:

答案 0 :(得分:5)

您需要启用lithist(文字历史记录)选项,该选项告诉bash保留换行符:

$ shopt -s lithist

答案 1 :(得分:1)

你需要两件事:

$ shopt -s cmdhist  # This is on by default, so probably unnecessary
$ shopt -s lithist  # This is off by default