Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening default text editor in bash?

Tags:

linux

bash

shell

I was writing a shell script and ran into a problem. Is there a way to open a file using the user's specified text editor?

like image 527
Stoof Avatar asked May 23 '12 17:05

Stoof


People also ask

What is default text editor for bash shell?

On Windows, if you use Git Bash the default editor will be Vim. Vim is another text editor, like nano or notepad.

How do I open bash editor?

If you use shell in default mode ( emacs if you don't know :P), you can press ctrl-x ctrl-e and enter text editor to edit all the commands together by using features of your editor like copy, paste visually select etc.

How do I find the default text editor in Linux?

The Vi application is the default text editor on most Linux systems, so it's the primary interface you will use when you need to edit a configuration file.


2 Answers

The user's chosen editor should be in $EDITOR, but you must still choose a sane default.

"${EDITOR:-vi}" file.txt 
like image 57
Ignacio Vazquez-Abrams Avatar answered Sep 30 '22 12:09

Ignacio Vazquez-Abrams


Ignacio's right (though arguably, the fallback should be ed, which POSIX requires to be present, although it's essentially only useful to old-timers).

If you're thinking about graphical editors, xdg-open file.txt is what you're after.

like image 40
Nicholas Wilson Avatar answered Sep 30 '22 12:09

Nicholas Wilson