当我运行 Cygwin.bat
时,我的所有自定义内容都可以从 .bash_profile
运行,但是当我只是运行 bash
时> 我的 .bash_profile
中的任何东西都不起作用,我只是得到了像 root@comp:/mnt/c/cygwin64#
这样的有线前缀(作为我当前的目录)
有什么方法可以在运行bash
时获得与运行Cygwin.bat
时相同的结果
Cygwin.bat
的内容是:
@echo off
C:
chdir C:\Tools\cygwin64\bin
bash --login -i
最佳答案
正如 @matzeri 在评论中指出的,cygwin.bat
使用 --login
选项调用 bash
,该选项创建一个 交互式登录外壳。没有 --login
选项的 bash
会创建一个交互式 shell,它不是登录 shell。
根据bash man page :
When bash is invoked as an interactive login shell, or as a non-interactive shell with the
--login
option, it first reads and executes commands from the file/etc/profile
, if that file exists. After reading that file, it looks for~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable. The--noprofile
option may be used when the shell is started to inhibit this behavior.When an interactive shell that is not a login shell is started, bash reads and executes commands from
~/.bashrc
, if that file exists. This may be inhibited by using the--norc
option. The--rcfile
file option will force bash to read and execute commands from file instead of~/.bashrc
.
我的~/.bash_profile
只有一行:
source ~/.bashrc
我把所有conf都放在~/.bashrc
中。
关于windows - 运行 'Cygwin.bat' 和仅运行 'bash' 时的差异(.bash_profile 与 .bashrc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43937077/