String comparision not working

have written a simple shell script to do some automation work. Basically the script searches for all the files in the current path and if the file is a specified one, it does some action. Below are the relevant lines ---

#!/bin/bash
1.for i in ls *
2.do
3.if [$i =="ls.sh"]
4.then .... //do something 5.fi 6.done

However, the string comparision in line 3 is not working and I am getting this when I run the script --

./ls.sh: line 3: [scripth.sh: command not found
./ls.sh: line 3: [scripth.sh~: command not found
./ls.sh: line 3: [test.sh: command not found

What is the correction to be done ?

You should have a "space" in the if clause

if [ $i == "ls.sh" ] 
then
  echo "Doing something"
fi

regards,
Ahamed

There has to be space after [ and before ] and around test operator, so if statement looks like this:

if [ $i == "ls.sh" ]
  1. There's no need of ls
    Supposing you have a.txt and b.txt un current directory : in for i in ls * will expand to
ls
a.txt
b.txt

You could simply write

for i in *