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

标签 windows bash cygwin

当我运行 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/

相关文章:

python - 使用linux开发机搭建跨平台桌面应用的推荐方式

windows - Git diff 在子模块中不起作用

linux - Bash 不支持浮点运算——但为什么我可以使用 BC?

batch-file - 使用命令行将文本文件拆分为较小的多个文本文件

python - Python 3 和 Windows 7 的定时输入

ruby-on-rails - 无法在 Windows 上从 heroku 运行控制台

java - 我可以在不挂起主进程的情况下从 Java 以交互模式运行 bash 吗?

linux - 从多节文件中提取列

c - 如何在 C 中完成自动数组的排序?

windows - 如何在 c :/wamp/logs/file in Windows? 上跟踪 cygwin