Mercurial > hg > octave-thorsten
annotate doc/interpreter/basics.txi @ 8653:2479ebf1c33f
doc/interpreter/system.txi: remove reference to 'eomdate'
author | Soren Hauberg <hauberg@gmail.com> |
---|---|
date | Sun, 01 Feb 2009 16:30:29 +0100 |
parents | fa78cb8d8a5c |
children | 03b7f618ab3d |
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 | |
6620 | 335 The following function can be used to change which programs are used |
336 for displaying the documentation, and where the documentation can be | |
337 found. | |
3294 | 338 |
6477 | 339 @DOCSTRING(info_file) |
3294 | 340 |
6477 | 341 @DOCSTRING(info_program) |
3294 | 342 |
6477 | 343 @DOCSTRING(makeinfo_program) |
3686 | 344 |
3332 | 345 @DOCSTRING(suppress_verbose_help_message) |
3294 | 346 |
4167 | 347 @node Command Line Editing |
3294 | 348 @section Command Line Editing |
349 @cindex command-line editing | |
350 @cindex editing the command line | |
351 | |
352 Octave uses the GNU readline library to provide an extensive set of | |
353 command-line editing and history features. Only the most common | |
354 features are described in this manual. Please see The GNU Readline | |
355 Library manual for more information. | |
356 | |
357 To insert printing characters (letters, digits, symbols, etc.), simply | |
358 type the character. Octave will insert the character at the cursor and | |
359 advance the cursor forward. | |
360 | |
361 Many of the command-line editing functions operate using control | |
362 characters. For example, the character @kbd{Control-a} moves the cursor | |
363 to the beginning of the line. To type @kbd{C-a}, hold down @key{CTRL} | |
364 and then press @key{a}. In the following sections, control characters | |
365 such as @kbd{Control-a} are written as @kbd{C-a}. | |
366 | |
367 Another set of command-line editing functions use Meta characters. On | |
368 some terminals, you type @kbd{M-u} by holding down @key{META} and | |
369 pressing @key{u}. If your terminal does not have a @key{META} key, you | |
7001 | 370 can still type Meta characters using two-character sequences starting |
3294 | 371 with @kbd{ESC}. Thus, to enter @kbd{M-u}, you could type |
372 @key{ESC}@key{u}. The @kbd{ESC} character sequences are also allowed on | |
373 terminals with real Meta keys. In the following sections, Meta | |
374 characters such as @kbd{Meta-u} are written as @kbd{M-u}. | |
375 | |
3428 | 376 |
3294 | 377 @menu |
378 * Cursor Motion:: | |
379 * Killing and Yanking:: | |
380 * Commands For Text:: | |
381 * Commands For Completion:: | |
382 * Commands For History:: | |
3439 | 383 * Customizing readline:: |
3294 | 384 * Customizing the Prompt:: |
385 * Diary and Echo Commands:: | |
386 @end menu | |
387 | |
4167 | 388 @node Cursor Motion |
3294 | 389 @subsection Cursor Motion |
390 | |
391 The following commands allow you to position the cursor. | |
392 | |
393 @table @kbd | |
394 @item C-b | |
395 Move back one character. | |
396 | |
397 @item C-f | |
398 Move forward one character. | |
399 | |
400 @item @key{DEL} | |
401 Delete the character to the left of the cursor. | |
402 | |
403 @item C-d | |
404 Delete the character underneath the cursor. | |
405 | |
406 @item M-f | |
407 Move forward a word. | |
408 | |
409 @item M-b | |
410 Move backward a word. | |
411 | |
412 @item C-a | |
413 Move to the start of the line. | |
414 | |
415 @item C-e | |
416 Move to the end of the line. | |
417 | |
418 @item C-l | |
419 Clear the screen, reprinting the current line at the top. | |
420 | |
421 @item C-_ | |
422 @itemx C-/ | |
423 Undo the last thing that you did. You can undo all the way back to an | |
424 empty line. | |
425 | |
426 @item M-r | |
427 Undo all changes made to this line. This is like typing the `undo' | |
428 command enough times to get back to the beginning. | |
429 @end table | |
430 | |
431 The above table describes the most basic possible keystrokes that you need | |
432 in order to do editing of the input line. On most terminals, you can | |
433 also use the arrow keys in place of @kbd{C-f} and @kbd{C-b} to move | |
434 forward and backward. | |
435 | |
436 Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves | |
437 forward a word. It is a loose convention that control keystrokes | |
438 operate on characters while meta keystrokes operate on words. | |
439 | |
440 @cindex clearing the screen | |
441 | |
6620 | 442 The function @code{clc} will allow you to clear the screen from within |
443 Octave programs. | |
444 | |
445 @ifinfo | |
3332 | 446 @DOCSTRING(clc) |
6620 | 447 @end ifinfo |
3294 | 448 |
4167 | 449 @node Killing and Yanking |
3294 | 450 @subsection Killing and Yanking |
451 | |
452 @dfn{Killing} text means to delete the text from the line, but to save | |
453 it away for later use, usually by @dfn{yanking} it back into the line. | |
454 If the description for a command says that it `kills' text, then you can | |
455 be sure that you can get the text back in a different (or the same) | |
456 place later. | |
457 | |
458 Here is the list of commands for killing text. | |
459 | |
460 @table @kbd | |
461 @item C-k | |
462 Kill the text from the current cursor position to the end of the line. | |
463 | |
464 @item M-d | |
465 Kill from the cursor to the end of the current word, or if between | |
466 words, to the end of the next word. | |
467 | |
468 @item M-@key{DEL} | |
469 Kill from the cursor to the start of the previous word, or if between | |
470 words, to the start of the previous word. | |
471 | |
472 @item C-w | |
473 Kill from the cursor to the previous whitespace. This is different than | |
474 @kbd{M-@key{DEL}} because the word boundaries differ. | |
475 @end table | |
476 | |
477 And, here is how to @dfn{yank} the text back into the line. Yanking | |
478 means to copy the most-recently-killed text from the kill buffer. | |
479 | |
480 @table @kbd | |
481 @item C-y | |
482 Yank the most recently killed text back into the buffer at the cursor. | |
483 | |
484 @item M-y | |
485 Rotate the kill-ring, and yank the new top. You can only do this if | |
486 the prior command is @kbd{C-y} or @kbd{M-y}. | |
487 @end table | |
488 | |
489 When you use a kill command, the text is saved in a @dfn{kill-ring}. | |
490 Any number of consecutive kills save all of the killed text together, so | |
491 that when you yank it back, you get it in one clean sweep. The kill | |
492 ring is not line specific; the text that you killed on a previously | |
493 typed line is available to be yanked back later, when you are typing | |
494 another line. | |
495 | |
4167 | 496 @node Commands For Text |
3294 | 497 @subsection Commands For Changing Text |
498 | |
499 The following commands can be used for entering characters that would | |
500 otherwise have a special meaning (e.g., @kbd{TAB}, @kbd{C-q}, etc.), or | |
501 for quickly correcting typing mistakes. | |
502 | |
503 @table @kbd | |
504 @item C-q | |
505 @itemx C-v | |
506 Add the next character that you type to the line verbatim. This is | |
507 how to insert things like @kbd{C-q} for example. | |
508 | |
509 @item M-@key{TAB} | |
510 Insert a tab character. | |
511 | |
512 @item C-t | |
513 Drag the character before the cursor forward over the character at the | |
514 cursor, also moving the cursor forward. If the cursor is at the end of | |
515 the line, then transpose the two characters before it. | |
516 | |
517 @item M-t | |
518 Drag the word behind the cursor past the word in front of the cursor | |
519 moving the cursor over that word as well. | |
520 | |
521 @item M-u | |
522 Uppercase the characters following the cursor to the end of the current | |
523 (or following) word, moving the cursor to the end of the word. | |
524 | |
525 @item M-l | |
6620 | 526 Lowercase the characters following the cursor to the end of the current |
3294 | 527 (or following) word, moving the cursor to the end of the word. |
528 | |
529 @item M-c | |
530 Uppercase the character following the cursor (or the beginning of the | |
531 next word if the cursor is between words), moving the cursor to the end | |
532 of the word. | |
533 @end table | |
534 | |
4167 | 535 @node Commands For Completion |
3294 | 536 @subsection Letting Readline Type For You |
537 @cindex command completion | |
538 | |
539 The following commands allow Octave to complete command and variable | |
540 names for you. | |
541 | |
542 @table @kbd | |
543 @item @key{TAB} | |
544 Attempt to do completion on the text before the cursor. Octave can | |
545 complete the names of commands and variables. | |
546 | |
547 @item M-? | |
548 List the possible completions of the text before the cursor. | |
549 @end table | |
550 | |
3332 | 551 @DOCSTRING(completion_append_char) |
3294 | 552 |
3332 | 553 @DOCSTRING(completion_matches) |
3294 | 554 |
4167 | 555 @node Commands For History |
3294 | 556 @subsection Commands For Manipulating The History |
557 @cindex command history | |
558 @cindex input history | |
559 @cindex history of commands | |
560 | |
561 Octave normally keeps track of the commands you type so that you can | |
562 recall previous commands to edit or execute them again. When you exit | |
563 Octave, the most recent commands you have typed, up to the number | |
564 specified by the variable @code{history_size}, are saved in a file. | |
565 When Octave starts, it loads an initial list of commands from the file | |
566 named by the variable @code{history_file}. | |
567 | |
568 Here are the commands for simple browsing and searching the history | |
569 list. | |
570 | |
571 @table @kbd | |
572 @item @key{LFD} | |
573 @itemx @key{RET} | |
574 Accept the line regardless of where the cursor is. If this line is | |
575 non-empty, add it to the history list. If this line was a history | |
576 line, then restore the history line to its original state. | |
577 | |
578 @item C-p | |
579 Move `up' through the history list. | |
580 | |
581 @item C-n | |
582 Move `down' through the history list. | |
583 | |
584 @item M-< | |
585 Move to the first line in the history. | |
586 | |
587 @item M-> | |
588 Move to the end of the input history, i.e., the line you are entering! | |
589 | |
590 @item C-r | |
591 Search backward starting at the current line and moving `up' through | |
592 the history as necessary. This is an incremental search. | |
593 | |
594 @item C-s | |
595 Search forward starting at the current line and moving `down' through | |
596 the history as necessary. | |
597 @end table | |
598 | |
599 On most terminals, you can also use the arrow keys in place of @kbd{C-p} | |
600 and @kbd{C-n} to move through the history list. | |
601 | |
602 In addition to the keyboard commands for moving through the history | |
603 list, Octave provides three functions for viewing, editing, and | |
604 re-running chunks of commands from the history list. | |
605 | |
3332 | 606 @DOCSTRING(history) |
3294 | 607 |
3332 | 608 @DOCSTRING(edit_history) |
3294 | 609 |
3332 | 610 @DOCSTRING(run_history) |
3294 | 611 |
6620 | 612 Octave also allows you customize the details of how and where the history |
613 is saved. | |
3294 | 614 |
3332 | 615 @DOCSTRING(history_file) |
3294 | 616 |
3332 | 617 @DOCSTRING(history_size) |
3294 | 618 |
3332 | 619 @DOCSTRING(saving_history) |
3294 | 620 |
6550 | 621 @DOCSTRING(history_timestamp_format_string) |
622 | |
6620 | 623 @DOCSTRING(EDITOR) |
624 | |
4167 | 625 @node Customizing readline |
3428 | 626 @subsection Customizing @code{readline} |
627 | |
6620 | 628 As mentioned earlier Octave uses the GNU readline library for |
629 command-line editing and history features. It is possible to | |
630 customize how readline works through a configuration file. | |
631 | |
5775 | 632 @c FIXME -- need a brief description of the ~/.inputrc file here. |
3428 | 633 |
3439 | 634 @DOCSTRING(read_readline_init_file) |
3428 | 635 |
4167 | 636 @node Customizing the Prompt |
3294 | 637 @subsection Customizing the Prompt |
638 @cindex prompt customization | |
639 @cindex customizing the prompt | |
640 | |
641 The following variables are available for customizing the appearance of | |
642 the command-line prompts. Octave allows the prompt to be customized by | |
643 inserting a number of backslash-escaped special characters that are | |
644 decoded as follows: | |
645 | |
646 @table @samp | |
647 @item \t | |
648 The time. | |
649 | |
650 @item \d | |
651 The date. | |
652 | |
653 @item \n | |
654 Begins a new line by printing the equivalent of a carriage return | |
655 followed by a line feed. | |
656 | |
657 @item \s | |
658 The name of the program (usually just @samp{octave}). | |
659 | |
660 @item \w | |
661 The current working directory. | |
662 | |
663 @item \W | |
664 The basename of the current working directory. | |
665 | |
666 @item \u | |
667 The username of the current user. | |
668 | |
669 @item \h | |
670 The hostname, up to the first `.'. | |
671 | |
672 @item \H | |
673 The hostname. | |
674 | |
675 @item \# | |
676 The command number of this command, counting from when Octave starts. | |
677 | |
678 @item \! | |
679 The history number of this command. This differs from @samp{\#} by the | |
680 number of commands in the history list when Octave starts. | |
681 | |
682 @item \$ | |
683 If the effective UID is 0, a @samp{#}, otherwise a @samp{$}. | |
684 | |
685 @item \nnn | |
686 The character whose character code in octal is @var{nnn}. | |
687 | |
688 @item \\ | |
689 A backslash. | |
690 @end table | |
691 | |
3332 | 692 @DOCSTRING(PS1) |
3294 | 693 |
3332 | 694 @DOCSTRING(PS2) |
3294 | 695 |
3332 | 696 @DOCSTRING(PS4) |
3294 | 697 |
4167 | 698 @node Diary and Echo Commands |
3294 | 699 @subsection Diary and Echo Commands |
700 @cindex diary of commands and output | |
6939 | 701 @cindex command and output logs |
3294 | 702 @cindex logging commands and output |
703 @cindex echoing executing commands | |
704 @cindex command echoing | |
705 | |
706 Octave's diary feature allows you to keep a log of all or part of an | |
707 interactive session by recording the input you type and the output that | |
708 Octave produces in a separate file. | |
709 | |
3332 | 710 @DOCSTRING(diary) |
3294 | 711 |
712 Sometimes it is useful to see the commands in a function or script as | |
713 they are being evaluated. This can be especially helpful for debugging | |
714 some kinds of problems. | |
715 | |
3332 | 716 @DOCSTRING(echo) |
3294 | 717 |
3332 | 718 @DOCSTRING(echo_executing_commands) |
3294 | 719 |
4167 | 720 @node Errors |
3294 | 721 @section How Octave Reports Errors |
722 @cindex error messages | |
723 @cindex messages, error | |
724 | |
725 Octave reports two kinds of errors for invalid programs. | |
726 | |
727 A @dfn{parse error} occurs if Octave cannot understand something you | |
728 have typed. For example, if you misspell a keyword, | |
729 | |
730 @example | |
731 octave:13> functon y = f (x) y = x^2; endfunction | |
732 @end example | |
733 | |
734 @noindent | |
735 Octave will respond immediately with a message like this: | |
736 | |
737 @example | |
738 parse error: | |
739 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
740 syntax error |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
741 |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
742 >>> 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
|
743 ^ |
3294 | 744 @end example |
745 | |
746 @noindent | |
747 For most parse errors, Octave uses a caret (@samp{^}) to mark the point | |
748 on the line where it was unable to make sense of your input. In this | |
749 case, Octave generated an error message because the keyword | |
750 @code{function} was misspelled. Instead of seeing @samp{function f}, | |
751 Octave saw two consecutive variable names, which is invalid in this | |
752 context. It marked the error at @code{y} because the first name by | |
753 itself was accepted as valid input. | |
754 | |
755 Another class of error message occurs at evaluation time. These | |
756 errors are called @dfn{run-time errors}, or sometimes | |
757 @dfn{evaluation errors} because they occur when your program is being | |
758 @dfn{run}, or @dfn{evaluated}. For example, if after correcting the | |
759 mistake in the previous function definition, you type | |
760 | |
761 @example | |
762 octave:13> f () | |
763 @end example | |
764 | |
765 @noindent | |
766 Octave will respond with | |
767 | |
7031 | 768 @c Using 'smallexample' to make text fit on page when creating smallbook. |
769 @smallexample | |
3294 | 770 @group |
771 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
|
772 error: called from: |
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
773 error: f at line 1, column 22 |
3294 | 774 @end group |
7031 | 775 @end smallexample |
3294 | 776 |
6620 | 777 @noindent |
3294 | 778 This error message has several parts, and gives you quite a bit of |
779 information to help you locate the source of the error. The messages | |
780 are generated from the point of the innermost error, and provide a | |
781 traceback of enclosing expressions and function calls. | |
782 | |
783 In the example above, the first line indicates that a variable named | |
784 @samp{x} was found to be undefined near line 1 and column 24 of some | |
785 function or expression. For errors occurring within functions, lines | |
786 are counted from the beginning of the file containing the function | |
787 definition. For errors occurring at the top level, the line number | |
788 indicates the input line number, which is usually displayed in the | |
789 prompt string. | |
790 | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
791 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
|
792 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
|
793 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
|
794 one more line: |
3294 | 795 |
796 @example | |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7031
diff
changeset
|
797 error: g at line 1, column 17 |
3294 | 798 @end example |
799 | |
800 These lists of function calls usually make it fairly easy to trace the | |
801 path your program took before the error occurred, and to correct the | |
802 error before trying again. | |
803 | |
4167 | 804 @node Executable Octave Programs |
3294 | 805 @section Executable Octave Programs |
806 @cindex executable scripts | |
807 @cindex scripts | |
808 @cindex self contained programs | |
809 @cindex program, self contained | |
810 @cindex @samp{#!} | |
811 | |
812 Once you have learned Octave, you may want to write self-contained | |
813 Octave scripts, using the @samp{#!} script mechanism. You can do this | |
814 on GNU systems and on many Unix systems @footnote{The @samp{#!} | |
815 mechanism works on Unix systems derived from Berkeley Unix, System V | |
6481 | 816 Release 4, and some System V Release 3 systems.}. |
817 | |
818 Self-contained Octave scripts are useful when you want to write a | |
819 program which users can invoke without knowing that the program is | |
820 written in the Octave language. | |
3294 | 821 |
822 For example, you could create a text file named @file{hello}, containing | |
823 the following lines: | |
824 | |
825 @example | |
826 @group | |
827 #! @var{octave-interpreter-name} -qf | |
828 # a sample Octave program | |
829 printf ("Hello, world!\n"); | |
830 @end group | |
831 @end example | |
832 | |
833 @noindent | |
834 (where @var{octave-interpreter-name} should be replaced with the full | |
6481 | 835 file name for your Octave binary). Note that this will only work if |
836 @samp{#!} appears at the very beginning of the file. After making this | |
837 file executable | |
3294 | 838 (with the @code{chmod} command), you can simply type: |
839 | |
840 @example | |
841 hello | |
842 @end example | |
843 | |
844 @noindent | |
845 at the shell, and the system will arrange to run Octave as if you had | |
846 typed: | |
847 | |
848 @example | |
849 octave hello | |
850 @end example | |
851 | |
852 The line beginning with @samp{#!} lists the full file name of an | |
853 interpreter to be run, and an optional initial command line argument to | |
854 pass to that interpreter. The operating system then runs the | |
855 interpreter with the given argument and the full argument list of the | |
856 executed program. The first argument in the list is the full file name | |
857 of the Octave program. The rest of the argument list will either be | |
858 options to Octave, or data files, or both. The @samp{-qf} option is | |
859 usually specified in stand-alone Octave programs to prevent them from | |
860 printing the normal startup message, and to keep them from behaving | |
861 differently depending on the contents of a particular user's | |
6620 | 862 @file{~/.octaverc} file. @xref{Invoking Octave from the Command Line}. |
6481 | 863 |
864 Note that some operating systems may place a limit on the number of | |
865 characters that are recognized after @samp{#!}. Also, the various | |
866 shells/systems parse differently the arguments appearing in a @samp{#!} | |
867 line. The majority of them group together all the arguments in a string | |
6939 | 868 and pass it to the interpreter as a single argument. In this case, the |
6481 | 869 following script: |
870 | |
871 @example | |
872 @group | |
873 #! @var{octave-interpreter-name} -q -f # comment | |
874 @end group | |
875 @end example | |
876 | |
877 @noindent | |
878 is equivalent to type at the command line: | |
3294 | 879 |
6481 | 880 @example |
881 @group | |
882 octave "-q -f # comment" | |
883 @end group | |
884 @end example | |
3294 | 885 |
6481 | 886 @noindent |
887 which would obviously produce an error message. Unfortunately, it is | |
888 impossible for Octave to know whether it has been called from the command | |
889 line or from a @samp{#!} script, so some care is needed when using the | |
890 @samp{#!} mechanism. | |
891 | |
892 Note that when Octave is started from an executable script, the built-in | |
893 function @code{argv} returns a cell array containing the command line | |
894 arguments passed to an executable Octave script, not the arguments | |
895 passed to the Octave interpreter on the @samp{#!} line of the script. | |
896 For example, the following program will reproduce the command line that | |
897 is used to execute script, not @samp{-qf}. | |
3294 | 898 |
899 @example | |
900 @group | |
901 #! /bin/octave -qf | |
6479 | 902 printf ("%s", program_name ()); |
6620 | 903 arg_list = argv (); |
3294 | 904 for i = 1:nargin |
6479 | 905 printf (" %s", arg_list@{i@}); |
3294 | 906 endfor |
907 printf ("\n"); | |
908 @end group | |
909 @end example | |
910 | |
4167 | 911 @node Comments |
3294 | 912 @section Comments in Octave Programs |
913 @cindex @samp{#} | |
914 @cindex @samp{%} | |
915 @cindex comments | |
916 @cindex use of comments | |
917 @cindex documenting Octave programs | |
918 @cindex programs | |
919 | |
920 A @dfn{comment} is some text that is included in a program for the sake | |
921 of human readers, and that is not really part of the program. Comments | |
922 can explain what the program does, and how it works. Nearly all | |
923 programming languages have provisions for comments, because programs are | |
924 typically hard to understand without them. | |
925 | |
926 In the Octave language, a comment starts with either the sharp sign | |
927 character, @samp{#}, or the percent symbol @samp{%} and continues to the | |
928 end of the line. The Octave interpreter ignores the rest of a | |
929 line following a sharp sign or percent symbol. For example, we could | |
930 have put the following into the function @code{f}: | |
931 | |
932 @example | |
933 @group | |
934 function xdot = f (x, t) | |
935 | |
936 # usage: f (x, t) | |
937 # | |
938 # This function defines the right hand | |
939 # side functions for a set of nonlinear | |
940 # differential equations. | |
941 | |
942 r = 0.25; | |
943 @dots{} | |
944 endfunction | |
945 @end group | |
946 @end example | |
947 | |
948 The @code{help} command (@pxref{Getting Help}) is able to find the first | |
949 block of comments in a function (even those that are composed directly | |
950 on the command line). This means that users of Octave can use the same | |
951 commands to get help for built-in functions, and for functions that you | |
952 have defined. For example, after defining the function @code{f} above, | |
953 the command @kbd{help f} produces the output | |
954 | |
955 @example | |
956 @group | |
957 usage: f (x, t) | |
958 | |
959 This function defines the right hand | |
960 side functions for a set of nonlinear | |
961 differential equations. | |
962 @end group | |
963 @end example | |
964 | |
965 Although it is possible to put comment lines into keyboard-composed | |
966 throw-away Octave programs, it usually isn't very useful, because the | |
967 purpose of a comment is to help you or another person understand the | |
968 program at a later time. | |
969 |