运行"Cygwin.bat"和仅运行"bash"时的区别(.bash_profile与.bashrc) [英] Difference when running 'Cygwin.bat' and if just running 'bash' (.bash_profile vs. .bashrc)
问题描述
当我运行Cygwin.bat
时,我所有的自定义内容都可以从.bash_profile
中运行,但是当我只运行bash
时,我的.bash_profile
中的所有内容都无法正常工作,而我只是得到了有线前缀就像root@comp:/mnt/c/cygwin64#
(作为我的当前目录)
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)
运行bash
时是否有任何方法可以实现与运行Cygwin.bat
Is there any way to achieve the same result when running bash
as I got when running Cygwin.bat
Cygwin.bat
的内容是:
@echo off
C:
chdir C:\Tools\cygwin64\bin
bash --login -i
推荐答案
正如@matzeri在评论中指出的,cygwin.bat
使用--login
选项调用bash
,该选项创建交互式登录shell .而没有--login
选项的bash
会创建一个交互式外壳,它不是登录外壳.
As pointed out by @matzeri in the comment, cygwin.bat
invokes bash
with the --login
option which creates an interactive login shell. And bash
without the --login
option creates an interactive shell which is not a login shell.
根据bash 手册页:
当bash作为交互式登录外壳或作为非交互式调用时 shell 和
--login
选项,它首先从以下位置读取并执行命令 文件/etc/profile
(如果该文件存在).读取该文件后, 依次搜索~/.bash_profile
,~/.bash_login
和~/.profile
,然后 从存在且可读的第一个命令中读取并执行命令.--noprofile
选项可以在启动外壳程序时禁止使用 行为.
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.
启动不是登录shell 的交互式shell 时,bash读取
并从~/.bashrc
执行命令(如果该文件存在).这可能是
通过使用--norc
选项禁止. --rcfile
文件选项将强制
bash从文件而不是~/.bashrc
读取和执行命令.
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
.
and I put all conf in ~/.bashrc
.
这篇关于运行"Cygwin.bat"和仅运行"bash"时的区别(.bash_profile与.bashrc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!