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