Mercurial > hg > octave-lyh
annotate doc/interpreter/basics.txi @ 9032:349616d9c38e
Cleanup top-level documentation menu in octave.texi
@detailmenu is now completely up to date with respect to included .texi files
@sp construct replaced with an equivalent because it produces ugly HTML output
Spellchecked file
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Fri, 20 Mar 2009 10:08:57 -0700 |
parents | d47290508a55 |
children | 57649dcecb55 |
rev | line source |
---|---|
7018 | 1 @c Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2005, 2006, |
8920 | 2 @c 2007, 2008, 2009 John W. Eaton |
7018 | 3 @c |
4 @c This file is part of Octave. | |
5 @c | |
6 @c Octave is free software; you can redistribute it and/or modify it | |
7 @c under the terms of the GNU General Public License as published by the | |
8 @c Free Software Foundation; either version 3 of the License, or (at | |
9 @c your option) any later version. | |
10 @c | |
11 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
12 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 @c for more details. | |
15 @c | |
16 @c You should have received a copy of the GNU General Public License | |
17 @c along with Octave; see the file COPYING. If not, see | |
18 @c <http://www.gnu.org/licenses/>. | |
3294 | 19 |
4167 | 20 @node Getting Started |
3294 | 21 @chapter Getting Started |
22 | |
23 This chapter explains some of Octave's basic features, including how to | |
24 start an Octave session, get help at the command prompt, edit the | |
25 command line, and write Octave programs that can be executed as commands | |
26 from your shell. | |
27 | |
28 @menu | |
6620 | 29 * Invoking Octave from the Command Line:: |
3294 | 30 * Quitting Octave:: |
31 * Getting Help:: | |
32 * Command Line Editing:: | |
33 * Errors:: | |
34 * Executable Octave Programs:: | |
35 * Comments:: | |
36 @end menu | |
37 | |
6620 | 38 @node Invoking Octave from the Command Line |
39 @section Invoking Octave from the Command Line | |
3294 | 40 |
41 Normally, Octave is used interactively by running the program | |
42 @samp{octave} without any arguments. Once started, Octave reads | |
43 commands from the terminal until you tell it to exit. | |
44 | |
45 You can also specify the name of a file on the command line, and Octave | |
46 will read and execute the commands from the named file and then exit | |
47 when it is finished. | |
48 | |
49 You can further control how Octave starts by using the command-line | |
50 options described in the next section, and Octave itself can remind you | |
51 of the options available. Type @samp{octave --help} to display all | |
52 available options and briefly describe their use (@samp{octave -h} is a | |
53 shorter equivalent). | |
54 | |
55 @menu | |
56 * Command Line Options:: | |
57 * Startup Files:: | |
58 @end menu | |
59 | |
4167 | 60 @node Command Line Options |
3294 | 61 @subsection Command Line Options |
62 @cindex Octave command options | |
63 @cindex command options | |
64 @cindex options, Octave command | |
65 | |
66 Here is a complete list of all the command line options that Octave | |
67 accepts. | |
68 | |
6620 | 69 |
3294 | 70 @table @code |
71 @item --debug | |
72 @itemx -d | |
73 @cindex @code{--debug} | |
74 @cindex @code{-d} | |
75 Enter parser debugging mode. Using this option will cause Octave's | |
76 parser to print a lot of information about the commands it reads, and is | |
77 probably only useful if you are actually trying to debug the parser. | |
78 | |
8923
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
79 @item --doc-cache-file |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
80 @cindex @code{--doc-cache-file} @var{filename} |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
81 Specify the name of the doc cache file to use. The value of @var{filename} |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
82 specified on the command line will override any value of |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
83 @code{OCTAVE_DOC_CACHE_FILE} found in the environment, but not any commands |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
84 in the system or user startup files that use the @code{doc_file_cache} |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
85 function. |
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
86 |
3294 | 87 @item --echo-commands |
88 @itemx -x | |
89 @cindex @code{--echo-commands} | |
90 @cindex @code{-x} | |
91 Echo commands as they are executed. | |
92 | |
5190 | 93 @item --eval @var{code} |
94 Evaluate @var{code} and exit when done unless @code{--persist} is also | |
95 specified. | |
96 | |
3294 | 97 @item --exec-path @var{path} |
98 @cindex @code{--exec-path @var{path}} | |
99 Specify the path to search for programs to run. The value of @var{path} | |
100 specified on the command line will override any value of | |
101 @code{OCTAVE_EXEC_PATH} found in the environment, but not any commands | |
102 in the system or user startup files that set the built-in variable | |
103 @code{EXEC_PATH}. | |
104 | |
105 @item --help | |
106 @itemx -h | |
107 @itemx -? | |
108 @cindex @code{--help} | |
109 @cindex @code{-h} | |
110 @cindex @code{-?} | |
111 Print short help message and exit. | |
112 | |
6620 | 113 @item --image-path @var{path} |
114 @cindex @code{--image-path @var{path}} | |
115 Specify the path to search for images. The value of @var{path} | |
116 specified on the command line will set the value of | |
117 @code{IMAGE_PATH} found in the environment. | |
118 | |
3294 | 119 @item --info-file @var{filename} |
120 @cindex @code{--info-file @var{filename}} | |
121 Specify the name of the info file to use. The value of @var{filename} | |
122 specified on the command line will override any value of | |
123 @code{OCTAVE_INFO_FILE} found in the environment, but not any commands | |
6653 | 124 in the system or user startup files that use the @code{info_file} |
6477 | 125 function. |
3294 | 126 |
127 @item --info-program @var{program} | |
128 @cindex @code{--info-program @var{program}} | |
129 Specify the name of the info program to use. The value of @var{program} | |
130 specified on the command line will override any value of | |
131 @code{OCTAVE_INFO_PROGRAM} found in the environment, but not any | |
6477 | 132 commands in the system or user startup files that use the |
133 @code{info_program} function. | |
3294 | 134 |
135 @item --interactive | |
136 @itemx -i | |
137 @cindex @code{--interactive} | |
138 @cindex @code{-i} | |
139 Force interactive behavior. This can be useful for running Octave via a | |
140 remote shell command or inside an Emacs shell buffer. For another way | |
9032
349616d9c38e
Cleanup top-level documentation menu in octave.texi
Rik <rdrider0-list@yahoo.com>
parents:
8923
diff
changeset
|
141 to run Octave within Emacs, see @ref{Emacs Octave Support}. |
3294 | 142 |
3428 | 143 @item --no-history |
144 @itemx -H | |
145 Disable command-line history. | |
146 | |
3294 | 147 @item --no-init-file |
148 @cindex @code{--no-init-file} | |
149 Don't read the @file{~/.octaverc} or @file{.octaverc} files. | |
150 | |
151 @item --no-line-editing | |
152 @cindex @code{--no-line-editing} | |
153 Disable command-line editing. | |
154 | |
155 @item --no-site-file | |
156 @cindex @code{--no-site-file} | |
157 Don't read the site-wide @file{octaverc} file. | |
158 | |
159 @item --norc | |
160 @itemx -f | |
161 @cindex @code{--norc} | |
162 @cindex @code{-f} | |
163 Don't read any of the system or user initialization files at startup. | |
164 This is equivalent to using both of the options @code{--no-init-file} | |
165 and @code{--no-site-file}. | |
166 | |
167 @item --path @var{path} | |
168 @itemx -p @var{path} | |
169 @cindex @code{--path @var{path}} | |
170 @cindex @code{-p @var{path}} | |
171 Specify the path to search for function files. The value of @var{path} | |
172 specified on the command line will override any value of | |
173 @code{OCTAVE_PATH} found in the environment, but not any commands in the | |
6643 | 174 system or user startup files that set the internal load path through one |
175 of the path functions. | |
3294 | 176 |
5190 | 177 @item --persist |
178 Go to interactive mode after @code{--eval} or reading from a file | |
179 named on the command line. | |
180 | |
3294 | 181 @item --silent |
182 @itemx --quiet | |
183 @itemx -q | |
184 @cindex @code{--silent} | |
185 @cindex @code{--quiet} | |
186 @cindex @code{-q} | |
187 Don't print the usual greeting and version message at startup. | |
188 | |
189 @item --traditional | |
190 @itemx --braindead | |
191 @cindex @code{--traditional} | |
192 @cindex @code{--braindead} | |
6556 | 193 For compatibility with @sc{Matlab}, set initial values for |
194 user-preferences to the following values | |
3294 | 195 |
196 @example | |
4455 | 197 @group |
7031 | 198 PS1 = ">> " |
199 PS2 = "" | |
200 beep_on_error = true | |
201 crash_dumps_octave_core = false | |
202 default_save_options = "-mat-binary" | |
203 fixed_point_format = true | |
204 history_timestamp_format_string | |
205 = "%%-- %D %I:%M %p --%%" | |
206 page_screen_output = false | |
207 print_empty_dimensions = false | |
6556 | 208 @end group |
209 @end example | |
210 | |
211 @noindent | |
212 and disable the following warnings | |
213 @example | |
214 @group | |
7031 | 215 Octave:fopen-file-in-path |
216 Octave:function-name-clash | |
217 Octave:load-file-in-path | |
4455 | 218 @end group |
3294 | 219 @end example |
220 | |
221 @item --verbose | |
222 @itemx -V | |
223 @cindex @code{--verbose} | |
224 @cindex @code{-V} | |
225 Turn on verbose output. | |
226 | |
227 @item --version | |
228 @itemx -v | |
229 @cindex @code{--version} | |
230 @cindex @code{-v} | |
231 Print the program version number and exit. | |
232 | |
233 @item @var{file} | |
5190 | 234 Execute commands from @var{file}. Exit when done unless |
235 @code{--persist} is also specified. | |
3294 | 236 @end table |
237 | |
238 Octave also includes several built-in variables that contain information | |
239 about the command line, including the number of arguments and all of the | |
240 options. | |
241 | |
3332 | 242 @DOCSTRING(argv) |
3294 | 243 |
6550 | 244 @DOCSTRING(program_name) |
245 | |
3332 | 246 @DOCSTRING(program_invocation_name) |
3294 | 247 |
6479 | 248 Here is an example of using these functions to reproduce Octave's |
3294 | 249 command line. |
250 | |
251 @example | |
6479 | 252 printf ("%s", program_name ()); |
6620 | 253 arg_list = argv (); |
3294 | 254 for i = 1:nargin |
6479 | 255 printf (" %s", arg_list@{i@}); |
3294 | 256 endfor |
257 printf ("\n"); | |
258 @end example | |
259 | |
260 @noindent | |
3402 | 261 @xref{Index Expressions}, for an explanation of how to properly index |
262 arrays of strings and substrings in Octave, and @xref{Defining Functions}, | |
3294 | 263 for information about the variable @code{nargin}. |
264 | |
4167 | 265 @node Startup Files |
3294 | 266 @subsection Startup Files |
267 @cindex initialization | |
268 @cindex startup | |
269 | |
6620 | 270 When Octave starts, it looks for commands to execute from the files in |
271 the following list. These files may contain any valid Octave commands, | |
272 including function definitions. | |
3294 | 273 |
274 @cindex startup files | |
275 | |
276 @table @code | |
277 @item @var{octave-home}/share/octave/site/m/startup/octaverc | |
278 Where @var{octave-home} is the directory in which all of Octave is | |
279 installed (the default is @file{@value{OCTAVEHOME}}). This file is | |
280 provided so that changes to the default Octave environment can be made | |
281 globally for all users at your site for all versions of Octave you have | |
282 installed. Some care should be taken when making changes to this file, | |
283 since all users of Octave at your site will be affected. | |
284 | |
285 @item @var{octave-home}/share/octave/@var{version}/m/startup/octaverc | |
286 Where @var{octave-home} is the directory in which all of Octave is | |
287 installed (the default is @file{@value{OCTAVEHOME}}), and @var{version} | |
288 is the version number of Octave. This file is provided so that changes | |
289 to the default Octave environment can be made globally for all users for | |
290 a particular version of Octave. Some care should be taken when making | |
291 changes to this file, since all users of Octave at your site will be | |
292 affected. | |
293 | |
294 @item ~/.octaverc | |
295 @cindex @code{~/.octaverc} | |
296 This file is normally used to make personal changes to the default | |
297 Octave environment. | |
298 | |
299 @item .octaverc | |
300 @cindex @code{.octaverc} | |
301 This file can be used to make changes to the default Octave environment | |
302 for a particular project. Octave searches for this file in the current | |
303 directory after it reads @file{~/.octaverc}. Any use of the @code{cd} | |
304 command in the @file{~/.octaverc} file will affect the directory that | |
305 Octave searches for the file @file{.octaverc}. | |
306 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8015
diff
changeset
|
307 If you start Octave in your home directory, commands from the file |
3294 | 308 @file{~/.octaverc} will only be executed once. |
309 @end table | |
310 | |
311 A message will be displayed as each of the startup files is read if you | |
312 invoke Octave with the @code{--verbose} option but without the | |
313 @code{--silent} option. | |
314 | |
4167 | 315 @node Quitting Octave |
3294 | 316 @section Quitting Octave |
317 @cindex exiting octave | |
318 @cindex quitting octave | |
319 | |
3332 | 320 @DOCSTRING(quit) |
3294 | 321 |
3332 | 322 @DOCSTRING(atexit) |
3294 | 323 |
4167 | 324 @node Getting Help |
3294 | 325 @section Commands for Getting Help |
326 @cindex on-line help | |
327 @cindex help, on-line | |
328 | |
329 The entire text of this manual is available from the Octave prompt | |
6620 | 330 via the command @kbd{doc}. In addition, the documentation for |
3294 | 331 individual user-written functions and variables is also available via |
332 the @kbd{help} command. This section describes the commands used for | |
333 reading the manual and the documentation strings for user-supplied | |
334 functions and variables. @xref{Function Files}, for more information | |
335 about how to document the functions you write. | |
336 | |
3332 | 337 @DOCSTRING(help) |
3294 | 338 |
6549 | 339 @DOCSTRING(doc) |
340 | |
341 @DOCSTRING(lookfor) | |
342 | |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
343 To see what is new in the current release of Octave, use the @code{news} |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
344 function. |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
345 |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
346 @DOCSTRING(news) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
347 |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
348 @DOCSTRING(info) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
349 |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
350 @DOCSTRING(warranty) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
351 |
6620 | 352 The following function can be used to change which programs are used |
353 for displaying the documentation, and where the documentation can be | |
354 found. | |
3294 | 355 |
6477 | 356 @DOCSTRING(info_file) |
3294 | 357 |
6477 | 358 @DOCSTRING(info_program) |
3294 | 359 |
6477 | 360 @DOCSTRING(makeinfo_program) |
3686 | 361 |
3332 | 362 @DOCSTRING(suppress_verbose_help_message) |
3294 | 363 |
4167 | 364 @node Command Line Editing |
3294 | 365 @section Command Line Editing |
366 @cindex command-line editing | |
367 @cindex editing the command line | |
368 | |
369 Octave uses the GNU readline library to provide an extensive set of | |
370 command-line editing and history features. Only the most common | |
371 features are described in this manual. Please see The GNU Readline | |
372 Library manual for more information. | |
373 | |
374 To insert printing characters (letters, digits, symbols, etc.), simply | |
375 type the character. Octave will insert the character at the cursor and | |
376 advance the cursor forward. | |
377 | |
378 Many of the command-line editing functions operate using control | |
379 characters. For example, the character @kbd{Control-a} moves the cursor | |
380 to the beginning of the line. To type @kbd{C-a}, hold down @key{CTRL} | |
381 and then press @key{a}. In the following sections, control characters | |
382 such as @kbd{Control-a} are written as @kbd{C-a}. | |
383 | |
384 Another set of command-line editing functions use Meta characters. On | |
385 some terminals, you type @kbd{M-u} by holding down @key{META} and | |
386 pressing @key{u}. If your terminal does not have a @key{META} key, you | |
7001 | 387 can still type Meta characters using two-character sequences starting |
3294 | 388 with @kbd{ESC}. Thus, to enter @kbd{M-u}, you could type |
389 @key{ESC}@key{u}. The @kbd{ESC} character sequences are also allowed on | |
390 terminals with real Meta keys. In the following sections, Meta | |
391 characters such as @kbd{Meta-u} are written as @kbd{M-u}. | |
392 | |
3428 | 393 |
3294 | 394 @menu |
395 * Cursor Motion:: | |
396 * Killing and Yanking:: | |
397 * Commands For Text:: | |
398 * Commands For Completion:: | |
399 * Commands For History:: | |
3439 | 400 * Customizing readline:: |
3294 | 401 * Customizing the Prompt:: |
402 * Diary and Echo Commands:: | |
403 @end menu | |
404 | |
4167 | 405 @node Cursor Motion |
3294 | 406 @subsection Cursor Motion |
407 | |
408 The following commands allow you to position the cursor. | |
409 | |
410 @table @kbd | |
411 @item C-b | |
412 Move back one character. | |
413 | |
414 @item C-f | |
415 Move forward one character. | |
416 | |
417 @item @key{DEL} | |
418 Delete the character to the left of the cursor. | |
419 | |
420 @item C-d | |
421 Delete the character underneath the cursor. | |
422 | |
423 @item M-f | |
424 Move forward a word. | |
425 | |
426 @item M-b | |
427 Move backward a word. | |
428 | |
429 @item C-a | |
430 Move to the start of the line. | |
431 | |
432 @item C-e | |
433 Move to the end of the line. | |
434 | |
435 @item C-l | |
436 Clear the screen, reprinting the current line at the top. | |
437 | |
438 @item C-_ | |
439 @itemx C-/ | |
440 Undo the last thing that you did. You can undo all the way back to an | |
441 empty line. | |
442 | |
443 @item M-r | |
444 Undo all changes made to this line. This is like typing the `undo' | |
445 command enough times to get back to the beginning. | |
446 @end table | |
447 | |
448 The above table describes the most basic possible keystrokes that you need | |
449 in order to do editing of the input line. On most terminals, you can | |
450 also use the arrow keys in place of @kbd{C-f} and @kbd{C-b} to move | |
451 forward and backward. | |
452 | |
453 Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves | |
454 forward a word. It is a loose convention that control keystrokes | |
455 operate on characters while meta keystrokes operate on words. | |
456 | |
457 @cindex clearing the screen | |
458 | |
6620 | 459 The function @code{clc} will allow you to clear the screen from within |
460 Octave programs. | |
461 | |
462 @ifinfo | |
3332 | 463 @DOCSTRING(clc) |
6620 | 464 @end ifinfo |
3294 | 465 |
4167 | 466 @node Killing and Yanking |
3294 | 467 @subsection Killing and Yanking |
468 | |
469 @dfn{Killing} text means to delete the text from the line, but to save | |
470 it away for later use, usually by @dfn{yanking} it back into the line. | |
471 If the description for a command says that it `kills' text, then you can | |
472 be sure that you can get the text back in a different (or the same) | |
473 place later. | |
474 | |
475 Here is the list of commands for killing text. | |
476 | |
477 @table @kbd | |
478 @item C-k | |
479 Kill the text from the current cursor position to the end of the line. | |
480 | |
481 @item M-d | |
482 Kill from the cursor to the end of the current word, or if between | |
483 words, to the end of the next word. | |
484 | |
485 @item M-@key{DEL} | |
486 Kill from the cursor to the start of the previous word, or if between | |
487 words, to the start of the previous word. | |
488 | |
489 @item C-w | |
490 Kill from the cursor to the previous whitespace. This is different than | |
491 @kbd{M-@key{DEL}} because the word boundaries differ. | |
492 @end table | |
493 | |
494 And, here is how to @dfn{yank} the text back into the line. Yanking | |
495 means to copy the most-recently-killed text from the kill buffer. | |
496 | |
497 @table @kbd | |
498 @item C-y | |
499 Yank the most recently killed text back into the buffer at the cursor. | |
500 | |
501 @item M-y | |
502 Rotate the kill-ring, and yank the new top. You can only do this if | |
503 the prior command is @kbd{C-y} or @kbd{M-y}. | |
504 @end table | |
505 | |
506 When you use a kill command, the text is saved in a @dfn{kill-ring}. | |
507 Any number of consecutive kills save all of the killed text together, so | |
508 that when you yank it back, you get it in one clean sweep. The kill | |
509 ring is not line specific; the text that you killed on a previously | |
510 typed line is available to be yanked back later, when you are typing | |
511 another line. | |
512 | |
4167 | 513 @node Commands For Text |
3294 | 514 @subsection Commands For Changing Text |
515 | |
516 The following commands can be used for entering characters that would | |
517 otherwise have a special meaning (e.g., @kbd{TAB}, @kbd{C-q}, etc.), or | |
518 for quickly correcting typing mistakes. | |
519 | |
520 @table @kbd | |
521 @item C-q | |
522 @itemx C-v | |
523 Add the next character that you type to the line verbatim. This is | |
524 how to insert things like @kbd{C-q} for example. | |
525 | |
526 @item M-@key{TAB} | |
527 Insert a tab character. | |
528 | |
529 @item C-t | |
530 Drag the character before the cursor forward over the character at the | |
531 cursor, also moving the cursor forward. If the cursor is at the end of | |
532 the line, then transpose the two characters before it. | |
533 | |
534 @item M-t | |
535 Drag the word behind the cursor past the word in front of the cursor | |
536 moving the cursor over that word as well. | |
537 | |
538 @item M-u | |
539 Uppercase the characters following the cursor to the end of the current | |
540 (or following) word, moving the cursor to the end of the word. | |
541 | |
542 @item M-l | |
6620 | 543 Lowercase the characters following the cursor to the end of the current |
3294 | 544 (or following) word, moving the cursor to the end of the word. |
545 | |
546 @item M-c | |
547 Uppercase the character following the cursor (or the beginning of the | |
548 next word if the cursor is between words), moving the cursor to the end | |
549 of the word. | |
550 @end table | |
551 | |
4167 | 552 @node Commands For Completion |
3294 | 553 @subsection Letting Readline Type For You |
554 @cindex command completion | |
555 | |
556 The following commands allow Octave to complete command and variable | |
557 names for you. | |
558 | |
559 @table @kbd | |
560 @item @key{TAB} | |
561 Attempt to do completion on the text before the cursor. Octave can | |
562 complete the names of commands and variables. | |
563 | |
564 @item M-? | |
565 List the possible completions of the text before the cursor. | |
566 @end table | |
567 | |
3332 | 568 @DOCSTRING(completion_append_char) |
3294 | 569 |
3332 | 570 @DOCSTRING(completion_matches) |
3294 | 571 |
4167 | 572 @node Commands For History |
3294 | 573 @subsection Commands For Manipulating The History |
574 @cindex command history | |
575 @cindex input history | |
576 @cindex history of commands | |
577 | |
578 Octave normally keeps track of the commands you type so that you can | |
579 recall previous commands to edit or execute them again. When you exit | |
580 Octave, the most recent commands you have typed, up to the number | |
581 specified by the variable @code{history_size}, are saved in a file. | |
582 When Octave starts, it loads an initial list of commands from the file | |
583 named by the variable @code{history_file}. | |
584 | |
585 Here are the commands for simple browsing and searching the history | |
586 list. | |
587 | |
588 @table @kbd | |
589 @item @key{LFD} | |
590 @itemx @key{RET} | |
591 Accept the line regardless of where the cursor is. If this line is | |
592 non-empty, add it to the history list. If this line was a history | |
593 line, then restore the history line to its original state. | |
594 | |
595 @item C-p | |
596 Move `up' through the history list. | |
597 | |
598 @item C-n | |
599 Move `down' through the history list. | |
600 | |
601 @item M-< | |
602 Move to the first line in the history. | |
603 | |
604 @item M-> | |
605 Move to the end of the input history, i.e., the line you are entering! | |
606 | |
607 @item C-r | |
608 Search backward starting at the current line and moving `up' through | |
609 the history as necessary. This is an incremental search. | |
610 | |
611 @item C-s | |
612 Search forward starting at the current line and moving `down' through | |
613 the history as necessary. | |
614 @end table | |
615 | |
616 On most terminals, you can also use the arrow keys in place of @kbd{C-p} | |
617 and @kbd{C-n} to move through the history list. | |
618 | |
619 In addition to the keyboard commands for moving through the history | |
620 list, Octave provides three functions for viewing, editing, and | |
621 re-running chunks of commands from the history list. | |
622 | |
3332 | 623 @DOCSTRING(history) |
3294 | 624 |
3332 | 625 @DOCSTRING(edit_history) |
3294 | 626 |
3332 | 627 @DOCSTRING(run_history) |
3294 | 628 |
6620 | 629 Octave also allows you customize the details of how and where the history |
630 is saved. | |
3294 | 631 |
3332 | 632 @DOCSTRING(history_file) |
3294 | 633 |
3332 | 634 @DOCSTRING(history_size) |
3294 | 635 |
3332 | 636 @DOCSTRING(saving_history) |
3294 | 637 |
6550 | 638 @DOCSTRING(history_timestamp_format_string) |
639 | |
6620 | 640 @DOCSTRING(EDITOR) |
641 | |
4167 | 642 @node Customizing readline |
3428 | 643 @subsection Customizing @code{readline} |
644 | |
6620 | 645 As mentioned earlier Octave uses the GNU readline library for |
646 command-line editing and history features. It is possible to | |
647 customize how readline works through a configuration file. | |
648 | |
5775 | 649 @c FIXME -- need a brief description of the ~/.inputrc file here. |
3428 | 650 |
3439 | 651 @DOCSTRING(read_readline_init_file) |
3428 | 652 |
8817
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
653 @DOCSTRING(re_read_readline_init_file) |
03b7f618ab3d
include docstrings for new functions in the manual
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
654 |
4167 | 655 @node Customizing the Prompt |
3294 | 656 @subsection Customizing the Prompt |
657 @cindex prompt customization | |
658 @cindex customizing the prompt | |
659 | |
660 The following variables are available for customizing the appearance of | |
661 the command-line prompts. Octave allows the prompt to be customized by | |
662 inserting a number of backslash-escaped special characters that are | |
663 decoded as follows: | |
664 | |
665 @table @samp | |
666 @item \t | |
667 The time. | |
668 | |
669 @item \d | |
670 The date. | |
671 | |
672 @item \n | |
673 Begins a new line by printing the equivalent of a carriage return | |
674 followed by a line feed. | |
675 | |
676 @item \s | |
677 The name of the program (usually just @samp{octave}). | |
678 | |
679 @item \w | |
680 The current working directory. | |
681 | |
682 @item \W | |
683 The basename of the current working directory. | |
684 | |
685 @item \u | |
686 The username of the current user. | |
687 | |
688 @item \h | |
689 The hostname, up to the first `.'. | |
690 | |
691 @item \H | |
692 The hostname. | |
693 | |
694 @item \# | |
695 The command number of this command, counting from when Octave starts. | |
696 | |
697 @item \! | |
698 The history number of this command. This differs from @samp{\#} by the | |
699 number of commands in the history list when Octave starts. | |
700 | |
701 @item \$ | |
702 If the effective UID is 0, a @samp{#}, otherwise a @samp{$}. | |
703 | |
704 @item \nnn | |
705 The character whose character code in octal is @var{nnn}. | |
706 | |
707 @item \\ | |
708 A backslash. | |
709 @end table | |
710 | |
3332 | 711 @DOCSTRING(PS1) |
3294 | 712 |
3332 | 713 @DOCSTRING(PS2) |
3294 | 714 |
3332 | 715 @DOCSTRING(PS4) |
3294 | 716 |
4167 | 717 @node Diary and Echo Commands |
3294 | 718 @subsection Diary and Echo Commands |
719 @cindex diary of commands and output | |
6939 | 720 @cindex command and output logs |
3294 | 721 @cindex logging commands and output |
722 @cindex echoing executing commands | |
723 @cindex command echoing | |
724 | |
725 Octave's diary feature allows you to keep a log of all or part of an | |
726 interactive session by recording the input you type and the output that | |
727 Octave produces in a separate file. | |
728 | |
3332 | 729 @DOCSTRING(diary) |
3294 | 730 |
731 Sometimes it is useful to see the commands in a function or script as | |
732 they are being evaluated. This can be especially helpful for debugging | |
733 some kinds of problems. | |
734 | |
3332 | 735 @DOCSTRING(echo) |
3294 | 736 |
3332 | 737 @DOCSTRING(echo_executing_commands) |
3294 | 738 |
4167 | 739 @node Errors |
3294 | 740 @section How Octave Reports Errors |
741 @cindex error messages | |
742 @cindex messages, error | |
743 | |
744 Octave reports two kinds of errors for invalid programs. | |
745 | |
746 A @dfn{parse error} occurs if Octave cannot understand something you | |
747 have typed. For example, if you misspell a keyword, | |
748 | |
749 @example | |
750 octave:13> functon y = f (x) y = x^2; endfunction | |
751 @end example | |
752 | |
753 @noindent | |
754 Octave will respond immediately with a message like this: | |
755 | |
756 @example | |
757 parse error: | |
758 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
759 syntax error |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
760 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
761 >>> functon y = f (x) y = x^2; endfunction |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
762 ^ |
3294 | 763 @end example |
764 | |
765 @noindent | |
766 For most parse errors, Octave uses a caret (@samp{^}) to mark the point | |
767 on the line where it was unable to make sense of your input. In this | |
768 case, Octave generated an error message because the keyword | |
769 @code{function} was misspelled. Instead of seeing @samp{function f}, | |
770 Octave saw two consecutive variable names, which is invalid in this | |
771 context. It marked the error at @code{y} because the first name by | |
772 itself was accepted as valid input. | |
773 | |
774 Another class of error message occurs at evaluation time. These | |
775 errors are called @dfn{run-time errors}, or sometimes | |
776 @dfn{evaluation errors} because they occur when your program is being | |
777 @dfn{run}, or @dfn{evaluated}. For example, if after correcting the | |
778 mistake in the previous function definition, you type | |
779 | |
780 @example | |
781 octave:13> f () | |
782 @end example | |
783 | |
784 @noindent | |
785 Octave will respond with | |
786 | |
7031 | 787 @c Using 'smallexample' to make text fit on page when creating smallbook. |
788 @smallexample | |
3294 | 789 @group |
790 error: `x' undefined near line 1 column 24 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
791 error: called from: |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
792 error: f at line 1, column 22 |
3294 | 793 @end group |
7031 | 794 @end smallexample |
3294 | 795 |
6620 | 796 @noindent |
3294 | 797 This error message has several parts, and gives you quite a bit of |
798 information to help you locate the source of the error. The messages | |
799 are generated from the point of the innermost error, and provide a | |
800 traceback of enclosing expressions and function calls. | |
801 | |
802 In the example above, the first line indicates that a variable named | |
803 @samp{x} was found to be undefined near line 1 and column 24 of some | |
804 function or expression. For errors occurring within functions, lines | |
805 are counted from the beginning of the file containing the function | |
806 definition. For errors occurring at the top level, the line number | |
807 indicates the input line number, which is usually displayed in the | |
808 prompt string. | |
809 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
810 The second and third lines in the error message indicates that the error occurred |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
811 within the function @code{f}. If the function @code{f} had been called from |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
812 another function, for example, @code{g}, the list of errors would have ended with |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
813 one more line: |
3294 | 814 |
815 @example | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
816 error: g at line 1, column 17 |
3294 | 817 @end example |
818 | |
819 These lists of function calls usually make it fairly easy to trace the | |
820 path your program took before the error occurred, and to correct the | |
821 error before trying again. | |
822 | |
4167 | 823 @node Executable Octave Programs |
3294 | 824 @section Executable Octave Programs |
825 @cindex executable scripts | |
826 @cindex scripts | |
827 @cindex self contained programs | |
828 @cindex program, self contained | |
829 @cindex @samp{#!} | |
830 | |
831 Once you have learned Octave, you may want to write self-contained | |
832 Octave scripts, using the @samp{#!} script mechanism. You can do this | |
833 on GNU systems and on many Unix systems @footnote{The @samp{#!} | |
834 mechanism works on Unix systems derived from Berkeley Unix, System V | |
6481 | 835 Release 4, and some System V Release 3 systems.}. |
836 | |
837 Self-contained Octave scripts are useful when you want to write a | |
838 program which users can invoke without knowing that the program is | |
839 written in the Octave language. | |
3294 | 840 |
841 For example, you could create a text file named @file{hello}, containing | |
842 the following lines: | |
843 | |
844 @example | |
845 @group | |
846 #! @var{octave-interpreter-name} -qf | |
847 # a sample Octave program | |
848 printf ("Hello, world!\n"); | |
849 @end group | |
850 @end example | |
851 | |
852 @noindent | |
853 (where @var{octave-interpreter-name} should be replaced with the full | |
6481 | 854 file name for your Octave binary). Note that this will only work if |
855 @samp{#!} appears at the very beginning of the file. After making this | |
856 file executable | |
3294 | 857 (with the @code{chmod} command), you can simply type: |
858 | |
859 @example | |
860 hello | |
861 @end example | |
862 | |
863 @noindent | |
864 at the shell, and the system will arrange to run Octave as if you had | |
865 typed: | |
866 | |
867 @example | |
868 octave hello | |
869 @end example | |
870 | |
871 The line beginning with @samp{#!} lists the full file name of an | |
872 interpreter to be run, and an optional initial command line argument to | |
873 pass to that interpreter. The operating system then runs the | |
874 interpreter with the given argument and the full argument list of the | |
875 executed program. The first argument in the list is the full file name | |
876 of the Octave program. The rest of the argument list will either be | |
877 options to Octave, or data files, or both. The @samp{-qf} option is | |
878 usually specified in stand-alone Octave programs to prevent them from | |
879 printing the normal startup message, and to keep them from behaving | |
880 differently depending on the contents of a particular user's | |
6620 | 881 @file{~/.octaverc} file. @xref{Invoking Octave from the Command Line}. |
6481 | 882 |
883 Note that some operating systems may place a limit on the number of | |
884 characters that are recognized after @samp{#!}. Also, the various | |
885 shells/systems parse differently the arguments appearing in a @samp{#!} | |
886 line. The majority of them group together all the arguments in a string | |
6939 | 887 and pass it to the interpreter as a single argument. In this case, the |
6481 | 888 following script: |
889 | |
890 @example | |
891 @group | |
892 #! @var{octave-interpreter-name} -q -f # comment | |
893 @end group | |
894 @end example | |
895 | |
896 @noindent | |
897 is equivalent to type at the command line: | |
3294 | 898 |
6481 | 899 @example |
900 @group | |
901 octave "-q -f # comment" | |
902 @end group | |
903 @end example | |
3294 | 904 |
6481 | 905 @noindent |
906 which would obviously produce an error message. Unfortunately, it is | |
907 impossible for Octave to know whether it has been called from the command | |
908 line or from a @samp{#!} script, so some care is needed when using the | |
909 @samp{#!} mechanism. | |
910 | |
911 Note that when Octave is started from an executable script, the built-in | |
912 function @code{argv} returns a cell array containing the command line | |
913 arguments passed to an executable Octave script, not the arguments | |
914 passed to the Octave interpreter on the @samp{#!} line of the script. | |
915 For example, the following program will reproduce the command line that | |
916 is used to execute script, not @samp{-qf}. | |
3294 | 917 |
918 @example | |
919 @group | |
920 #! /bin/octave -qf | |
6479 | 921 printf ("%s", program_name ()); |
6620 | 922 arg_list = argv (); |
3294 | 923 for i = 1:nargin |
6479 | 924 printf (" %s", arg_list@{i@}); |
3294 | 925 endfor |
926 printf ("\n"); | |
927 @end group | |
928 @end example | |
929 | |
4167 | 930 @node Comments |
3294 | 931 @section Comments in Octave Programs |
932 @cindex @samp{#} | |
933 @cindex @samp{%} | |
934 @cindex comments | |
935 @cindex use of comments | |
936 @cindex documenting Octave programs | |
937 @cindex programs | |
938 | |
939 A @dfn{comment} is some text that is included in a program for the sake | |
940 of human readers, and that is not really part of the program. Comments | |
941 can explain what the program does, and how it works. Nearly all | |
942 programming languages have provisions for comments, because programs are | |
943 typically hard to understand without them. | |
944 | |
945 In the Octave language, a comment starts with either the sharp sign | |
946 character, @samp{#}, or the percent symbol @samp{%} and continues to the | |
947 end of the line. The Octave interpreter ignores the rest of a | |
948 line following a sharp sign or percent symbol. For example, we could | |
949 have put the following into the function @code{f}: | |
950 | |
951 @example | |
952 @group | |
953 function xdot = f (x, t) | |
954 | |
955 # usage: f (x, t) | |
956 # | |
957 # This function defines the right hand | |
958 # side functions for a set of nonlinear | |
959 # differential equations. | |
960 | |
961 r = 0.25; | |
962 @dots{} | |
963 endfunction | |
964 @end group | |
965 @end example | |
966 | |
967 The @code{help} command (@pxref{Getting Help}) is able to find the first | |
968 block of comments in a function (even those that are composed directly | |
969 on the command line). This means that users of Octave can use the same | |
970 commands to get help for built-in functions, and for functions that you | |
971 have defined. For example, after defining the function @code{f} above, | |
972 the command @kbd{help f} produces the output | |
973 | |
974 @example | |
975 @group | |
976 usage: f (x, t) | |
977 | |
978 This function defines the right hand | |
979 side functions for a set of nonlinear | |
980 differential equations. | |
981 @end group | |
982 @end example | |
983 | |
984 Although it is possible to put comment lines into keyboard-composed | |
985 throw-away Octave programs, it usually isn't very useful, because the | |
986 purpose of a comment is to help you or another person understand the | |
987 program at a later time. | |
988 |