12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <html lang="en">
- <head>
- <title>Example Script - avram - a virtual machine code interpreter</title>
- <meta http-equiv="Content-Type" content="text/html">
- <meta name="description" content="avram - a virtual machine code interpreter">
- <meta name="generator" content="makeinfo 4.13">
- <link title="Top" rel="start" href="index.html#Top">
- <link rel="up" href="User-Manual.html#User-Manual" title="User Manual">
- <link rel="prev" href="Security.html#Security" title="Security">
- <link rel="next" href="Files.html#Files" title="Files">
- <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
- <meta http-equiv="Content-Style-Type" content="text/css">
- <style type="text/css"><!--
- pre.display { font-family:inherit }
- pre.format { font-family:inherit }
- pre.smalldisplay { font-family:inherit; font-size:smaller }
- pre.smallformat { font-family:inherit; font-size:smaller }
- pre.smallexample { font-size:smaller }
- pre.smalllisp { font-size:smaller }
- span.sc { font-variant:small-caps }
- span.roman { font-family:serif; font-weight:normal; }
- span.sansserif { font-family:sans-serif; font-weight:normal; }
- --></style>
- </head>
- <body>
- <div class="node">
- <a name="Example-Script"></a>
- <p>
- Next: <a rel="next" accesskey="n" href="Files.html#Files">Files</a>,
- Previous: <a rel="previous" accesskey="p" href="Security.html#Security">Security</a>,
- Up: <a rel="up" accesskey="u" href="User-Manual.html#User-Manual">User Manual</a>
- <hr>
- </div>
- <h3 class="section">1.8 Example Script</h3>
- <p><a name="index-script-120"></a><a name="index-shell-script-121"></a>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-g_t_0040code_007bcat_007d-122"></a><a name="index-g_t_0040code_007bdefault_002dto_002dstdin_007d-command-line-option-123"></a>Here is a script that performs a similar operation to the standard
- <a name="index-Unix-124"></a>Unix <samp><span class="command">cat</span></samp> utility.
- <pre class="example"> #!/bin/sh
- #\
- exec avram --force-text-input --default-to-stdin "$0" "$@"
- sKYQNTP\
- </pre>
- <p class="noindent">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-125"></a>(with <samp><span class="command">chmod</span></samp>) and run by any user
- <a name="index-g_t_0040code_007bchmod_007d-126"></a><a name="index-paths-127"></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-128"></a><samp><span class="file">~/bin</span></samp>.
- <p>The idea for this script is blatantly lifted from the <samp><span class="command">wish</span></samp>
- <a name="index-g_t_0040code_007bwish_007d-129"></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>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.
- </body></html>
|