cronenvironment-variableseditor

How do I permanently change $EDITOR to a specific text editor?


Issue

I am trying to work with crontabs, and cron never asked me which text editor I would like to use, and I don't like the choice it has taken.

Initial Troubleshooting

(Where the post gets its title from)

To my surprise, when I run echo $EDITOR, I get a blank output.

I can change it with export EDITOR=/usr/bin/nano, so it is set for the session, but as soon as I log-out it doesn't retain the value.

I want it to be the system-wide default, so I can use it with all users, but adding EDITOR=/usr/bin/nano, which is the location of nano, to my /etc/environment, killing the terminal and relaunching still returns a blank line when running echo $EDITOR.

As @CHAOTING says down below, adding export EDITOR=/usr/bin/nanoto the .zshrc file in my home folder helped. Now, it is the default environmental variable for my user and for root, but running commands with sudo, I still get the wrong editor. Is there anyway the variable can be made trully global?

Best Solution to the Root Problem

(A workaround to the title question)

It's really a workflow problem. Now, I just use the editor of choice to open the crontab from its full path.

micro /var/spool/cron/foo


Solution

  • After running into this issue multiple times, the best workflow to circumvent the actual problem is just using my text editor of choice and opening the crontabs' full path:

    micro /var/spool/cron/foo