samedi 21 février 2015

Search if file exists for a file pattern stored in array

I have two arrays one has the file paths to be searched in , and the other has the files to be serached.For eg searchfile.dat will have File: abc303 xyz123


i have to search for files that could be abc303*.dat or for that matter any extension . abc303*.dat.gz


The following code doesnt work if i give * , it works only if i give the exact file name to be searched in the searchfile.dat , also i tried without quotes and without backslash.


Im using ksh



while [[ $i -lt ${#filearray[@]} ]];do
while [[ $j -lt ${#filepath[@]} ]];do
found=0
if [[ -a "${filepath[$j]}/${filearray[$i]}"\* ]]; then
echo ${filepath[$j]}/${filearray[$i]} "found"

Aucun commentaire:

Enregistrer un commentaire