为什么在bash脚本中该字符串的值正在执行?

Ros*_*oss 3 unix linux bash shell

为什么此脚本在if语句中执行字符串:

#!/bin/bash
FILES="*"
STRING=''

for f in $FILES
do
  if ["$STRING" = ""]
   then
    echo first
    STRING='hello'
   else
    STRING="$STRING hello"
  fi
done

echo $STRING
Run Code Online (Sandbox Code Playgroud)

sh script.sh输出运行时:

first
lesscd.sh: line 7: [hello: command not found
lesscd.sh: line 7: [hello hello: command not found
lesscd.sh: line 7: [hello hello hello: command not found
lesscd.sh: line 7: [hello hello hello hello: command not found
lesscd.sh: line 7: [hello hello hello hello hello: command not found
hello hello hello hello hello hello
Run Code Online (Sandbox Code Playgroud)

ps首先尝试shell脚本
谢谢

Joh*_*itb 6

您正在尝试执行该命令[hello.之后放置一个空格[,它将被视为一个测试.

for f in $FILES
do
  if [ "$STRING" = "" ]
   then
    echo first
    STRING='hello'
   else
    STRING="$STRING hello"
  fi
done
Run Code Online (Sandbox Code Playgroud)