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?
On Windows, if you use Git Bash the default editor will be Vim. Vim is another text editor, like nano or notepad.
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.
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.
The user's chosen editor should be in $EDITOR
, but you must still choose a sane default.
"${EDITOR:-vi}" file.txt
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With