Reading the referers of this website, I found that someone reached it querying a search engine for
bash scripting validate file extension
I suppose they were looking for a script that, for example, when it finds a perl file, it is able to recognise it as such even if its extension is not pl.
Well, the following is my recipe for your Ferragosto Bash-becue
- Using your favourite language, populate an associative array with the strings that
fileshows for the extensions that you are interested to map. Like:php => PHP script text pl => perl script text executable
- Within a Bash loop over the folder of your files:
- run
fileagainst each file and save the string that it shows; - using
awk, extract the extension of each file and look at the associative array: if the associated string is not the same that you have just found then the extension of your file is not validated.
- run
- Don’t grill that much, please.
Last update: 2008-05-20

2 Comments
Hi, I enjoyed the read.
Drake: good.