源没有正确读取符号链接?

源没有正确读取符号链接?

我的.bashrc文件是 的符号链接~/Scripts/rc/bashrc。这对我来说很有效,而且已经用了很多年了。

然而,截至今天,我看到的情况如下:

bash-4.3$ source .bashrc
bash: source: .bashrc: file not found
bash-4.3$ ls -la .bashrc
lrwxrwxrwx 1 jonas jonas 17 Oct 28 12:31 .bashrc -> Scripts/rc/bashrc
bash-4.3$ source Scripts/rc/bashrc 
jonas@jonas-xps:~$

我真的不明白这一点。为什么它会突然停止工作?我在一台 amd64 戴尔笔记本电脑上使用 Utopic。

一些调试输出:

bash-4.3$ stat .bashrc
  File: ‘.bashrc’ -> ‘Scripts/rc/bashrc’
  Size: 17          Blocks: 8          IO Block: 4096   symbolic link
Device: 22h/34d Inode: 10880136    Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1001/   jonas)   Gid: ( 1001/   jonas)
Access: 2014-10-28 12:31:57.076868217 +0100
Modify: 2014-10-28 12:31:57.076868217 +0100
Change: 2014-10-28 12:31:57.076868217 +0100
 Birth: -

bash-4.3$ stat Scripts/rc/bashrc
  File: ‘Scripts/rc/bashrc’
  Size: 4019        Blocks: 24         IO Block: 4096   regular file
Device: 22h/34d Inode: 11146383    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/   jonas)   Gid: ( 1001/   jonas)
Access: 2014-10-28 12:29:53.352871873 +0100
Modify: 2014-05-27 12:43:09.470849817 +0200
Change: 2014-05-27 12:43:09.470849817 +0200
 Birth: -

bash-4.3$ readlink -e .bashrc
/home/jonas/Scripts/rc/bashrc

答案1

如果文件名不包含/,则内置命令source可能仅在 中查找名称PATH,具体取决于某些 shell 选项。因此source .bashrc,不要使用 ,

`source ./.bashrc`

应该做你想做的事。

man bash

     .  filename [arguments]
    source filename [arguments]
           Read  and  execute  commands from filename in the current shell
           environment and return the exit status of the last command exe‐
           cuted  from  filename.   If  filename does not contain a slash,
           filenames in PATH are used to  find  the  directory  containing
           filename.   The  file  searched  for  in  PATH need not be exe‐
           cutable.  When bash is not in posix mode, the current directory
           is  searched  if  no  file is found in PATH.  If the sourcepath
           option to the shopt builtin command is turned off, the PATH  is
           not  searched.

相关内容