ZSH / /类型-p的别名不识别节点

时间:2012-07-20 21:22:32

标签: shell zsh

我们有代码来检查节点安装:

which="type -p"
if [ $SHELL = "/bin/zsh" ]; then
    which="whence"
fi
# make sure that node exists
node=`$which node 2>&1`
ret=$?
if [ $ret -ne 0 ] || ! [ -x "$node" ]; then
<"This error code is returned">

但是当我用ZSH(OhMyZsh)运行它时,它返回127(不存在)。评论which="whence"可以让它运行良好。

没有删除整个别名位有没有办法让ZSH与此一起玩?理想情况下,我想在我的结尾做一个改变,而不是修改这个代码。

1 个答案:

答案 0 :(得分:1)

您的意思是,您运行$node并且您似乎尝试运行名称为node --alias-args且不存在的命令?

如果是这样,请更改第三行以使用whence -p:它在bash中具有与type -p相同的输出。如果没有,请解释返回此代码的时间。

更新:我不知道在ohmyzsh中做了什么(虽然我没有一个想法如何使内置程序找不到)所以只是尝试以这种方式重写代码:

# At the very top
if [ -n $ZSH_VERSION ] ; then
    emulate -L zsh
endif
<...>
which="type -p"
if [ -n $ZSH_VERSION ] ; then
    which=( whence -p ) # Changes variable type as well
endif
node=`$which node 2>&1`
if (( ? )) || ! test -x $node ; then
<...>