Why is the value of this string, in a bash script, being executing?
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/13
2:37 UTC
Read the original article
Hit count: 343
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