Check whether file exists in directory

Hi guys,
I am beginner trying to learn unix. So any help is welcomed.
My requirement is to check whether is a file exists in a particular directory or not.
The directory path and filename are taken dynamically with user interaction. So the program should continue only if the $filename exists in $directory

Regards,
Maris Markur

You may see the manual page for test

man test

The flag -f may be of use in this context.

if [ -f $directory/$filename ];then
#action
fi
1 Like