Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有一种好方法可以测试我是在登录文本外壳还是在 .bashrc 中启动 GUI 会话?例如,如果在 gnome 和 emacs 中使用命令行,则将我的编辑器设置为 gedit。
DISPLAY如果您登录到 X 会话,您的变量将被设置。
DISPLAY
编辑:所以,这个(未经测试的)代码应该可以工作:
[ -n "${DISPLAY}" ] && export EDITOR=gedit || export EDITOR=emacs
根据评论修复。
使用 bash 约定:
if [[ $DISPLAY ]]; then export EDITOR=gedit else export EDITOR=emacs fi