[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: detect shell script language

Lorenzo Bettini <bettini@dsi.unifi.it> writes:


> However, there are cases where this is not enough, since the script,
> although it has #!/bin/sh is actually written (and interpreted) in
> another language, e.g., Tcl.
> So my question is, is there another way of detecting the actual
> language?  I mean, another convention?

I think you'll find a wide variety of conventions, and you'll want to
look for several of them, and use a heuristic to choose the best one.

One way to do this would be to put appropriate strings in /etc/magic,
so that file(1) could detect them, then use that.  file(1) can already
detect lots of things, so it's a useful framework to start with, and
it can very quickly deal with many types of patterns.

Another way would be to read in the first block of the file, then run
a few regular expressions over it to make a good guess.

Good luck,


Reply to: