Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 641ebb3060c35990cc021d8f7aaf9aca > files > 230

octave-doc-5.1.0-7.1.mga7.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Executable Octave Programs (GNU Octave (version 5.1.0))</title>

<meta name="description" content="Executable Octave Programs (GNU Octave (version 5.1.0))">
<meta name="keywords" content="Executable Octave Programs (GNU Octave (version 5.1.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Getting-Started.html#Getting-Started" rel="up" title="Getting Started">
<link href="Comments.html#Comments" rel="next" title="Comments">
<link href="Errors.html#Errors" rel="prev" title="Errors">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<a name="Executable-Octave-Programs"></a>
<div class="header">
<p>
Next: <a href="Comments.html#Comments" accesskey="n" rel="next">Comments</a>, Previous: <a href="Errors.html#Errors" accesskey="p" rel="prev">Errors</a>, Up: <a href="Getting-Started.html#Getting-Started" accesskey="u" rel="up">Getting Started</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Executable-Octave-Programs-1"></a>
<h3 class="section">2.6 Executable Octave Programs</h3>
<a name="index-executable-scripts"></a>
<a name="index-scripts"></a>
<a name="index-batch-processing"></a>
<a name="index-self-contained-programs"></a>
<a name="index-program_002c-self-contained"></a>

<a name="index-_0023_0021-self_002dcontained-script"></a>
<p>Once you have learned Octave, you may want to write self-contained
Octave scripts, using the &lsquo;<samp>#!</samp>&rsquo; script mechanism.  You can do this
on GNU systems and on many Unix systems <a name="DOCF1" href="#FOOT1"><sup>1</sup></a>.
</p>
<p>Self-contained Octave scripts are useful when you want to write a
program which users can invoke without knowing that the program is
written in the Octave language.  Octave scripts are also used for batch
processing of data files.  Once an algorithm has been developed and tested
in the interactive portion of Octave, it can be committed to an executable
script and used again and again on new data files.
</p>
<p>As a trivial example of an executable Octave script, you might create a
text file named <samp>hello</samp>, containing the following lines:
</p>
<div class="example">
<pre class="example">#! <var>octave-interpreter-name</var> -qf
# a sample Octave program
printf (&quot;Hello, world!\n&quot;);
</pre></div>

<p>(where <var>octave-interpreter-name</var> should be replaced with the full
path and name of your Octave binary).  Note that this will only work if
&lsquo;<samp>#!</samp>&rsquo; appears at the very beginning of the file.  After making the
file executable (with the <code>chmod</code> command on Unix systems), you can
simply type:
</p>
<div class="example">
<pre class="example">hello
</pre></div>

<p>at the shell, and the system will arrange to run Octave as if you had
typed:
</p>
<div class="example">
<pre class="example">octave hello
</pre></div>

<p>The line beginning with &lsquo;<samp>#!</samp>&rsquo; lists the full path and filename of an
interpreter to be run, and an optional initial command line argument to
pass to that interpreter.  The operating system then runs the
interpreter with the given argument and the full argument list of the
executed program.  The first argument in the list is the full filename
of the Octave executable.  The rest of the argument list will either be
options to Octave, or data files, or both.  The &lsquo;<samp>-qf</samp>&rsquo; options are
usually specified in stand-alone Octave programs to prevent them from
printing the normal startup message, and to keep them from behaving
differently depending on the contents of a particular user&rsquo;s
<samp>~/.octaverc</samp> file.  See <a href="Invoking-Octave-from-the-Command-Line.html#Invoking-Octave-from-the-Command-Line">Invoking Octave from the Command Line</a>.
</p>
<p>Note that some operating systems may place a limit on the number of
characters that are recognized after &lsquo;<samp>#!</samp>&rsquo;.  Also, the arguments
appearing in a &lsquo;<samp>#!</samp>&rsquo; line are parsed differently by various
shells/systems.  The majority of them group all the arguments together in one
string and pass it to the interpreter as a single argument.  In this case, the
following script:
</p>
<div class="example">
<pre class="example">#! <var>octave-interpreter-name</var> -q -f # comment
</pre></div>

<p>is equivalent to typing at the command line:
</p>
<div class="example">
<pre class="example">octave &quot;-q -f # comment&quot;
</pre></div>

<p>which will produce an error message.  Unfortunately, it is
not possible for Octave to determine whether it has been called from the
command line or from a &lsquo;<samp>#!</samp>&rsquo; script, so some care is needed when using the
&lsquo;<samp>#!</samp>&rsquo; mechanism.
</p>
<p>Note that when Octave is started from an executable script, the built-in
function <code>argv</code> returns a cell array containing the command line
arguments passed to the executable Octave script, not the arguments
passed to the Octave interpreter on the &lsquo;<samp>#!</samp>&rsquo; line of the script.
For example, the following program will reproduce the command line that
was used to execute the script, not &lsquo;<samp>-qf</samp>&rsquo;.
</p>
<div class="example">
<pre class="example">#! /bin/octave -qf
printf (&quot;%s&quot;, program_name ());
arg_list = argv ();
for i = 1:nargin
  printf (&quot; %s&quot;, arg_list{i});
endfor
printf (&quot;\n&quot;);
</pre></div>

<div class="footnote">
<hr>
<h4 class="footnotes-heading">Footnotes</h4>

<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
<p>The &lsquo;<samp>#!</samp>&rsquo;
mechanism works on Unix systems derived from Berkeley Unix, System V
Release 4, and some System V Release 3 systems.</p>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Comments.html#Comments" accesskey="n" rel="next">Comments</a>, Previous: <a href="Errors.html#Errors" accesskey="p" rel="prev">Errors</a>, Up: <a href="Getting-Started.html#Getting-Started" accesskey="u" rel="up">Getting Started</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>