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