I have an executable which creates either file1
or file2
along with other files. I am trying to write a shell script which should output the latest created file. If the executable creates file1
, the output should be file1
. Please note that I already have both file1
and file2
exists in the directory along with other files. The executable overwrites it.
If there are no file1/file2 exist, below script works but this doesn't work if both file1
and file2
exists.
if [ -e "file1" ]; then
output="file1"
else
output="file2"
fi