Identify missing file

I am on linux and I am supposed to receive 3 files. If any of the files are not received I need to identify the missing file and throw it out in a variable.

I have put in something like this

if [[ -a $file1 ]]
    then echo "file $file1 was found"
else
    echo "ERROR: file $file1 was not found!!!"
      #####  set a variable here ##############
       fi

if [[ -a $file2 ]]
    then echo "file $file2 was found"
else
    echo "ERROR: file $file2 was not found!!!"
 #####  set a variable here ##############
               
fi

if [[ -a $file3 ]]
    then echo "file $file3 was found"
else
    echo "ERROR: file $file3 was not found!!!"
                #####  set a variable here ##############

Is there a way I can capture each file in a variable and throw out the missing file after all the checks are completed?

Something like this,

missing_file=$file1
echo $missing_file

Thanks. How can I check if any of the 3 files is missing and exit out with the missing file information

What do you mean by "capture each file in a variable"? You already have each file's pathname in a variable. You can't put the contents of a file that was not found in a variable (unless you just want to set a variable to an empty string).

I assume that you are asking for our help in setting variables (since you have put those comments in bold text), but I have no idea what you intend to do with those variables???

How do you "throw out the missing file"? If a file is missing isn't it already gone???

You can use a loop over your files, for instance (since you didn't specify which shell you want to use) in bash/zsh:

typeset -i number_of_unfound_files=0
for file_to_check in $file1 $file2 $file3
do
   [[ -a $file_to_check ]] || ((++number_of_unfound_files)
done

What you have to do exactly in the loop, I can't say, because - as Don Cragun already pointed out - you did not specify it in your posting.

What i was looking for was to find out which file is missing by assigning a variable in the check condition for each file and if any of the variables have a value exit it out by throwing which file was missing based on the variable.

I would use something like:

missing=0
for file in "$file1" "$file2" "$file3"
do	if [ -e "$file" ]
	then	printf 'file "%s" found.\n' "$file"
	else	printf 'file "%s" not found.\n' "$file" >&2
		missing=$((missing + 1))
	fi
done
if [ $missing -ne 0 ]
then	[ $missing -eq 1 ] && string=" is" || string="s are"
	printf 'Exiting because %d file%s missing.\n' $missing "$string" >&2
	exit 1
fi

Thanks Don

To capture the missing file names in a list, try

for file in "$file1" "$file2" "$file3"
  do    if [ ! -e "$file" ]
        then    missing=$((missing + 1))
                misslist="$misslist $file,"
        fi
  done