open files

I want to open a file and edit it using vi However, i dont want to open directories or binary files. how can i do this?

Right now it opens all files without caring

echo "please enter a file to edit in Vi"
read file

if [  'grep " $file"'   ]

then

do a check whether its a dir or regular file, before you open it:

if [ -d $file ] ; then echo "its a dir" ; fi
if [ -f $file ] ; then echo "its a regular file" ; fi

Also, you got single quotes there, which is probably not what you want. You want "backticks", which is the key next to '1'.

You could start by making sure file is a regular file and is readable (or writable?). Then checking output of "file" command for "ASCII" might be enough:

if [ -f "$file" ] && [ -r "$file" ]
then
    file "$file" | grep -q "ASCII"
    if [ $? -eq 0]
    then
        vi "$file"
    else
       echo "$file" "is not an ASCII file - vi not allowed"
    fi
fi