123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
- <html>
- <!-- Created on December 10, 2012 by texi2html 1.82
- texi2html was written by:
- Lionel Cons <[email protected]> (original author)
- Karl Berry <[email protected]>
- Olaf Bachmann <[email protected]>
- and many others.
- Maintained by: Many creative people.
- Send bugs and suggestions to <[email protected]>
- -->
- <head>
- <title>avram - a virtual machine code interpreter: 1.8 Example Script</title>
- <meta name="description" content="avram - a virtual machine code interpreter: 1.8 Example Script">
- <meta name="keywords" content="avram - a virtual machine code interpreter: 1.8 Example Script">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="texi2html 1.82">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.smallquotation {font-size: smaller}
- pre.display {font-family: serif}
- pre.format {font-family: serif}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: serif; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: serif; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.roman {font-family:serif; font-weight:normal;}
- span.sansserif {font-family:sans-serif; font-weight:normal;}
- ul.toc {list-style: none}
- -->
- </style>
- </head>
- <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
- <a name="Example-Script"></a>
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Security.html#Security" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Files.html#Files" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <hr size="1">
- <a name="Example-Script-1"></a>
- <h2 class="section">1.8 Example Script</h2>
- <a name="index-script"></a>
- <a name="index-shell-script"></a>
- <p>It is recommended that the application developer (or the compiler)
- package virtual machine code applications as shell scripts with the
- <code>avram</code> command line embedded in them. This style relieves the user
- of the need to remember the appropriate virtual machine options for
- invoking the application, which are always the same for a given
- application, or even to be aware of the virtual machine at all.
- </p>
- <a name="index-cat"></a>
- <a name="index-default_002dto_002dstdin-command-line-option-1"></a>
- <p>Here is a script that performs a similar operation to the standard
- <a name="index-Unix-3"></a>
- Unix <code>cat</code> utility.
- </p>
- <table><tr><td> </td><td><pre class="example">#!/bin/sh
- #\
- exec avram --force-text-input --default-to-stdin "$0" "$@"
- sKYQNTP\
- </pre></td></tr></table>
- <p>That is, it copies the contents of a file whose
- name is given on the command line to standard output, or copies
- standard input to standard output if no file name is given. This
- script can be marked executable
- <a name="index-executable-files"></a>
- (with <code>chmod</code>) and run by any user
- <a name="index-chmod"></a>
- <a name="index-paths-1"></a>
- with the directory of the <code>avram</code> executable in his or her
- <code>PATH</code> environment variable, even if <code>avram</code> had to be
- installed in a non-standard directory such as
- <a name="index-non_002dstandard-installation"></a>
- ‘<tt>~/bin</tt>’.
- </p>
- <p>The idea for this script is blatantly lifted from the <code>wish</code>
- <a name="index-wish"></a>
- manpage. The first line of the script invokes a shell to process
- what follows. The shell treats the second line as a comment and
- ignores it. Based on the third line, the shell invokes <code>avram</code>
- with the indicated options, the script itself as the next argument, and
- whatever command line parameters were initially supplied by the user
- as the remaining arguments. The rest of the script after
- that line is never processed by the shell.
- </p>
- <p>When <code>avram</code> attempts to load the shell script as a virtual
- machine code file, which happens as a result of it being executed by
- the shell, it treats the first line as a comment and ignores it. It
- also treats the second line as a comment, but takes heed of the
- trailing backslash, which is interpreted as a comment continuation
- character. It therefore also treats the third line as a comment and
- ignores it. Starting with the fourth line, it reads the virtual code,
- which is in a binary data format encoded with printable characters,
- and evaluates it.
- </p>
- <hr size="1">
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Security.html#Security" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Files.html#Files" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <p>
- <font size="-1">
- This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
- </font>
- <br>
- </p>
- </body>
- </html>
|