0

尝试编写一个 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

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

4

1 回答 1

3

在分配$之前删除多余的。diffv利用:

diffv=$(which diff)

和:

diffv=$MY_DIFF

$您一起获得:

<diffv value, empty>=<MY_DIFF value, or which diff>
=/opt/gnu/bin/diff
于 2013-08-02T16:33:29.413 回答