星期二, 1月 12, 2010

用 bash source 時,出現 "file not found"

今天遇到很鳥的問題。

情境是這樣的:目前的目錄下有 .config,而 scripts 目錄下有個 shell script ,名稱是 Configure。Configure 的內容很簡單,就是 source .config。接著,在目前的目錄下輸入 sh scripts/Configure,你就會遇到 ".config: file not found" 的訊息。

試了好久,雖然知道可以用 bash 執行來解決,但是就是覺得奇怪,因為 9.04 的 bash 3.2 是沒問題的,但到了 9.10 的 bash 4.0 就不行了。
最後在這裡:Re: source command differs if in bash or sh mode 找到答案:
This is a property of bash posix mode when you don't have `.' in $PATH:

28. The `.' and `source' builtins do not search the current directory
for the filename argument if it is not found by searching `PATH'.

> This behavior is new in version 4, old version 3.2 works fine.

The bash-3.2 behavior was a bug. Its fix is listed in CHANGES:

ggg. Fixed a bug that caused a shell running in Posix mode to search $PWD for
a file specified as an argument to source/. when the file was not found
in $PATH.



對,這是 bug,bash 3.2 沒問題,是因為他是 bug,4.0 的時候修正了,所以就有問題了,你必須要在 PATH 裡加入 . 才行。

好鳥。

沒有留言:

您或許對這些文章有興趣

Related Posts Plugin for WordPress, Blogger...