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

Re: detect shell script language

On 9/1/06, Lorenzo Bettini <bettini@dsi.unifi.it> wrote:
Ron Johnson wrote:
> Hash: SHA1
> Lorenzo Bettini wrote:
>> Hi
>> I need to detect the actual programming language of a script.
>> A way of detecting it is to examine the first line searching for the
>> "sha-bang" (#!), e.g.,
>> #!/bin/bash
>> or
>> #!/usr/bin/perl
>> 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?
> Is this internal to the script, or external (looking in)?

I need to detect the language of the script in order to highlight it
accordingly (GNU source-highlight http://www.gnu.org/software/src-highlite)

for instance I have some tcl scripts that start as follows:

# Tcl ignores the next line -*- tcl -*- \
exec wish "$0" -- "$@"

and I want them to be colorized as a Tcl script instead of a shell script

> I don't think that you can accurately do what you want, because a
> script can call multiple interpreters.
>   #!/bin/bash
>   echo 'A shellism'
>   python <<EOF1
>   print 'This is a python scriptlet'
>   print 'It can do many things'
>   EOF1
>   echo 'another shellism'
>   perl <<EOF2
>   {
>       print "This is a Perl scriptlet\n";
>       print "It also can do many things\n";
>   }
>   EOF2
>   echo 'a third shellism'

well that's not a big problem for what I'd like to do :-)

thanks in advance

|  Lorenzo Bettini          ICQ# lbetto, 16080134     |
|  PhD in Computer Science                            |
|  Dip. Sistemi e Informatica, Univ. di Firenze       |
|  Florence - Italy        (GNU/Linux User # 158233)  |
|  Home Page        : http://www.lorenzobettini.it    |
|  http://music.dsi.unifi.it         XKlaim language  |
|  http://www.purplesucker.com Deep Purple Cover Band |
|  http://www.gnu.org/software/src-highlite           |
|  http://www.gnu.org/software/gengetopt              |
|  http://www.lorenzobettini.it/software/gengen       |
|  http://www.lorenzobettini.it/software/doublecpp    |

To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

(I'm thinking out loud here)

How about identifying patterns specific to each shell, and then
implementing an algorithm that would produce score for each shell
match. The one with the highest score will be the one used by
src-highlite. This perhaps should be a standalone utility/lib, a fact
that would allow it to be used in other implementation besides

BTW, src-highlite is great. Thank you Lorenzo for adding another tool
to my already unbelievably huge free software tools arsenal.

Maxim Vexler

"Free as in Freedom" - Do u GNU ?

Reply to: