gpt4 book ai didi

bash - Bash 多行命令中的向上/向下导航

转载 作者:行者123 更新时间:2023-11-29 09:11:55 28 4
gpt4 key购买 nike

有没有办法将命令作为多行命令保存到 bash 历史记录中,然后上下导航以进行一些编辑并再次运行?

$ shopt -s cmdhist
$ shopt -s lithist
$ echo "1"\
&& echo "2"\
&& echo "3"

现在,如果我点击向上箭头,我想看到

$ echo "1"\
&& echo "2"\
&& echo "3"

..再次,但 bash 给了我 echo "1"&& echo "2"&& echo "3"。 IE。尽管设置了 cmdhistlithist 标志,但它删除了新行。

如果向上箭头起作用并显示多行命令,我如何在其中上下导航?

最佳答案

Bash 中,\Bash 中忽略换行符之前是不可能的。来自 man bash:

A non-quoted backslash () is the escape character. It preserves the literal value of the next character that follows, with the exception of . If a \ pair appears, and the backslash is not itself quoted, the \ is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).

如果您愿意更改您的 shell 或想试验一下 zsh,它可以满足您的需求:

$ echo a \
echo b

C-p 并查看是否保留了换行符:

$ echo a \
echo b

关于bash - Bash 多行命令中的向上/向下导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31989618/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com