Example-Script.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
  2. <html>
  3. <!-- Created on November 8, 2012 by texi2html 1.82
  4. texi2html was written by:
  5. Lionel Cons <[email protected]> (original author)
  6. Karl Berry <[email protected]>
  7. Olaf Bachmann <[email protected]>
  8. and many others.
  9. Maintained by: Many creative people.
  10. Send bugs and suggestions to <[email protected]>
  11. -->
  12. <head>
  13. <title>avram - a virtual machine code interpreter: 1.8 Example Script</title>
  14. <meta name="description" content="avram - a virtual machine code interpreter: 1.8 Example Script">
  15. <meta name="keywords" content="avram - a virtual machine code interpreter: 1.8 Example Script">
  16. <meta name="resource-type" content="document">
  17. <meta name="distribution" content="global">
  18. <meta name="Generator" content="texi2html 1.82">
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <style type="text/css">
  21. <!--
  22. a.summary-letter {text-decoration: none}
  23. blockquote.smallquotation {font-size: smaller}
  24. pre.display {font-family: serif}
  25. pre.format {font-family: serif}
  26. pre.menu-comment {font-family: serif}
  27. pre.menu-preformatted {font-family: serif}
  28. pre.smalldisplay {font-family: serif; font-size: smaller}
  29. pre.smallexample {font-size: smaller}
  30. pre.smallformat {font-family: serif; font-size: smaller}
  31. pre.smalllisp {font-size: smaller}
  32. span.roman {font-family:serif; font-weight:normal;}
  33. span.sansserif {font-family:sans-serif; font-weight:normal;}
  34. ul.toc {list-style: none}
  35. -->
  36. </style>
  37. </head>
  38. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  39. <a name="Example-Script"></a>
  40. <table cellpadding="1" cellspacing="1" border="0">
  41. <tr><td valign="middle" align="left">[<a href="Security.html#Security" title="Previous section in reading order"> &lt; </a>]</td>
  42. <td valign="middle" align="left">[<a href="Files.html#Files" title="Next section in reading order"> &gt; </a>]</td>
  43. <td valign="middle" align="left"> &nbsp; </td>
  44. <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  45. <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Up section"> Up </a>]</td>
  46. <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Next chapter"> &gt;&gt; </a>]</td>
  47. <td valign="middle" align="left"> &nbsp; </td>
  48. <td valign="middle" align="left"> &nbsp; </td>
  49. <td valign="middle" align="left"> &nbsp; </td>
  50. <td valign="middle" align="left"> &nbsp; </td>
  51. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  52. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  53. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  54. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  55. </tr></table>
  56. <hr size="1">
  57. <a name="Example-Script-1"></a>
  58. <h2 class="section">1.8 Example Script</h2>
  59. <a name="index-script"></a>
  60. <a name="index-shell-script"></a>
  61. <p>It is recommended that the application developer (or the compiler)
  62. package virtual machine code applications as shell scripts with the
  63. <code>avram</code> command line embedded in them. This style relieves the user
  64. of the need to remember the appropriate virtual machine options for
  65. invoking the application, which are always the same for a given
  66. application, or even to be aware of the virtual machine at all.
  67. </p>
  68. <a name="index-cat"></a>
  69. <a name="index-default_002dto_002dstdin-command-line-option-1"></a>
  70. <p>Here is a script that performs a similar operation to the standard
  71. <a name="index-Unix-3"></a>
  72. Unix <code>cat</code> utility.
  73. </p>
  74. <table><tr><td>&nbsp;</td><td><pre class="example">#!/bin/sh
  75. #\
  76. exec avram --force-text-input --default-to-stdin &quot;$0&quot; &quot;$@&quot;
  77. sKYQNTP\
  78. </pre></td></tr></table>
  79. <p>That is, it copies the contents of a file whose
  80. name is given on the command line to standard output, or copies
  81. standard input to standard output if no file name is given. This
  82. script can be marked executable
  83. <a name="index-executable-files"></a>
  84. (with <code>chmod</code>) and run by any user
  85. <a name="index-chmod"></a>
  86. <a name="index-paths-1"></a>
  87. with the directory of the <code>avram</code> executable in his or her
  88. <code>PATH</code> environment variable, even if <code>avram</code> had to be
  89. installed in a non-standard directory such as
  90. <a name="index-non_002dstandard-installation"></a>
  91. &lsquo;<tt>~/bin</tt>&rsquo;.
  92. </p>
  93. <p>The idea for this script is blatantly lifted from the <code>wish</code>
  94. <a name="index-wish"></a>
  95. manpage. The first line of the script invokes a shell to process
  96. what follows. The shell treats the second line as a comment and
  97. ignores it. Based on the third line, the shell invokes <code>avram</code>
  98. with the indicated options, the script itself as the next argument, and
  99. whatever command line parameters were initially supplied by the user
  100. as the remaining arguments. The rest of the script after
  101. that line is never processed by the shell.
  102. </p>
  103. <p>When <code>avram</code> attempts to load the shell script as a virtual
  104. machine code file, which happens as a result of it being executed by
  105. the shell, it treats the first line as a comment and ignores it. It
  106. also treats the second line as a comment, but takes heed of the
  107. trailing backslash, which is interpreted as a comment continuation
  108. character. It therefore also treats the third line as a comment and
  109. ignores it. Starting with the fourth line, it reads the virtual code,
  110. which is in a binary data format encoded with printable characters,
  111. and evaluates it.
  112. </p>
  113. <hr size="1">
  114. <table cellpadding="1" cellspacing="1" border="0">
  115. <tr><td valign="middle" align="left">[<a href="Security.html#Security" title="Previous section in reading order"> &lt; </a>]</td>
  116. <td valign="middle" align="left">[<a href="Files.html#Files" title="Next section in reading order"> &gt; </a>]</td>
  117. <td valign="middle" align="left"> &nbsp; </td>
  118. <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
  119. <td valign="middle" align="left">[<a href="User-Manual.html#User-Manual" title="Up section"> Up </a>]</td>
  120. <td valign="middle" align="left">[<a href="Virtual-Machine-Specification.html#Virtual-Machine-Specification" title="Next chapter"> &gt;&gt; </a>]</td>
  121. <td valign="middle" align="left"> &nbsp; </td>
  122. <td valign="middle" align="left"> &nbsp; </td>
  123. <td valign="middle" align="left"> &nbsp; </td>
  124. <td valign="middle" align="left"> &nbsp; </td>
  125. <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
  126. <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
  127. <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
  128. <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
  129. </tr></table>
  130. <p>
  131. <font size="-1">
  132. This document was generated on <i>November 8, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
  133. </font>
  134. <br>
  135. </p>
  136. </body>
  137. </html>