bad if test

:confused:

Bad if test:

if [ -f filename]

returns an error
I have changed filename to
"filename"s su
"$filename"
'filename''
'$filename''
"./filename"
"./$filename"

error is usually [ -f: command not found]
why cant I test the filename?

Thanks

if [ -f filename] ; then echo file exist ; fi
if [ -f filename] ; then echo exist ; else echo " don't exist " ; fi

I often use the double [[ ]] to get the ksh internal tests.
if [[ -f $File ]]
then
print "yes"
else
print "no"
fi

You could use -L to test links, or -n just to see if $File is set.
a short notation is
[[ -f $File ]] && print "yes" || print "no"

Als nice is:

[[ ! -f $File ]] && print "no file found" && return 1
(abort script, returns with non-zero exit code)

Can you paste the script part where in you are using test.

Spaces are significant when using test command ...

if [ -f "$filename" ]
then
...
fi

Note the space between filename and ]