Cygwin 找不到 /.bashrc

问题描述 投票:0回答:4

我在 Windows 7 64 位上安装了 Cygwin,我在

/.bashrc
位置上的位置是
C:/cygwin64/home/admin/bashrc
,但我无法从 Cygwin 中看到它,它说:

bash: /.bashrc: 没有这样的文件或目录

我尝试使用以下命令导航到该文件夹:

cd /cygdrive/c/cygwin64/home/admin/

然后使用:

/.bashrc

但它说:

没有这样的文件或目录

如何查看该文件?

windows cygwin bash
4个回答
5
投票

我在安装 Cygwin 时遇到了同样的问题。

CYGWIN_NT-6.1 2.5.2(0.297/5/3) x86_64 Cygwin

我在我的(cygwin)主目录中创建了一个 ~/.bashrc 文件,但我设置的别名不起作用。

问题是我的主目录中没有 ~/.bash_profile 文件。它必须包含以下行才能识别所需的 .bashrc

. ~/.bashrc

我通过附加所需的行来创建它

echo ". ~/.bashrc" >> ~/.bash_profile

参见 StackOverflow > Cygwin shell 不执行 .bashrc


2
投票

澄清一下:这与 Cygwin 无关。这是正常的 Bash 行为。

~/.profile:最初由/bin/sh使用的登录脚本文件名。

~/.bash_profile:个人初始化文件,为登录shell执行

~/.bashrc:每个交互式 shell 的单独启动文件。

每个新的 Cygwin 窗口(每次调用 Cygwin.bat)都会打开一个登录 shell,因为没有 init 进程并且您已经以 Windows 用户身份登录。在 Cygwin.bat 中调用 Bash,如下:

bash --login -i

因为

--login
~/.bash_profile 被执行。更具体地说,Bash 按顺序读取 /etc/profile,然后读取 ~/.bash_profile~/.bash_login~/.profile,并执行第一个可读的。

因为

-i
~/.bashrc 也应该被执行。但这并不是因为 Bash 只为交互式且非登录的 shell 执行 .bashrc

请注意,

bash --login -i --rcfile=C:/Cygin/home/%USERNAME%/.bashrc
也不起作用,因为在登录 shell 中,
--rcfile
会被默默忽略。

因此,如果是真正的登录 shell(文本登录 shell),最好挂钩 $HOME/.bashrc。这就是为什么许多 .bash_profile 文件包含以下行的原因:

if [ -f "${HOME}/.bashrc" ]; then
    source "${HOME}/.bashrc"
fi

当您 ssh/telnet 到主机、将 Linux 引导到文本模式或...运行 Cygwin.bat.

时,会出现文本登录 shell

说到这里我想补充一点。许多 Linux 桌面在启动过程桌面会话期间由显示管理器自动读取 ~/.profile(不是 ~/.bash_profile~/.bash_login)。因此,也将 ~/.bashrc 挂入 ~/.profile 中:

if [ -n "$BASH_VERSION" ]; then
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

因为 Bash 在没有 ~/.bash_profile 的情况下执行 ~/.profile,你可能只需要 ~/.profile

现在您可以在 ~/.bashrc 中进行所有自定义操作。


0
投票

找到你的

$HOME
,你可以尝试这个命令吗:

cd ~/

ls -la

如果他不存在,就创建它。 或者检查这篇文章:Cygwin shell 不执行 .bashrc

或尝试

cat ~/.bashrc

0
投票

老话题,我知道......但是,可能对某人有用。 在 cygwin64 in 文件夹中,创建一个名为 ls.bat 的 bacth 文件并添加以下内容:

@echo off
ls_.exe --color=auto %*

然后将 ls.exe 重命名为 ls_.exe

就是这样。

© www.soinside.com 2019 - 2024. All rights reserved.