65.9K
CodeProject 正在变化。 阅读更多。
Home

在 Raspberry Pi 的 bash shell 中更改默认 crontab 编辑器

2023年5月7日

CPOL
viewsIcon

8352

本文档展示了一种在 Raspberry Pi 的 bash shell 中更改默认 crontab 编辑器的方法。

默认情况下,Raspberry Pi 上 crontab 的编辑器由 VISUAL 或 EDITOR 环境变量指定。如果未定义这两个环境变量,则使用 /usr/bin/editor 中的默认编辑器。在 Raspberry Pi 上,即使您已经将 VISUAL 和 EDITOR 的值设置为预期的编辑器,例如 vi,仍然可能会使用诸如 nano 之类的默认编辑器。

要解决此问题,首先检查当前的编辑器

$> ls -l /usr/bin/editor

lrwxrwxrwx 1 root root 24 May  7  2015 /usr/bin/editor -> /etc/alternatives/editor 

由于当前编辑器是 /etc/alternatives/editor 的软链接,我们将进一步检查它

$> ls -lt /etc/alternatives/editor

lrwxrwxrwx 1 root root 9 Jan  4 11:51 /etc/alternatives/editor -> /bin/nano 

显然,正在使用 nano 编辑器。现在我们将使用以下命令将编辑器更新为 Vi

$> sudo update-alternatives --config editor 

有三个可供选择的编辑器

Selection    Path               Priority   Status
------------------------------------------------------------
* 0            /bin/nano           40        auto mode
1            /bin/ed            -100       manual mode
2            /bin/nano           40        manual mode
3            /usr/bin/vim.tiny   10        manual mode

按 ENTER 键以保留当前选择(用 * 标记),或键入选择编号,例如 3,以选择 vim.tiny 作为默认编辑器。

您可以使用以下命令验证更改是否已生效

$> ls -lt /etc/alternatives/editor 

结果应为

lrwxrwxrwx 1 root root 17 Jan  4 11:54 /etc/alternatives/editor -> /usr/bin/vim.tiny

这样,使用 sudo 的 crontab 的默认编辑器将是 vi

© . All rights reserved.