A Bash-becue recipe :)

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 :)

  1. Using your favourite language, populate an associative array with the strings that file shows for the extensions that you are interested to map. Like:
    php => PHP script text
    pl  => perl script text executable
  2. Within a Bash loop over the folder of your files:
    • run file against 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.
  3. Don’t grill that much, please. :)

Last update: 2008-05-20

2 Comments

  1. Drake
    Posted August 19, 2007 at 1:28 am | Permalink

    Hi, I enjoyed the read.

  2. Posted August 20, 2007 at 8:36 am | Permalink

    Drake: good. :)

Post a Comment

Your email is never shared. Required fields are marked *

*
*