我通常find
在搜索源代码时使用环境变量作为路径。最近我用符号链接替换了我的环境变量,它破坏了 Bash 的 shell 完成。当我find
使用符号链接时,它不起作用,但如果我使用符号链接指向的实际路径,它会找到。
ln -s /some/source/dir /the/source
export SYMLINK=/the/source
export DIR=/some/source/dir
find $SYMLINK -name file.c // doesn't find anything
find $DIR -name file.c // works as expected
Run Code Online (Sandbox Code Playgroud)
在此示例中,$SYMLINK 是 $DIR 值的符号链接。
那么,为什么 bash 以不同的方式处理符号链接环境变量?
这很奇怪:
$ ls -l 'Lana Del Rey - Blue Jeans (Remastered 2011).mp3'
-rw-rw-r-- 1 gigi gigi 4.0M Dec 11 23:06 'Lana Del Rey - Blue Jeans (Remastered 2011).mp3'
$ find . -name 'Lana Del Rey - Blue Jeans (Remastered 2011).mp3'
./Lana Del Rey - Blue Jeans (Remastered 2011).mp3
# but still in the same directory:
$ find `pwd` -name 'Lana Del Rey - Blue Jeans (Remastered 2011).mp3'
# nothing found!
# directly using the path pointed by pwd will produce …
Run Code Online (Sandbox Code Playgroud)