<html lang="en"> <head> <title>Commands - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Functions-and-Scripts.html#Functions-and-Scripts" title="Functions and Scripts"> <link rel="prev" href="Function-Handles-Inline-Functions-and-Anonymous-Functions.html#Function-Handles-Inline-Functions-and-Anonymous-Functions" title="Function Handles Inline Functions and Anonymous Functions"> <link rel="next" href="Organization-of-Functions.html#Organization-of-Functions" title="Organization of Functions"> <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="Commands"></a> <p> Next: <a rel="next" accesskey="n" href="Organization-of-Functions.html#Organization-of-Functions">Organization of Functions</a>, Previous: <a rel="previous" accesskey="p" href="Function-Handles-Inline-Functions-and-Anonymous-Functions.html#Function-Handles-Inline-Functions-and-Anonymous-Functions">Function Handles Inline Functions and Anonymous Functions</a>, Up: <a rel="up" accesskey="u" href="Functions-and-Scripts.html#Functions-and-Scripts">Functions and Scripts</a> <hr> </div> <h3 class="section">11.11 Commands</h3> <p>Commands are a special class of functions that only accept string input arguments. A command can be called as an ordinary function, but it can also be called without the parentheses. For example, <pre class="example"> my_command hello world </pre> <p class="noindent">is equivalent to <pre class="example"> my_command("hello", "world") </pre> <p class="noindent">The general form of a command call is <pre class="example"> <var>cmdname</var> <var>arg1</var> <var>arg2</var> ... </pre> <p class="noindent">which translates directly to <pre class="example"> <var>cmdname</var> ("<var>arg1</var>", "<var>arg2</var>", ...) </pre> <p>Any regular function can be used as a command if it accepts string input arguments. For example: <pre class="example"> toupper lower_case_arg ⇒ ans = LOWER_CASE_ARG </pre> <p>One difficulty of commands occurs when one of the string input arguments is stored in a variable. Because Octave can't tell the difference between a variable name and an ordinary string, it is not possible to pass a variable as input to a command. In such a situation a command must be called as a function. For example: <pre class="example"> strvar = "hello world"; toupper strvar ⇒ ans = STRVAR toupper (strvar) ⇒ ans = HELLO WORLD </pre> </body></html>