我想寫一個zsh函數來獲取python模塊的路徑。zsh函數捕獲命令輸出
這工作:
pywhere() {
python -c "import $1; print $1.__file__"
}
不過,我真的很喜歡的是沒有文件名的目錄路徑。這是行不通的:
pywhere() {
dirname $(python -c "import $1; print $1.__file__")
}
注意:它在bash中工作,但不在zsh中!
編輯這是錯誤:
~ % pywhere() {
function → dirname $(python -c "import $1; print $1.__file__")
function → }
File "<string>", line 1
import pywhere() {
^
SyntaxError: invalid syntax
這看起來是正確的,它適用於我。它怎麼不適合你? – Gilles
啊 - 只是注意到在另一個系統上工作正常。所以一定是我的zsh配置中的東西我猜..呃! – bee
如果我在preexec中使用標題函數,則會發生錯誤: http://dotfiles.org/~_why/.zshrc 我剛剛對此進行了評論。不確定爲什麼這會干擾函數定義。 – bee