4

I want to change the default editor on my CentOS 7 box for crontab as it currently launches vi and I prefer nano.

I have read a lot of pages online which suggest running export EDITOR='nano' or some similar - some places seem to suggest double quotes ("), others no quotes at all.

In any case, none of these approaches are working, I run the export command, then sudo crontab -e and still it launches vi! What am I doing wrong?

I realise that if I want the change to persist between sessions, I need to place this export command into my bashrc or bash_profile file, or create a .sh file in /etc/profile.d/, but I just want to get it working in isolation first before I make it persistent - can anyone help?

3N1GM4
  • 3,372
  • 3
  • 19
  • 40

2 Answers2

9

You can use -E with sudo

-E' The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.

export EDITOR=nano
sudo -E crontab -e
Dmitry T.
  • 101
  • 2
  • 1
    Great, thanks for that - combined with the answer from Carlos I now understand why this was not working as I expected. – 3N1GM4 Jan 15 '16 at 08:17
1

The export works like you see, but if you use sudo, you're running crontab as other user, in this case as root, then you need set EDITOR as root too.

(I post as answer because I can't comment)

  • Of course, what a moron I am! Thanks for that, now that I'm also running crontab as the current user, this is working fine. – 3N1GM4 Jan 15 '16 at 08:13