GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  SYNTAX::HIGHLIGHT::SHELL (3)

.ds Aq ’

NAME

Syntax::Highlight::Shell - Highlight shell scripts

CONTENTS

VERSION

Version 0.04

SYNOPSIS



    use Syntax::Highlight::Shell;

    my $highlighter = new Syntax::Highlight::Shell;
    $output = $highlighter->parse($script);



If $script contains the following shell code:



    # an if statement
    if [ -f /etc/passwd ]; then
        grep $USER /etc/passwd | awk -F: {print $5} /etc/passwd
    fi



then the resulting HTML contained in $output will render like this:

DESCRIPTION

This module is designed to take shell scripts and highlight them in HTML with meaningful colours using CSS. The resulting HTML output is ready for inclusion in a web page. Note that no reformating is done, all spaces are preserved.

METHODS

new() The constructor. Returns a Syntax::Highlight::Shell object, which derives from Shell::Parser.

<B>OptionsB>
o nnn - Activate line numbering. Default value: 0 (disabled).
o pre - Surround result by <pre>...</pre> tags. Default value: 1 (enabled).
o syntax - Selects the shell syntax. Check the documentation about the syntax() method in Shell::Parser documentation for more information on the available syntaxes. Default value: bourne.
o tabs - When given a non-nul value, converts tabulations to this number of spaces. Default value: 4.

<B>ExampleB>

To avoid surrounding the result by the <pre>...</pre> tags:



    my $highlighter = Syntax::Highlight::Shell->new(pre => 0);



parse() Parse the shell code given in argument and returns the corresponding HTML code, ready for inclusion in a web page.

<B>ExamplesB>



    $html = $highlighter->parse(q{ echo "hello world" });

    $html = $highlighter->parse(<<END);
        # find my name
        if [ -f /etc/passwd ]; then
            grep $USER /etc/passwd | awk -F: {print $5} /etc/passwd
        fi
    END



    Internal Methods

The following methods are for internal use only.
_generic_highlight() Shell::Parser callback that does all the work of highlighting the code.

NOTES

The resulting HTML uses CSS to colourize the syntax. Here are the classes that you can define in your stylesheet.
o .s-key - for shell keywords, like if, for, while, do...
o .s-blt - for the builtins commands
o .s-cmd - for the external commands
o .s-arg - for the command arguments
o .s-mta - for shell metacharacters, like |, >, \, &
o .s-quo - for the single () and double (") quotes
o .s-var - for expanded variables: $VARIABLE
o .s-avr - for assigned variables: VARIABLE=value
o .s-val - for shell values (inside quotes)
o .s-cmt - for shell comments
An example stylesheet can be found in examples/shell-syntax.css.

EXAMPLE

Here is an example of generated HTML output. It was generated with the script eg/highlight.pl.

The following shell script



    #!/bin/sh
   
    user="$1"
   
    case "$user" in
      # check if the user is root
      root)
        echo "You are the BOFH."
        ;;
   
      # for normal users, grep throught /etc/passwd
      *)
        passwd=/etc/passwd
        if [ -f $passwd ]; then
            grep "$user" $passwd | awk -F: {print $5}
        else
            echo "No $passwd"
        fi
    esac



will be rendered like this (using the CSS stylesheet eg/shell-syntax.css):

CAVEATS

Syntax::Highlight::Shell relies on Shell::Parser for parsing the shell code and therefore suffers from the same limitations.

SEE ALSO

Shell::Parser

AUTHOR

Se\k:'Aperghis-Tramoni, <sebastien@aperghis.net>

BUGS

Please report any bugs or feature requests to bug-syntax-highlight-shell@rt.cpan.org, or through the web interface at <https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Syntax-Highlight-Shell>. I will be notified, and then you’ll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Copyright 2004 Se\k:'Aperghis-Tramoni, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 SYNTAX::HIGHLIGHT::SHELL (3) 2005-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.