Error in loop

This is my first ever bash script. What i wish to achieve is to find all files in current directory except the script file and count lines in each found file. Some thing seems to be wrong with the if statement :confused: Please help why it does not work? and maybe you have some ideas how to improve this script :slight_smile:

#!/bin/bash

files=$(find . -maxdepth 1 -not -type d)
me=$(basename $0)
echo $me
for f in $files
do
    if [$f != $me]
    then
        echo $(wc -l $f);
    fi    
done

Just give the expression a little more space :stuck_out_tongue:

You have: if [$f != $me]
Should be: if [ $f != $me ]

EDIT:
Just out of fun it could be done smaller by removing the unrequired "$(echo $(wc -l":

me=$(basename $0)
for f in $(find . -maxdepth 1 -not -type d);do [ $f != $me ] && wc -l $f;done

hth

The immediate problem is the format of your test. Change:

    if [$f != $me]

to:

    if [ $f != $me ]

A much simpler solution might be:

me=${0##*/}
find . -maxdepth 1 ! -type d ! -name "$me" -exec wc -l {} +

thank you guys was realy hellpfull finaly it works :smiley: