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