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