Find ordinary files in directory input by user

I need to make a shell script that accepts a directory input by the user. The program searches for the directory and finds if it exists or not. Then if it does exist, it outputs the number of files within that directory. Here's what I have so far.

result=
echo "Please input a directory: \c"
read directory
if [-d "$directory"];
then
        result=ls -l . | egrep -c '^-'
        echo "The file $directory is a directory with the # of ordinary files: $
result"
else
        echo "The file $directory is not a directory or does not exist."
fi

When I run the script, I get an error that

[-d: execute permission denied

How can I fix this script?

It's difficult to tell for sure because you didn't use code tags, but I'm guessing you need a space between the opening bracket and the -d.

if [ -d $directory ]
then
   echo "$directory is a directory"
fi

You also will need to fix your ls command:

result=$(ls -l . | egrep -c '^-')

Ok now I fixed those two errors and now it is giving me a syntax error: `result=$' unexpected.

I'm guessing that the version of shell doesn't support $(command) syntax. What shell and what version of it are you using?

You could try this:

result=`ls -l . | egrep -c '^-'`

It is saying I need a ) at the end of line 1: result=

I am using the sh shell by the way

I fixed a typo in my example with back quotes, but that shouldn't have generated the error you are seeing. Can you post the script that is giving you the error so we can see what you are trying?