我可以在 Cygwin 中强制 XTerm.exe 的默认 BASH Shell 和其他非登录 Shell 加载 ~/.bashrc 吗?
Can I Force XTerm.exe's Default BASH Shell and Other Non-Login Shells in Cygwin to Load ~/.bashrc?
我在使用 Cygwin
时遇到问题,特定于 XTerm.exe
会话未正确加载 BASH
配置文件。
首先,我的 .startxwinrc
是:
#!/bin/sh
xrdb -merge ~/.Xresources
xterm -geometry +0+60 -ls &
xterm -geometry +0-100 &
exec xclock
...我的 .Xresources 是:
Xft*antialias: true
Xft*autohint: true
XTerm*background: white
XTerm*foreground: black
XTerm*cursorColor: orchid
XTerm*fullCursor: true
XTerm*reverseVideo: false
XTerm*geometry: 80x40
XTerm*scrollBar: true
XTerm*rightScrollBar: true
XTerm*scrollTtyOutput: off
XTerm*scrollKey: on
XTerm*reverseWrap: true
XTerm*saveLines: 10000
XTerm*faceName: BitStream Vera Sans Mono
XTerm*faceSize: 12
XTerm*toolBar: off
XTerm*VT100.Translations: #override\n\
<Key>BackSpace: string(0x7F)\n\
<Key>Delete: string("3[3~")\n\
<Key>Home: string("3[1~")\n\
<Key>End: string("3[4~")\n\
<KeyPress>Prior : scroll-back(1,page)\n\
<KeyPress>Next : scroll-forw(1,page)
我将我的 X 服务器启动为:
startxwin &
而且我看到上面的配置有效...我得到两个 XTerm
windows 和一个 xclock
(并且颜色和滚动等符合我的规格)。
但奇怪的是终端提示不是我在 ~/.bashrc
配置文件中设置的。
起初我以为我的问题与这些问题有关:
Why is my .bashrc not read under cygwin?
Cygwin shell doesn't execute .bashrc
...这表明问题可能是实际配置设置是从 ~/.profile
或 ~/.bash_profile
加载的。但是添加这些没有任何作用。
为了验证它们不是 运行,我在三个 bash 配置文件(.bashrc
、.bash_profile
和 .profile
) 在我的主目录中:
echo "**** EXECUTING /home/JasonMick/.bash_profile *****" | \
tee -a /tmp/shell.log
该文件从未被写入...很明显这些文件从未被触及过。
接下来我验证了我的 Windows 环境变量中没有 "HOME" 变量(有人认为这可能是此类问题的根源)。没有这个变量,所以我在这方面没问题。
接下来我使用...
验证了一些关于shell状态的基本信息
printf '%s\n' $SHELL $HOME $USER
XTerm 的结果是:
/bin/bash
/home/JasonMick
JasonMick
这些结果与在非 X11
终端 mintty
(我通常用来启动 startxwin
)中执行的相同命令的结果完全匹配。但是,当我打开新的 mintty
时,提示是正确的,根据我的主目录 .bashrc
文件中的设置。
为了安全起见,我在/etc/
中搜索了.profile
、.bashrc
和.bash_profile
个文件。我找到了以下文件:
/etc/profile
/etc/bash.bashrc
/etc/skel/.bashrc
/etc/skel/.bash_profile
/etc/defaults/etc/skel/.bashrc
/etc/defaults/etc/skel/.bash_profile
/etc/defaults/etc/bash.bashrc
/etc/defaults/etc/profile
我为所有这些都添加了印刷品。
在 mintty I 中,/etc/shell.log 文件获取以下命令:
**** EXECUTING /etc/profile ****
**** EXECUTING /etc/bash.bashrc *****
**** EXECUTING /home/JasonMick/.bash_profile *****
...所以它似乎在调用 /etc/
文件,然后最终在我的主目录中自动调用 .bash_profile
,没有来自 /etc/
的任何源调用配置文件。
删除日志,我启动 startxwin。 Xterm 打开,但日志文件不存在!
这意味着 XTerm 没有触及任何配置文件.. 不在 /etc/
不在 ${HOME}
!
我发现的唯一区别是,在 mintty
中调用 echo [=45=] $-
时,我得到:
-bash himBH
...在 XTerm 中,我得到:
bash himBH
根据以下信息:
Difference between Login Shell and Non-Login Shell?
Why 'echo [=64=]' gives different result for two different terminals?
我的 bash shell 在 Xterm 中是一个 interactive (i flag in $-
)非登录([=48=]
前面没有-)BASH
shell,而我的mintty
是迭代, 登录 BASH
shell.
好的。基于上面的第二个 link,我仍然希望我的 非登录 interactive shells 加载我的 ~/. bashrc。但同样,如上所述,它不仅不加载该文件......据我所知,它们没有加载任何 bash 配置文件。 None ${HOME}
... none /etc/
.
知道如何在 Cygwin 中强制 非登录 shells(即 XTerm
默认 shell 会话)以正确获取源~/.bashrc
或 ~/.bash_profile
?
我是不是做错了什么?
您可能也注意到了这一点:Run xterm with login shell or not?,它指出 xterm 的 loginShell
资源可用于告诉它充当登录shell.
此外,根据 Cygwin FAQ. The FAQ mentions some typical problems with HOME
.
,取消设置(或错误设置)HOME
变量会在启动时干扰采购 .bashrc
我发现在 Cygwin
中我可以通过调用 non-login shell 加载它们的配置设置12=] 在我的 .startxwinrc
文件中。新的 .startxwinrc
文件是:
#!/bin/sh
export ENV=~/.bashrc
xrdb -merge ~/.Xresources
xterm -geometry +0+60 -ls &
xterm -geometry +0-100 &
exec xclock
打扰 xterm
会话和他们的 children 现在可以正确地获取我的 ~/.bashrc
.
@Gilles 在线程 Difference between Login Shell and Non-Login Shell? 中指出:
"When you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, …), you get an interactive, non-login shell. That shell might read a shell configuration file (~/.bashrc
for bash invoked as bash
, /etc/zshrc
and ~/.zshrc
for zsh, /etc/csh.cshrc
and ~/.cshrc
for csh, the file indicated by the ENV
variable for POSIX/XSI-compliant shells such as dash, ksh, and bash when invoked as sh
, $ENV
if set and ~/.mkshrc
for mksh, etc.)."
当我第一次读到它时,第一个子句似乎暗示 ~/.bashrc
会自动加载 non-login shells。虽然第二个子句确实声明可以定义变量 ENV
来设置 bash
的配置文件位置,但第一个子句的语言让人不清楚这是否总是有必要,或者只是有时有必要?根据我的发现,对于某些默认 GUI 文件包含导出对应于默认 shell 配置文件的 ENV
变量的调用的平台,"sometimes" 可能是正确的。
@ThomasDickey 对相关问题的链接解决方案帮助我重新评估了上面引用的@Gilles 答案。但是,他建议将我的 XTerm
调用更改为 login shells 在这一点上我认为不是最好的答案,因为唯一的区别是我担心的是无法自动加载 shell 配置,我的修复补救措施是 non-login shells.
对 uptime
的调用与 Difference between... 状态下的某些其他报告调用存在差异,但我认为这些并不是我的用例所关注的问题。我的部署是使用 Cygwin
的单用户本地部署,无意接受对我机器的传入 ssh
调用。因此,没有令人信服的理由我可以找到不采用更简单的一行修复,它通过 ${ENV}
将正确的配置文件应用到所有 XTerm
s,而不是向每个添加一个标志的更冗长的修复XTerm
调用,告诉它以 login 模式启动 shell。
我在使用 Cygwin
时遇到问题,特定于 XTerm.exe
会话未正确加载 BASH
配置文件。
首先,我的 .startxwinrc
是:
#!/bin/sh
xrdb -merge ~/.Xresources
xterm -geometry +0+60 -ls &
xterm -geometry +0-100 &
exec xclock
...我的 .Xresources 是:
Xft*antialias: true
Xft*autohint: true
XTerm*background: white
XTerm*foreground: black
XTerm*cursorColor: orchid
XTerm*fullCursor: true
XTerm*reverseVideo: false
XTerm*geometry: 80x40
XTerm*scrollBar: true
XTerm*rightScrollBar: true
XTerm*scrollTtyOutput: off
XTerm*scrollKey: on
XTerm*reverseWrap: true
XTerm*saveLines: 10000
XTerm*faceName: BitStream Vera Sans Mono
XTerm*faceSize: 12
XTerm*toolBar: off
XTerm*VT100.Translations: #override\n\
<Key>BackSpace: string(0x7F)\n\
<Key>Delete: string("3[3~")\n\
<Key>Home: string("3[1~")\n\
<Key>End: string("3[4~")\n\
<KeyPress>Prior : scroll-back(1,page)\n\
<KeyPress>Next : scroll-forw(1,page)
我将我的 X 服务器启动为:
startxwin &
而且我看到上面的配置有效...我得到两个 XTerm
windows 和一个 xclock
(并且颜色和滚动等符合我的规格)。
但奇怪的是终端提示不是我在 ~/.bashrc
配置文件中设置的。
起初我以为我的问题与这些问题有关:
Why is my .bashrc not read under cygwin?
Cygwin shell doesn't execute .bashrc
...这表明问题可能是实际配置设置是从 ~/.profile
或 ~/.bash_profile
加载的。但是添加这些没有任何作用。
为了验证它们不是 运行,我在三个 bash 配置文件(.bashrc
、.bash_profile
和 .profile
) 在我的主目录中:
echo "**** EXECUTING /home/JasonMick/.bash_profile *****" | \
tee -a /tmp/shell.log
该文件从未被写入...很明显这些文件从未被触及过。
接下来我验证了我的 Windows 环境变量中没有 "HOME" 变量(有人认为这可能是此类问题的根源)。没有这个变量,所以我在这方面没问题。
接下来我使用...
验证了一些关于shell状态的基本信息printf '%s\n' $SHELL $HOME $USER
XTerm 的结果是:
/bin/bash
/home/JasonMick
JasonMick
这些结果与在非 X11
终端 mintty
(我通常用来启动 startxwin
)中执行的相同命令的结果完全匹配。但是,当我打开新的 mintty
时,提示是正确的,根据我的主目录 .bashrc
文件中的设置。
为了安全起见,我在/etc/
中搜索了.profile
、.bashrc
和.bash_profile
个文件。我找到了以下文件:
/etc/profile
/etc/bash.bashrc
/etc/skel/.bashrc
/etc/skel/.bash_profile
/etc/defaults/etc/skel/.bashrc
/etc/defaults/etc/skel/.bash_profile
/etc/defaults/etc/bash.bashrc
/etc/defaults/etc/profile
我为所有这些都添加了印刷品。
在 mintty I 中,/etc/shell.log 文件获取以下命令:
**** EXECUTING /etc/profile ****
**** EXECUTING /etc/bash.bashrc *****
**** EXECUTING /home/JasonMick/.bash_profile *****
...所以它似乎在调用 /etc/
文件,然后最终在我的主目录中自动调用 .bash_profile
,没有来自 /etc/
的任何源调用配置文件。
删除日志,我启动 startxwin。 Xterm 打开,但日志文件不存在!
这意味着 XTerm 没有触及任何配置文件.. 不在 /etc/
不在 ${HOME}
!
我发现的唯一区别是,在 mintty
中调用 echo [=45=] $-
时,我得到:
-bash himBH
...在 XTerm 中,我得到:
bash himBH
根据以下信息:
Difference between Login Shell and Non-Login Shell?
Why 'echo [=64=]' gives different result for two different terminals?
我的 bash shell 在 Xterm 中是一个 interactive (i flag in $-
)非登录([=48=]
前面没有-)BASH
shell,而我的mintty
是迭代, 登录 BASH
shell.
好的。基于上面的第二个 link,我仍然希望我的 非登录 interactive shells 加载我的 ~/. bashrc。但同样,如上所述,它不仅不加载该文件......据我所知,它们没有加载任何 bash 配置文件。 None ${HOME}
... none /etc/
.
知道如何在 Cygwin 中强制 非登录 shells(即 XTerm
默认 shell 会话)以正确获取源~/.bashrc
或 ~/.bash_profile
?
我是不是做错了什么?
您可能也注意到了这一点:Run xterm with login shell or not?,它指出 xterm 的 loginShell
资源可用于告诉它充当登录shell.
此外,根据 Cygwin FAQ. The FAQ mentions some typical problems with HOME
.
HOME
变量会在启动时干扰采购 .bashrc
我发现在 Cygwin
中我可以通过调用 non-login shell 加载它们的配置设置12=] 在我的 .startxwinrc
文件中。新的 .startxwinrc
文件是:
#!/bin/sh
export ENV=~/.bashrc
xrdb -merge ~/.Xresources
xterm -geometry +0+60 -ls &
xterm -geometry +0-100 &
exec xclock
打扰 xterm
会话和他们的 children 现在可以正确地获取我的 ~/.bashrc
.
@Gilles 在线程 Difference between Login Shell and Non-Login Shell? 中指出:
"When you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, …), you get an interactive, non-login shell. That shell might read a shell configuration file (~/.bashrc
for bash invoked as bash
, /etc/zshrc
and ~/.zshrc
for zsh, /etc/csh.cshrc
and ~/.cshrc
for csh, the file indicated by the ENV
variable for POSIX/XSI-compliant shells such as dash, ksh, and bash when invoked as sh
, $ENV
if set and ~/.mkshrc
for mksh, etc.)."
当我第一次读到它时,第一个子句似乎暗示 ~/.bashrc
会自动加载 non-login shells。虽然第二个子句确实声明可以定义变量 ENV
来设置 bash
的配置文件位置,但第一个子句的语言让人不清楚这是否总是有必要,或者只是有时有必要?根据我的发现,对于某些默认 GUI 文件包含导出对应于默认 shell 配置文件的 ENV
变量的调用的平台,"sometimes" 可能是正确的。
@ThomasDickey 对相关问题的链接解决方案帮助我重新评估了上面引用的@Gilles 答案。但是,他建议将我的 XTerm
调用更改为 login shells 在这一点上我认为不是最好的答案,因为唯一的区别是我担心的是无法自动加载 shell 配置,我的修复补救措施是 non-login shells.
对 uptime
的调用与 Difference between... 状态下的某些其他报告调用存在差异,但我认为这些并不是我的用例所关注的问题。我的部署是使用 Cygwin
的单用户本地部署,无意接受对我机器的传入 ssh
调用。因此,没有令人信服的理由我可以找到不采用更简单的一行修复,它通过 ${ENV}
将正确的配置文件应用到所有 XTerm
s,而不是向每个添加一个标志的更冗长的修复XTerm
调用,告诉它以 login 模式启动 shell。