在学习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: 未找到命令 这样提示。

 

相关文章:

  • 2021-05-20
  • 2021-06-19
  • 2022-01-01
  • 2022-03-04
  • 2021-06-30
  • 2021-12-28
  • 2021-11-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2021-12-21
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案