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