Cron expressions are a useful tool for automating tasks using cron expressions. In this tutorial, we’ll learn how to change the default editor for maintaining our crontab.
2. Environment Variables
There are two environment variables we can use to change the editor opened by crontab -e.
Note that the examples below will change the editor for the current terminal session only. We can make this change persistent by using environment variables.
First, we can use EDITOR. Let’s change our editor to nano:
$ export EDITOR=/usr/bin/nano
Depending on our configuration, this might not actually work because there is another variable that takes precedence.
The VISUAL environment variable takes precedence to EDITOR. Let’s see if we can override the EDITOR variable we set before by setting VISUAL to joe:
$ export VISUAL=/usr/bin/joe
Now, every time we issue crontab -e, it should open our crontab in joe instead of nano.
Some Linux distributions (like Ubuntu) provide us with a command select-editor. Running select-editor gives us a list of editors to choose from:
$ select-editor Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/vim.basic 3. /usr/bin/vim.tiny 4. /bin/ed Choose 1-4 :
The selection is stored in our home directory in ~/.selected-editor and therefore persistent across terminal sessions.
Note that the environment variables EDITOR and VISUAL take precedence over select-editor, so we’ve got to make sure these variables aren’t set.
In this article, we’ve learned how to make crontab -e use our favorite editor. The recommended way is by setting the VISUAL environment variable.
Depending on our Linux distribution, we might also use the select-editor utility.