我想写一个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