Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mac上bash脚本中的“-bash:[git:未找到命令”_Bash_Git_Macos - Fatal编程技术网

mac上bash脚本中的“-bash:[git:未找到命令”

mac上bash脚本中的“-bash:[git:未找到命令”,bash,git,macos,Bash,Git,Macos,我正在创建一个bash脚本来执行git命令。在一个函数中,我在git status上使用if语句: if [[ `git status --porcelain` ]]; then echo "has change" else echo "no" fi 然后给出了这个错误: -bash: [git: command not found git在命令行中运行良好,在没有if语句的其他函数中也运行良好 -bash:[git:未找到命令 此错误表示您的[和命令的其余部分之间没有空格,

我正在创建一个bash脚本来执行git命令。在一个函数中,我在git status上使用if语句:

if [[ `git status --porcelain` ]]; then
    echo "has change"
else
    echo "no"
fi
然后给出了这个错误:

-bash: [git: command not found
git在命令行中运行良好,在没有if语句的其他函数中也运行良好

-bash:[git:未找到命令

此错误表示您的[和命令的其余部分之间没有空格,如第1行无空格下方的屏幕截图所示


您确定这是导致错误的语句吗?更可能的情况是,您的语句在[和git之间没有空格,例如,如果[git status];那么为true;fi