Hi all
I have a list of file names in array. But this file names are not exact. so i want to search whether a file exists or not using regular expression.
code snippet:
if [ -f "*EQST*" ];
then
echo "File exists"
else
echo "File does not exits"
fi
over here "*EQST*" should be treated as a regular expression. and the Actual file name in the directory will be something like 'Exp_BK_FT_T_EQST.txt'.
So how should i do this?
The above could is taking *EQST* as a string and trying to search with the same name.
TIA
Regards
Ganesh
---------- Post updated at 02:51 PM ---------- Previous update was at 02:45 PM ----------
Hey got it no need to reply. i just had to remove the double quotes from the if clause.
Generally, that won't work either. If the pattern goes unmatched, it remains unmodified and will be assigned to the array as is. If there is no match, the array will have 1 member. If one file matches, the array will also have 1 member. If many files match, the array will have more than 1 member. In all cases, the subsequent test will evaluate to true.
Some shells can be told to replace unmatched patterns with a null string (e.g. bash's shopt -s nullglob ), but this is not the default, standard-compliant behavior.