Bash没有这样的文件或目录

时间:2013-08-02 16:29:18

标签: bash

尝试编写一个bash,其中要使用的命令在环境变量中指定(如果已定义)。这样做如下:

if [ -z $MY_DIFF ];
then
    echo Using standard diff $(which diff), change MY_DIFF env variable to use a different one.
    echo $(which diff)
    $diffv=$(which diff)
else
    $diffv=$MY_DIFF
fi

$diffv c.xml c2.xml

但我得到了:

./bash.sh: line 10: =/opt/gnu/bin/diff: No such file or directory
./bash.sh: line 13: c.xml: command not found

我确定该文件存在且我确实有权执行。知道问题可能是什么吗?

1 个答案:

答案 0 :(得分:3)

$分配之前删除额外的diffv。使用:

diffv=$(which diff)

diffv=$MY_DIFF

使用$

<diffv value, empty>=<MY_DIFF value, or which diff>
=/opt/gnu/bin/diff
相关问题