简体   繁体   English

运行“ Cygwin.bat”和仅运行“ bash”时的区别(.bash_profile与.bashrc)

[英]Difference when running 'Cygwin.bat' and if just running 'bash' (.bash_profile vs. .bashrc)

When I am running Cygwin.bat I've got my all my custom stuff working from .bash_profile but when I am just running bash none of my stuff from .bash_profile is working and I am just got wired prefix like root@comp:/mnt/c/cygwin64# (as my current dir) 当我运行Cygwin.bat我所有的自定义内容都可以从.bash_profile运行,但是当我运行bash ,我的.bash_profile内容都无法正常工作,而我只能得到像root@comp:/mnt/c/cygwin64#这样的有线前缀。 root@comp:/mnt/c/cygwin64# (作为当前目录)

Is there any way to achieve the same result when running bash as I got when running Cygwin.bat 运行bash时是否有任何方法可以达到运行Cygwin.bat时获得的相同结果

the content of Cygwin.bat is: Cygwin.bat的内容是:

@echo off

C:
chdir C:\Tools\cygwin64\bin

bash --login -i

As pointed out by @matzeri in the comment, cygwin.bat invokes bash with the --login option which creates an interactive login shell . 正如在评论@matzeri指出, cygwin.bat调用bash--login它创建一个交互式登录shell选项。 And bash without the --login option creates an interactive shell which is not a login shell . 而没有--login选项的bash将创建一个交互式shell ,它不是登录shell

According to bash man page : 根据bash 手册页

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. 当bash作为交互式登录外壳或带--login选项的非交互式外壳被调用时,它首先从文件/etc/profile (如果存在)读取并执行命令。 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. 读取该文件后,它将~/.bash_login顺序查找~/.bash_profile~/.bash_login~/.profile ,并从存在且可读的第一个命令中读取并执行命令。 The --noprofile option may be used when the shell is started to inhibit this behavior. 启动外壳程序时,可以使用--noprofile选项禁止此行为。

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc , if that file exists. 启动不是登录外壳程序的交互式外壳程序时,bash从~/.bashrc读取并执行命令(如果该文件存在)。 This may be inhibited by using the --norc option. 使用--norc选项可以禁止这种情况。 The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc . --rcfile file选项将强制bash从文件而不是~/.bashrc读取并执行命令。

My ~/.bash_profile has only one line: 我的~/.bash_profile只有一行:

source ~/.bashrc

and I put all conf in ~/.bashrc . 我把所有的conf放在~/.bashrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM