运行"Cygwin.bat"和仅运行"bash"时的区别(.bash_profile与.bashrc) [英] Difference when running 'Cygwin.bat' and if just running 'bash' (.bash_profile vs. .bashrc)

查看:162
本文介绍了运行"Cygwin.bat"和仅运行"bash"时的区别(.bash_profile与.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆