gpt4 book ai didi

windows - 运行 'Cygwin.bat' 和仅运行 'bash' 时的区别(.bash_profile 与 .bashrc)

转载 作者:可可西里 更新时间:2023-11-01 10:03:20 25 4
gpt4 key购买 nike

当我运行 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 而不是 login 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com