I have a function to check if a file exists in a path or not
file_exists ()
{
[ -f $1 ]
}
My requirement is to check for multiple files (in this case 2 files) which are in different paths. If both files exist then only I should move to next step.
Here I thought of using IF condition with an AND gate, but unable to get the result I'm expecting.
The function is never getting called from the IF condition.
Can someone help me with my requirement and also how can I write it better?
if [[ $(file_exists /opt/file1) == "0" && $(file_exists /temp/file2) == "0" ]];
then
#next steps code here
else
echo " some files missing"
fi
file_exists() { [ -f "$1" ]; }. (Although IMO this is a lot cleaner if you write itfile_exists() { test -f "$1"; }. The square brackets just seem to cause confusion and offer no benefit overtest.