shell [ff: 未找到命令

在学习shell脚本时遇到一个问题:  [ff: 未找到命令

相信很多初学者都会遇到,再次说明一下,希望对大家有所帮助;

shell脚本代码如下:

#!/bin/bash

echo -n "str1"
read str1
echo -n "str2"
read str2
if [$str1 = "ff" -a $str2 = "ll"];then
echo "hello" $str1
else echo $str1$str2
fi

这段脚本运行便会出现  [ff: 未找到命令 的错误

以下shell脚本则正常执行

#!/bin/bash

echo -n "str1"
read str1
echo -n "str2"
read str2
if [ $str1 = "ff" -a $str2 = "ll" ];then
echo "hello" $str1
else echo $str1$str2
fi

细心的人会发现第一段代码if后面的中括号与 $str1 没有空格,而后面则加了空格,不加空格会将[和$str1解析成一个命令,因此出现 [ff: 未找到命令 这样提示。

原文地址:https://www.cnblogs.com/leinuo2016/p/6526606.html