小编PyG*_*Guy的帖子

如何将长 shell 命令分成由“\”分隔的多行?

我需要运行一系列长行 bash 命令。每次尝试时,我都需要更改一些参数并重新运行命令。

我知道最好的情况是用 换行"\",但这只能附加参数。

有没有办法在长 bash 命令中间注入a ?类似或在大多数编辑环境中。"\" + "\n"Shift+EnterCtrl+Enter

例如,我从历史记录中调出了下面的命令,我想对其进行编辑:

$ execute_command -a /path/to/file -b another_option -c third_option
Run Code Online (Sandbox Code Playgroud)

到:

$ execute_command \
  -a /path/to/file \
  -b another_option \
  -c third_option
Run Code Online (Sandbox Code Playgroud)

回答

根据@benjamin-w的建议,可以使用Ctrl-X-E组合键。这将打开默认编辑器,您可以将现有命令分成由 分隔的多行"\",并在退出时将其放在命令行上。

bash terminal zsh

6
推荐指数
1
解决办法
4088
查看次数

标签 统计

bash ×1

terminal ×1

zsh ×1