Opening default text editor in Bash?

bash, linux, shell

Solution

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

"${EDITOR:-vi}" file.txt

Problem

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?

Original source