Determine the exist status

Hi,

i am a novice in scrpting and need your help on the following. i have a script that checks if a file exists:

if [ -f  $path/file1 ] ; then
echo " Files exists"
else 
echo " file not found"
fi

assuming the files does not exist ,, the script when run dusplays " file not found".. so far true. but when i type : echo $? i get output as 0.
shouldnt it say 1 if a condition fails.:confused: if possible can someone plz explain why it shows 0 instead of 1 when a condition has failed.

thanks

Did it? What condition should have failed?

Where did you put 'echo $?'

$? changes every time you run a statement, so it's easy to miss your chance at it having the value you're interested in.

Do the following exercise

[ -f /does/not/exist ]
echo $?
echo $?

The second echo returns the exit status of the first echo.
BTW always quote variables in command arguments!
[ -f "$path/file1" ] or [ -f "$path"/file1 ]