how to check identical files name as prefix present or not in shell script i.e. MY_REPORT_2018_04_23_01.txt, MY_REPORT_2018_04_23_02.txt, MY_REPORT_2018_04_13_03.txt etc.
when i am trying:
if [ ! -e MY_REPORT_*.txt ] ;
then
echo "files not present in current directory"
exit 1
fi
It's working but with a warning message:
[: too many arguments
Use an array:
#!/usr/bin/env bash
shopt -s nullglob # make sure glob evaluates to nothing if there are no matches
files=(MY_REPORT_*.txt) # create an array of matching files
if ((${#files[@]} == 0)); then # check number of items in array
echo "Files not present"
exit 1
fi
Check this post to understand how [ ... ] works:
Another related post:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With