Opening default text editor in bash?

2019-04-03 21:11发布

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?

标签: linux bash shell
3条回答
手持菜刀,她持情操
2楼-- · 2019-04-03 21:27

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-03 21:32

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

"${EDITOR:-vi}" file.txt
查看更多
混吃等死
4楼-- · 2019-04-03 21:36

note: xdg-open file.xml will open in a Web-Browser, most likely. So, try;

    # select your default sensible-editor from all installed editors, or not.
    select-editor
    # Open Default Text Editor
    sensible-editor file.xml
查看更多
登录 后发表回答