Linux 在 bash 中打开默认文本编辑器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10725238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening default text editor in bash?
提问by Stoof
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?
我正在编写一个 shell 脚本并遇到了一个问题。有没有办法使用用户指定的文本编辑器打开文件?
采纳答案by Ignacio Vazquez-Abrams
The user's chosen editor should be in $EDITOR
, but you must still choose a sane default.
用户选择的编辑器应该在 中$EDITOR
,但您仍然必须选择一个合理的默认值。
"${EDITOR:-vi}" file.txt
回答by Nicholas Wilson
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).
Ignacio 是对的(尽管可以说,回退应该是ed
,POSIX 要求存在,尽管它基本上只对老手有用)。
If you're thinking about graphical editors, xdg-open file.txt
is what you're after.
如果您正在考虑图形编辑器,xdg-open file.txt
这就是您所追求的。
回答by JimmyLandStudios
note: xdg-open file.xml
will open in a Web-Browser, most likely.
So, try;
注意:xdg-open file.xml
很可能会在网络浏览器中打开。所以,试试;
# select your default sensible-editor from all installed editors, or not.
select-editor
# Open Default Text Editor
sensible-editor file.xml