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
You are trying to execute the command [hello. Put a space after [ so it will be regognized as a test.
for f in $FILES
do
if [ "$STRING" = "" ]
then
echo first
STRING='hello'
else
STRING="$STRING hello"
fi
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With