Scenario1:If I pass the values as file_date=20170501 and prefix and suffix are empty.The script should give the count 2.
Since it should consider the files are 20170501 and 20170501.
But the script is not working properly.
Scenario2:If I pass the values as file_date=20170501 and prefix=abc_ and suffix is empty.The script should give the count 1.
Since it should consider the file abc_20170501
But the script is not working properly.
Scenario3:If I pass the values as file_date=20170501 and prefix is empty and suffix is .txt.The script should give the count 3.
Since it should consider the file 20170501.txt
But the script is not working properly.
Scenario4:If I pass the values as file_date=20170501 and prefix is abc_ and suffix is .txt.The script should give the count 1.
Since it should consider the file 20170501.txt
in this case the script is working properly.
Certainly not. NO two files with the same name CAN exist in the same directory
No - again.If suffix is empty, the search pattern is ${prefix}*${file_date}* and the count should be 2.
Certainly not. NO three files with the same name CAN exist in the same directory
Please note that a phrase "But the script is not working properly." doesn't really help people help you as it is way less descriptive than e.g. "the count printed is 14.7, expected was -5" or e.g. an exact error message.
Scenario1:If I pass the values as file_date=20170501 and prefix and suffix are empty.
My script is giving the count 4 it should be 1 since only one file with the date 20170501 without prefix and sufix.
Since it should consider the file 20170501.
Scenario2:If I pass the values as file_date=20170501 and prefix=abc_ and suffix is empty.
My script is giving the count 2 it should be 1 since only one file with abc_20170501 without sufix.
Since it should consider the file abc_20170501.
Scenario3:If I pass the values as file_date=20170501 and prefix is empty and suffix is .txt.
My script is giving the count 2 it should be 1 since only one file with 20170501.txt without prefix.
Since it should consider the file 20170501.txt.
Scenario4:If I pass the values as file_date=20170501 and prefix is abc_ and suffix is .txt.
My script is working properly for this scenario. The count is 1. I's considering the file abc_20170501.txt
Could you please provide generic script to work for all scenarios.
The script counts correctly. As said before, look at the pattern when both fixes are empty: *${file_date}* What would you expect with a pattern like that?
What RudiC is pointing out is your wildcards which I missed it too.
Just think about your prefix and suffix with reference to your wildcards.
Do you put the wildcards inside the prefix and suffix or do you have the wildcards as a separate input say as wildcard="*" and call as ${wildcard} if and when it is needed. You could toggle the wildcard from "" to "*" as you need.