Why is the value if this string executing in a bash script?

Posted by Ross on Stack Overflow See other posts from Stack Overflow or by Ross
Published on 2010-03-12T23:31:45Z Indexed on 2010/03/12 23:37 UTC
Read the original article Hit count: 266

Filed under:
|
|
|

Hello

Why is this script executing the string in the if statement:

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

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

echo $STRING

when run it with sh script.sh outputs:

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

p.s. first attempt at a shell script
thanks

© Stack Overflow or respective owner

Related posts about shell

Related posts about bash