Mercurial > hg > octave-lyh
comparison doc/interpreter/basics.texi @ 2670:18192eea4973
[project @ 1997-02-13 18:29:53 by jwe]
author | jwe |
---|---|
date | Thu, 13 Feb 1997 18:34:06 +0000 |
parents | e7908588548a |
children | 8c7955a8d49f |
comparison
equal
deleted
inserted
replaced
2669:c821858188b6 | 2670:18192eea4973 |
---|---|
1 @c Copyright (C) 1996 John W. Eaton | 1 @c Copyright (C) 1996, 1997 John W. Eaton |
2 @c This is part of the Octave manual. | 2 @c This is part of the Octave manual. |
3 @c For copying conditions, see the file gpl.texi. | 3 @c For copying conditions, see the file gpl.texi. |
4 | 4 |
5 @node Basics, Expressions, Invoking Octave, Top | 5 @node Getting Started, Data Types, Introduction, Top |
6 @chapter Basics | 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. | |
7 | 12 |
8 @menu | 13 @menu |
14 * Invoking Octave:: | |
15 * Quitting Octave:: | |
16 * Getting Help:: | |
17 * Command Line Editing:: | |
18 * Errors:: | |
19 * Executable Octave Programs:: | |
9 * Comments:: | 20 * Comments:: |
10 * Executable Octave Programs:: | |
11 * Errors:: | |
12 * Help:: | |
13 * Command Line Editing:: | |
14 * Command History Functions:: | |
15 @end menu | 21 @end menu |
16 | 22 |
17 @node Comments, Executable Octave Programs, Basics, Basics | 23 @node Invoking Octave, Quitting Octave, Getting Started, Getting Started |
18 @section Comments in Octave Programs | 24 @section Invoking Octave |
19 @cindex @samp{#} | 25 |
20 @cindex @samp{%} | 26 Normally, Octave is used interactively by running the program |
21 @cindex comments | 27 @samp{octave} without any arguments. Once started, Octave reads |
22 @cindex use of comments | 28 commands from the terminal until you tell it to exit. |
23 @cindex documenting Octave programs | 29 |
24 @cindex programs | 30 You can also specify the name of a file on the command line, and Octave |
25 | 31 will read and execute the commands from the named file and then exit |
26 A @dfn{comment} is some text that is included in a program for the sake | 32 when it is finished. |
27 of human readers, and that is not really part of the program. Comments | 33 |
28 can explain what the program does, and how it works. Nearly all | 34 You can further control how Octave starts by using the command-line |
29 programming languages have provisions for comments, because programs are | 35 options described in the next section, and Octave itself can remind you |
30 typically hard to understand without them. | 36 of the options available. Type @kbd{octave --help} to display all |
31 | 37 available options and briefly describe their use (@kbd{octave -h} is a |
32 In the Octave language, a comment starts with either the sharp sign | 38 shorter equivalent). |
33 character, @samp{#}, or the percent symbol @samp{%} and continues to the | 39 |
34 end of the line. The Octave interpreter ignores the rest of a | 40 @menu |
35 line following a sharp sign or percent symbol. For example, we could | 41 * Command Line Options:: |
36 have put the following into the function @code{f}: | 42 * Startup Files:: |
37 | 43 @end menu |
38 @smallexample | 44 |
39 function xdot = f (x, t) | 45 @node Command Line Options, Startup Files, Invoking Octave, Invoking Octave |
40 | 46 @subsection Command Line Options |
41 # usage: f (x, t) | 47 @cindex Octave command options |
42 # | 48 @cindex command options |
43 # This function defines the right-hand-side functions for a set of | 49 @cindex options, Octave command |
44 # nonlinear differential equations. | 50 |
45 | 51 Here is a complete list of all the command line options that Octave |
46 r = 0.25 | 52 accepts. |
47 | 53 |
48 and so on... | 54 @table @code |
49 | 55 @item --debug |
50 endfunction | 56 @itemx -d |
51 @end smallexample | 57 @cindex @code{--debug} |
52 | 58 @cindex @code{-d} |
53 The @code{help} command (@pxref{Help}) is able to find the first block | 59 Enter parser debugging mode. Using this option will cause Octave's |
54 of comments in a function (even those that are composed directly on the | 60 parser to print a lot of information about the commands it reads, and is |
55 command line). This means that users of Octave can use the same | 61 probably only useful if you are actually trying to debug the parser. |
56 commands to get help for built-in functions, and for functions that you | 62 |
57 have defined. For example, after defining the function @code{f} above, | 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 @samp{OCTAVE_EXEC_PATH} found in the environment, but not any | |
74 @samp{EXEC_PATH = "path"} commands found in the system or user startup | |
75 files. | |
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 @samp{OCTAVE_INFO_FILE} found in the environment, but not any | |
90 @samp{INFO_FILE = "filename"} commands found in the system or user | |
91 startup files. | |
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 @samp{OCTAVE_INFO_PROGRAM} found in the environment, but not any | |
98 @samp{INFO_PROGRAM = "program"} commands found in the system or user | |
99 startup files. | |
100 | |
101 @item --interactive | |
102 @itemx -i | |
103 @cindex @code{--interactive} | |
104 @cindex @code{-i} | |
105 Force interactive behavior. | |
106 | |
107 @item --no-init-file | |
108 @cindex @code{--no-init-file} | |
109 Don't read the @file{~/.octaverc} or @file{.octaverc} files. | |
110 | |
111 @item --no-line-editing | |
112 @cindex @code{--no-line-editing} | |
113 Disable command-line editing and history. | |
114 | |
115 @item --no-site-file | |
116 @cindex @code{--no-site-file} | |
117 Don't read the site-wide @file{octaverc} file. | |
118 | |
119 @item --norc | |
120 @itemx -f | |
121 @cindex @code{--norc} | |
122 @cindex @code{-f} | |
123 Don't read any of the system or user initialization files at startup. | |
124 This is equivalent to using both of the options @code{--no-init-file} | |
125 and @code{--no-site-file}. | |
126 | |
127 @item --path @var{path} | |
128 @itemx -p @var{path} | |
129 @cindex @code{--path @var{path}} | |
130 @cindex @code{-p @var{path}} | |
131 Specify the path to search for function files. The value of @var{path} | |
132 specified on the command line will override any value of | |
133 @samp{OCTAVE_PATH} found in the environment, but not any | |
134 @samp{LOADPATH = "path"} commands found in the system or user startup | |
135 files. | |
136 | |
137 @item --silent | |
138 @itemx --quiet | |
139 @itemx -q | |
140 @cindex @code{--silent} | |
141 @cindex @code{--quiet} | |
142 @cindex @code{-q} | |
143 Don't print message at startup. | |
144 | |
145 @item --traditional | |
146 @itemx --braindead | |
147 @cindex @code{--traditional} | |
148 @cindex @code{--braindead} | |
149 Set initial values for user-preference variables to the following | |
150 values for compatibility with @sc{Matlab}. | |
151 | |
152 @example | |
153 PS1 = ">> " | |
154 PS2 = "" | |
155 beep_on_error = 1 | |
156 default_save_format = "mat-binary" | |
157 define_all_return_values = 1 | |
158 do_fortran_indexing = 1 | |
159 empty_list_elements_ok = 1 | |
160 implicit_str_to_num_ok = 1 | |
161 ok_to_lose_imaginary_part = 1 | |
162 page_screen_output = 0 | |
163 prefer_column_vectors = 0 | |
164 prefer_zero_one_indexing = 1 | |
165 print_empty_dimensions = 0 | |
166 treat_neg_dim_as_zero = 1 | |
167 warn_function_name_clash = 0 | |
168 whitespace_in_literal_matrix = "traditional" | |
169 @end example | |
170 | |
171 @item --verbose | |
172 @itemx -V | |
173 @cindex @code{--verbose} | |
174 @cindex @code{-V} | |
175 Turn on verbose output. | |
176 | |
177 @item --version | |
178 @itemx -v | |
179 @cindex @code{--version} | |
180 @cindex @code{-v} | |
181 Print the program version number and exit. | |
182 | |
183 @item @var{file} | |
184 Execute commands from @var{file}. | |
185 @end table | |
186 | |
187 Octave also includes several built-in variables that contain information | |
188 about the command line, including the number of arguments and all of the | |
189 options. | |
190 | |
191 @defvr {Built-in Variable} argv | |
192 The command line arguments passed to Octave are available in this | |
193 variable. For example, if you invoked Octave using the command | |
194 | |
195 @example | |
196 octave --no-line-editing --silent | |
197 @end example | |
198 | |
199 @noindent | |
200 @code{argv} would be a string vector with the elements | |
201 @code{--no-line-editing} and @code{--silent}. | |
202 | |
203 If you write an executable Octave script, @code{argv} will contain the | |
204 list of arguments passed to the script. @pxref{Executable Octave Programs}. | |
205 @end defvr | |
206 | |
207 @defvr {Built-in Variable} nargin | |
208 At the top level, this variable is defined as the number of command line | |
209 arguments that were passed to Octave. | |
210 @end defvr | |
211 | |
212 @defvr {Built-in Variable} program_invocation_name | |
213 @defvrx {Built-in Variable} program_name | |
214 When Octave starts, the value of the built-in variable | |
215 @code{program_invocation_name} is automatically set to the name that was | |
216 typed at the shell prompt to run Octave, and the value of | |
217 @code{program_name} is automatically set to the final component of | |
218 @code{program_invocation_name}. For example, if you typed | |
219 @kbd{@value{OCTAVEHOME}/bin/octave} to start Octave, | |
220 @code{program_invocation_name} would have the value | |
221 @code{"@value{OCTAVEHOME}/bin/octave"}, and @code{program_name} would | |
222 have the value @code{"octave"}. | |
223 | |
224 If executing a script from the command line (e.g., @code{octave foo.m} | |
225 or using an executable Octave script, the program name is set to the | |
226 name of the script. @xref{Executable Octave Programs} for an example of | |
227 how to create an executable Octave script. | |
228 @end defvr | |
229 | |
230 Here is an example of using these variables to reproduce Octave's | |
231 command line. | |
232 | |
233 @example | |
234 printf ("%s", program_name); | |
235 for i = 1:nargin | |
236 printf (" %s", argv(i,:)); | |
237 endfor | |
238 printf ("\n"); | |
239 @end example | |
240 | |
241 @noindent | |
242 @xref{Index Expressions} for an explanation of how to properly index | |
243 arrays of strings and substrings in Octave. | |
244 | |
245 @node Startup Files, , Command Line Options, Invoking Octave | |
246 @subsection Startup Files | |
247 @cindex initialization | |
248 @cindex startup | |
249 | |
250 When Octave starts, it looks for commands to execute from the following | |
251 files: | |
252 | |
253 @cindex startup files | |
254 | |
255 @table @code | |
256 @item OCTAVE_HOME/share/octave/site/m/startup/octaverc | |
257 Where @code{OCTAVE_HOME} is the directory in which all of Octave is | |
258 installed (the default is @file{/usr/local}). This file is provided so | |
259 that changes to the default Octave environment can be made globally for | |
260 all users at your site for all versions of Octave you have installed. | |
261 Some care should be taken when making changes to this file, since all | |
262 users of Octave at your site will be affected. | |
263 | |
264 @item OCTAVE_HOME/share/octave/VERSION/m/startup/octaverc | |
265 Where @code{OCTAVE_HOME} is the directory in which all of Octave is | |
266 installed (the default is @file{/usr/local}), and @code{VERSION} is the | |
267 version number of Octave. This file is provided so that changes to the | |
268 default Octave environment can be made globally for all users for a | |
269 particular version of Octave. Some care should be taken when making | |
270 changes to this file, since all users of Octave at your site will be | |
271 affected. | |
272 | |
273 @item ~/.octaverc | |
274 @cindex @code{~/.octaverc} | |
275 This file is normally used to make personal changes to the default | |
276 Octave environment. | |
277 | |
278 @item .octaverc | |
279 @cindex @code{.octaverc} | |
280 This file can be used to make changes to the default Octave environment | |
281 for a particular project. Octave searches for this file in the current | |
282 directory after it reads @file{~/.octaverc}. Any use of the @code{cd} | |
283 command in the @file{~/.octaverc} file will affect the directory that | |
284 Octave searches for the file @file{.octaverc}. | |
285 | |
286 If you start Octave in your home directory, commands from from the file | |
287 @file{~/.octaverc} will only be executed once. | |
288 @end table | |
289 | |
290 A message will be displayed as each of the startup files is read if you | |
291 invoke Octave with the @code{--verbose} option but without the | |
292 @code{--silent} option. | |
293 | |
294 Startup files may contain any valid Octave commands, including function | |
295 definitions. | |
296 | |
297 @node Quitting Octave, Getting Help, Invoking Octave, Getting Started | |
298 @section Quitting Octave | |
299 @cindex exiting octave | |
300 @cindex quitting octave | |
301 | |
302 @deftypefn {Built-in Function} {} exit (@var{status}) | |
303 @deftypefnx {Built-in Function} {} quit (@var{status}) | |
304 Exit the current Octave session. If the optional integer value | |
305 @var{status} is supplied, pass that value to the operating system as the | |
306 Octave's exit status. | |
307 @end deftypefn | |
308 | |
309 @deftypefn {Built-in Function} {} atexit (@var{fcn}) | |
310 Register function to be called when Octave exits. | |
311 @end deftypefn | |
312 | |
313 @node Getting Help, Command Line Editing, Quitting Octave, Getting Started | |
314 @section Commands for Getting Help | |
315 @cindex on-line help | |
316 @cindex help, on-line | |
317 | |
318 The entire text of this manual is available from the Octave prompt | |
319 via the command @kbd{help -i}. In addition, the documentation for | |
320 individual user-written functions and variables is also available via | |
321 the @kbd{help} command. This section describes the commands used for | |
322 reading the manual and the documentation strings for user-supplied | |
323 functions and variables. @xref{Function Files}, for more information | |
324 about how to document the functions you write. | |
325 | |
326 @deffn {Command} help | |
327 Octave's @code{help} command can be used to print brief usage-style | |
328 messages, or to display information directly from an on-line version of | |
329 the printed manual, using the GNU Info browser. If invoked without any | |
330 arguments, @code{help} prints a list of all the available operators, | |
331 functions, and built-in variables. If the first argument is @code{-i}, | |
332 the @code{help} command searches the index of the on-line version of | |
333 this manual for the given topics. | |
334 | |
335 For example, the command @kbd{help help} prints a short message | |
336 describing the @code{help} command, and @kbd{help -i help} starts the | |
337 GNU Info browser at this node in the on-line version of the manual. | |
338 | |
339 Once the GNU Info browser is runnig, help for using it is available | |
340 using the command @kbd{C-h}. | |
341 @end deffn | |
342 | |
343 The help command can give you information about operators, but not the | |
344 comma and semicolons that are used as command separators. To get help | |
345 for those, you must type @kbd{help comma} or @kbd{help semicolon}. | |
346 | |
347 @defvr {Built-in Variable} INFO_FILE | |
348 The variable @code{INFO_FILE} names the location of the Octave info file. | |
349 The default value is @code{"@value{OCTAVEHOME}/info/octave.info"}. | |
350 @end defvr | |
351 | |
352 @defvr {Built-in Variable} INFO_PROGRAM | |
353 The variable @code{INFO_PROGRAM} names the info program to run. Its | |
354 initial value is | |
355 @code{@value{OCTAVEHOME}/libexec/octave/VERSION/exec/ARCH/info}, but | |
356 that value can be overridden by the environment variable | |
357 @code{OCTAVE_INFO_PROGRAM}, or the command line argument | |
358 @code{--info-program NAME}, or by setting the value of | |
359 @code{INFO_PROGRAM} in a startup script. | |
360 @end defvr | |
361 | |
362 @defvr {Built-in Variable} suppress_verbose_help_message | |
363 If the value of @code{suppress_verbose_help_message} is nonzero, Octave | |
364 will not add additional help information to the end of the output from | |
365 the @code{help} command and usage messages for built-in commands. | |
366 @end defvr | |
367 | |
368 @node Command Line Editing, Errors, Getting Help, Getting Started | |
369 @section Command Line Editing | |
370 @cindex command-line editing | |
371 @cindex editing the command line | |
372 | |
373 Octave uses the GNU readline library to provide an extensive set of | |
374 command-line editing and history features. Only the most common | |
375 features are described in this manual. Please see The GNU Readline | |
376 Library for more information. | |
377 | |
378 To insert printing characters (letters, digits, symbols, etc.), simply | |
379 type the character. Octave will insert the character at the cursor and | |
380 advance the cursor forward. | |
381 | |
382 Many of the command-line editing functions operate using control | |
383 characters. For example, the character @kbd{Control-a} moves the cursor | |
384 to the beginning of the line. To type @kbd{C-a}, hold down @key{CTRL} | |
385 and then press @key{a}. In the following sections, control characters | |
386 such as @kbd{Control-a} are written as @kbd{C-a}. | |
387 | |
388 Another set of command-line editing functions use Meta characters. On | |
389 some terminals, you type @kbd{M-u} by holding down @key{META} and | |
390 pressing @key{u}. If your terminal does not have a @key{META} key, you | |
391 can still type Meta charcters using two-character sequences starting | |
392 with @kbd{ESC}. Thus, to enter @kbd{M-u}, you could type | |
393 @key{ESC}@key{u}. The @kbd{ESC} character sequences are also allowed on | |
394 terminals with real Meta keys. In the following sections, Meta | |
395 characters such as @kbd{Meta-u} are written as @kbd{M-u}. | |
396 | |
397 @menu | |
398 * Cursor Motion:: | |
399 * Killing and Yanking:: | |
400 * Commands For Text:: | |
401 * Commands For Completion:: | |
402 * Commands For History:: | |
403 * Customizing the Prompt:: | |
404 * Diary and Echo Commands:: | |
405 @end menu | |
406 | |
407 @node Cursor Motion, Killing and Yanking, Command Line Editing, Command Line Editing | |
408 @subsection Cursor Motion | |
409 | |
410 The following commands allow you to position the cursor. | |
411 | |
412 @table @kbd | |
413 @item C-b | |
414 Move back one character. | |
415 | |
416 @item C-f | |
417 Move forward one character. | |
418 | |
419 @item DEL | |
420 Delete the character to the left of the cursor. | |
421 | |
422 @item C-d | |
423 Delete the character underneath the cursor. | |
424 | |
425 @item M-f | |
426 Move forward a word. | |
427 | |
428 @item M-b | |
429 Move backward a word. | |
430 | |
431 @item C-a | |
432 Move to the start of the line. | |
433 | |
434 @item C-e | |
435 Move to the end of the line. | |
436 | |
437 @item C-l | |
438 Clear the screen, reprinting the current line at the top. | |
439 | |
440 @item C-_ | |
441 @itemx C-/ | |
442 Undo the last thing that you did. You can undo all the way back to an | |
443 empty line. | |
444 | |
445 @item M-r | |
446 Undo all changes made to this line. This is like typing the `undo' | |
447 command enough times to get back to the beginning. | |
448 @end table | |
449 | |
450 The above table describes the most basic possible keystrokes that you need | |
451 in order to do editing of the input line. On most terminals, you can | |
452 also use the arrow keys in place of @kbd{C-f} and @kbd{C-b} to move | |
453 forward and backward. | |
454 | |
455 Notice how @kbd{C-f} moves forward a character, while @kbd{M-f} moves | |
456 forward a word. It is a loose convention that control keystrokes | |
457 operate on characters while meta keystrokes operate on words. | |
458 | |
459 There is also a function available so that you can clear the screen from | |
460 within Octave programs. | |
461 | |
462 @cindex clearing the screen | |
463 | |
464 @deftypefn {Built-in Function} {} clc () | |
465 @deftypefnx {Built-in Function} {} home () | |
466 Clear the terminal screen and move the cursor to the upper left corner. | |
467 @end deftypefn | |
468 | |
469 @node Killing and Yanking, Commands For Text, Cursor Motion, Command Line Editing | |
470 @subsection Killing and Yanking | |
471 | |
472 @dfn{Killing} text means to delete the text from the line, but to save | |
473 it away for later use, usually by @dfn{yanking} it back into the line. | |
474 If the description for a command says that it `kills' text, then you can | |
475 be sure that you can get the text back in a different (or the same) | |
476 place later. | |
477 | |
478 Here is the list of commands for killing text. | |
479 | |
480 @table @kbd | |
481 @item C-k | |
482 Kill the text from the current cursor position to the end of the line. | |
483 | |
484 @item M-d | |
485 Kill from the cursor to the end of the current word, or if between | |
486 words, to the end of the next word. | |
487 | |
488 @item M-DEL | |
489 Kill from the cursor to the start of the previous word, or if between | |
490 words, to the start of the previous word. | |
491 | |
492 @item C-w | |
493 Kill from the cursor to the previous whitespace. This is different than | |
494 @kbd{M-DEL} because the word boundaries differ. | |
495 @end table | |
496 | |
497 And, here is how to @dfn{yank} the text back into the line. Yanking | |
498 means to copy the most-recently-killed text from the kill buffer. | |
499 | |
500 @table @kbd | |
501 @item C-y | |
502 Yank the most recently killed text back into the buffer at the cursor. | |
503 | |
504 @item M-y | |
505 Rotate the kill-ring, and yank the new top. You can only do this if | |
506 the prior command is @kbd{C-y} or @kbd{M-y}. | |
507 @end table | |
508 | |
509 When you use a kill command, the text is saved in a @dfn{kill-ring}. | |
510 Any number of consecutive kills save all of the killed text together, so | |
511 that when you yank it back, you get it in one clean sweep. The kill | |
512 ring is not line specific; the text that you killed on a previously | |
513 typed line is available to be yanked back later, when you are typing | |
514 another line. | |
515 | |
516 @node Commands For Text, Commands For Completion, Killing and Yanking, Command Line Editing | |
517 @subsection Commands For Changing Text | |
518 | |
519 The following commands can be used for entering characters that would | |
520 otherwise have a special meaning (e.g., @kbd{TAB}, @kbd{C-q}, etc.), or | |
521 for quickly correcting typing mistakes. | |
522 | |
523 @table @kbd | |
524 @item C-q | |
525 @itemx C-v | |
526 Add the next character that you type to the line verbatim. This is | |
527 how to insert things like @kbd{C-q} for example. | |
528 | |
529 @item M-TAB | |
530 Insert a tab character. | |
531 | |
532 @item C-t | |
533 Drag the character before the cursor forward over the character at the | |
534 cursor, also moving the cursor forward. If the cursor is at the end of | |
535 the line, then transpose the two characters before it. | |
536 | |
537 @item M-t | |
538 Drag the word behind the cursor past the word in front of the cursor | |
539 moving the cursor over that word as well. | |
540 | |
541 @item M-u | |
542 Uppercase the characters following the cursor to the end of the current | |
543 (or following) word, moving the cursor to the end of the word. | |
544 | |
545 @item M-l | |
546 Lowecase the characters following the cursor to the end of the current | |
547 (or following) word, moving the cursor to the end of the word. | |
548 | |
549 @item M-c | |
550 Uppercase the character following the cursor (or the beginning of the | |
551 next word if the cursor is between words), moving the cursor to the end | |
552 of the word. | |
553 @end table | |
554 | |
555 @node Commands For Completion, Commands For History, Commands For Text, Command Line Editing | |
556 @subsection Letting Readline Type For You | |
557 @cindex command completion | |
558 | |
559 The following commands allow Octave to complete commands and file names | |
560 for you. | |
561 | |
562 @table @kbd | |
563 @item TAB | |
564 Attempt to do completion on the text before the cursor. Octave can | |
565 complete commands and variables. | |
566 | |
567 @item M-? | |
568 List the possible completions of the text before the cursor. | |
569 @end table | |
570 | |
571 @defvr {Built-in Variable} completion_append_char | |
572 The value of @code{completion_append_char} is used as the character to | |
573 append to successful command-line completion attempts. The default | |
574 value is @code{" "} (a single space). | |
575 @end defvr | |
576 | |
577 @deftypefn {Built-in Function} {} completion_matches (@var{hint}) | |
578 Generate possible completions given @var{hint}. | |
579 | |
580 This function is provided for the benefit of programs like Emacs which | |
581 might be controlling Octave and handling user input. The current | |
582 command number is not incremented when this function is called. This is | |
583 a feature, not a bug. | |
584 @end deftypefn | |
585 | |
586 @node Commands For History, Customizing the Prompt, Commands For Completion, Command Line Editing | |
587 @subsection Commands For Manipulating The History | |
588 @cindex command history | |
589 @cindex input history | |
590 @cindex history of commands | |
591 | |
592 Octave normally keeps track of the commands you type so that you can | |
593 recall previous commands to edit or execute them again. When you exit | |
594 Octave, the most recent commands you have typed, up to the number | |
595 specified by the variable @code{history_size}, are saved in a file. | |
596 When Octave starts, it loads an initial list of commands from the file | |
597 named by the variable @code{history_file}. | |
598 | |
599 Here are the commands for simple browsing and searching the history | |
600 list. | |
601 | |
602 @table @kbd | |
603 @item LFD | |
604 @itemx RET | |
605 Accept the line regardless of where the cursor is. If this line is | |
606 non-empty, add it to the history list. If this line was a history | |
607 line, then restore the history line to its original state. | |
608 | |
609 @item C-p | |
610 Move `up' through the history list. | |
611 | |
612 @item C-n | |
613 Move `down' through the history list. | |
614 | |
615 @item M-< | |
616 Move to the first line in the history. | |
617 | |
618 @item M-> | |
619 Move to the end of the input history, i.e., the line you are entering! | |
620 | |
621 @item C-r | |
622 Search backward starting at the current line and moving `up' through | |
623 the history as necessary. This is an incremental search. | |
624 | |
625 @item C-s | |
626 Search forward starting at the current line and moving `down' through | |
627 the the history as necessary. | |
628 @end table | |
629 | |
630 On most terminals, you can also use the arrow keys in place of @kbd{C-p} | |
631 and @kbd{C-n} to move through the history list. | |
632 | |
633 In addition to the keyboard commands for moving through the history | |
634 list, Octave provides three functions for viewing, editing, and | |
635 re-running chunks of commands from the history list. | |
636 | |
637 @deffn {Command} history options | |
638 If invoked with no arguments, @code{history} displays a list of commands | |
639 that you have executed. Valid options are: | |
640 | |
641 @table @code | |
642 @item -w file | |
643 Write the current history to the named file. If the name is omitted, | |
644 use the default history file (normally @file{~/.octave_hist}). | |
645 | |
646 @item -r file | |
647 Read the named file, replacing the current history list with its | |
648 contents. If the name is omitted, use the default history file | |
649 (normally @file{~/.octave_hist}). | |
650 | |
651 @item @var{N} | |
652 Only display the most recent @var{N} lines of history. | |
653 | |
654 @item -q | |
655 Don't number the displayed lines of history. This is useful for cutting | |
656 and pasting commands if you are using the X Window System. | |
657 @end table | |
658 | |
659 For example, to display the five most recent commands that you have | |
660 typed without displaying line numbers, use the command | |
661 @samp{history -q 5}. | |
662 @end deffn | |
663 | |
664 @deffn {Command} edit_history options | |
665 If invoked with no arguments, @code{edit_history} allows you to edit the | |
666 history list using the editor named by the variable @code{EDITOR}. The | |
667 commands to be edited are first copied to a temporary file. When you | |
668 exit the editor, Octave executes the commands that remain in the file. | |
669 It is often more convenient to use @code{edit_history} to define functions | |
670 rather than attempting to enter them directly on the command line. | |
671 By default, the block of commands is executed as soon as you exit the | |
672 editor. To avoid executing any commands, simply delete all the lines | |
673 from the buffer before exiting the editor. | |
674 | |
675 The @code{edit_history} command takes two optional arguments specifying | |
676 the history numbers of first and last commands to edit. For example, | |
58 the command | 677 the command |
59 | 678 |
60 @example | 679 @example |
61 help f | 680 edit_history 13 |
62 @end example | 681 @end example |
63 | 682 |
64 @noindent | 683 @noindent |
65 produces the output | 684 extracts all the commands from the 13th through the last in the history |
66 | 685 list. The command |
67 @smallexample | 686 |
68 usage: f (x, t) | 687 @example |
69 | 688 edit_history 13 169 |
70 This function defines the right-hand-side functions for a set of | 689 @end example |
71 nonlinear differential equations. | 690 |
72 @end smallexample | 691 @noindent |
73 | 692 only extracts commands 13 through 169. Specifying a larger number for |
74 Although it is possible to put comment lines into keyboard-composed | 693 the first command than the last command reverses the list of commands |
75 throw-away Octave programs, it usually isn't very useful, because the | 694 before placing them in the buffer to be edited. If both arguments are |
76 purpose of a comment is to help you or another person understand the | 695 omitted, the previous command in the history list is used. |
77 program at a later time. | 696 @end deffn |
78 | 697 |
79 @node Executable Octave Programs, Errors, Comments, Basics | 698 @deffn {Command} run_history |
699 Similar to @code{edit_history}, except that the editor is not invoked, | |
700 and the commands are simply executed as they appear in the history list. | |
701 @end deffn | |
702 | |
703 @defvr {Built-in Variable} EDITOR | |
704 A string naming the editor to use with the @code{edit_history} command. | |
705 If the environment variable @code{EDITOR} is set when Octave starts, its | |
706 value is used as the default. Otherwise, @code{EDITOR} is set to | |
707 @code{"vi"}. | |
708 @end defvr | |
709 | |
710 @defvr {Built-in Variable} history_file | |
711 This variable specifies the name of the file used to store command | |
712 history. The default value is @code{"~/.octave_hist"}, but may be | |
713 overridden by the environment variable @code{OCTAVE_HISTFILE}. | |
714 @end defvr | |
715 | |
716 @defvr {Built-in Variable} history_size | |
717 This variable specifies how many entries to store in the history file. | |
718 The default value is @code{1024}, but may be overridden by the | |
719 environment variable @code{OCTAVE_HISTSIZE}. | |
720 @end defvr | |
721 | |
722 @defvr {Built-in Variable} saving_history | |
723 If the value of @code{saving_history} is @code{"true"}, command entered | |
724 on the command line are saved in the file specified by the variable | |
725 @code{history_file}. | |
726 @end defvr | |
727 | |
728 @node Customizing the Prompt, Diary and Echo Commands, Commands For History, Command Line Editing | |
729 @subsection Customizing the Prompt | |
730 @cindex prompt customization | |
731 @cindex customizing the prompt | |
732 | |
733 The following variables are available for customizing the appearance of | |
734 the command-line prompts. Octave allows the prompt to be customized by | |
735 inserting a number of backslash-escaped special characters that are | |
736 decoded as follows: | |
737 | |
738 @table @samp | |
739 @item \t | |
740 The time. | |
741 | |
742 @item \d | |
743 The date. | |
744 | |
745 @item \n | |
746 Begins a new line by printing the equivalent of a carriage return | |
747 followed by a line feed. | |
748 | |
749 @item \s | |
750 The name of the program (usually just @code{octave}). | |
751 | |
752 @item \w | |
753 The current working directory. | |
754 | |
755 @item \W | |
756 The basename of the current working directory. | |
757 | |
758 @item \u | |
759 The username of the current user. | |
760 | |
761 @item \h | |
762 The hostname. | |
763 | |
764 @item \H | |
765 The hostname, up to the first `.'. | |
766 | |
767 @item \# | |
768 The command number of this command, counting from when Octave starts. | |
769 | |
770 @item \! | |
771 The history number of this command. This differs from @samp{\#} by the | |
772 number of commands in the history list when Octave starts. | |
773 | |
774 @item \$ | |
775 If the effective UID is 0, a #, otherwise a $. | |
776 | |
777 @item \nnn | |
778 The character whose character code in octal is @samp{nnn}. | |
779 | |
780 @item \\ | |
781 A backslash. | |
782 @end table | |
783 | |
784 @defvr {Built-in Variable} PS1 | |
785 The primary prompt string. When executing interactively, Octave | |
786 displays the primary prompt @code{PS1} when it is ready to read a | |
787 command. | |
788 | |
789 The default value of @code{PS1} is @code{"\s:\#> "}. To change it, use a | |
790 command like | |
791 | |
792 @example | |
793 octave:13> PS1 = "\\u@@\\H> " | |
794 @end example | |
795 | |
796 @noindent | |
797 which will result in the prompt @samp{boris@@kremvax> } for the user | |
798 @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two | |
799 backslashes are required to enter a backslash into a string. | |
800 @xref{Strings}. | |
801 @end defvr | |
802 | |
803 @defvr {Built-in Variable} PS2 | |
804 The secondary prompt string, which is printed when Octave is | |
805 expecting additional input to complete a command. For example, when | |
806 defining a function over several lines, Octave will print the value of | |
807 @code{PS1} at the beginning of each line after the first. The default | |
808 value of @code{PS2} is @code{"> "}. | |
809 @end defvr | |
810 | |
811 @defvr {Built-in Variable} PS4 | |
812 If Octave is invoked with the @code{--echo-input} option, the value of | |
813 @code{PS4} is printed before each line of input that is echoed. The | |
814 default value of @code{PS4} is @code{"+ "}. @xref{Invoking Octave}, for | |
815 a description of @code{--echo-input}. | |
816 @end defvr | |
817 | |
818 @node Diary and Echo Commands, , Customizing the Prompt, Command Line Editing | |
819 @subsection Diary and Echo Commands | |
820 @cindex diary of commands and output | |
821 @cindex command and ouput logs | |
822 @cindex logging commands and output | |
823 @cindex echoing executing commands | |
824 @cindex command echoing | |
825 | |
826 Octave's diary feature allows you to keep a log of all or part of an | |
827 interactive session by recording the input you type and the output that | |
828 Octave produces in a separate file. | |
829 | |
830 @deffn {Command} diary options | |
831 Create a list of all commands @emph{and} the output they produce, mixed | |
832 together just as you see them on your terminal. Valid options are: | |
833 | |
834 @table @code | |
835 @item on | |
836 Start recording your session in a file called @file{diary} in your | |
837 current working directory. | |
838 | |
839 @item off | |
840 Stop recording your session in the diary file. | |
841 | |
842 @item @var{file} | |
843 Record your session in the file named @var{file}. | |
844 @end table | |
845 | |
846 Without any arguments, @code{diary} toggles the current diary state. | |
847 @end deffn | |
848 | |
849 Sometimes it is useful to see the commands in a function or script as | |
850 they are being evaluated. This can be especially helpful for debugging | |
851 some kinds of problems. | |
852 | |
853 @deffn {Command} echo options | |
854 Control whether commands are displayed as they are executed. Valid | |
855 options are: | |
856 | |
857 @table @code | |
858 @item on | |
859 Enable echoing of commands as they are executed in script files. | |
860 | |
861 @item off | |
862 Disable echoing of commands as they are executed in script files. | |
863 | |
864 @item on all | |
865 Enable echoing of commands as they are executed in script files and | |
866 functions. | |
867 | |
868 @item off all | |
869 Disable echoing of commands as they are executed in script files and | |
870 functions. | |
871 @end table | |
872 | |
873 @noindent | |
874 If invoked without any arguments, @code{echo} toggles the current echo | |
875 state. | |
876 @end deffn | |
877 | |
878 @defvr {Built-in Variable} echo_executing_commands | |
879 This variable is may also be used to control the echo state. It may be | |
880 the sum of the following values: | |
881 | |
882 @table @asis | |
883 @item 1 | |
884 Echo commands read from script files. | |
885 | |
886 @item 2 | |
887 Echo commands from functions. | |
888 | |
889 @item 4 | |
890 Echo commands read from command line. | |
891 @end table | |
892 | |
893 More than one state can be active at once. For example, a value of 3 is | |
894 equivalent to the command @kbd{echo on all}. | |
895 | |
896 The value of @code{echo_executing_commands} is set by the @kbd{echo} | |
897 command and the command line option @code{--echo-input}. | |
898 @end defvr | |
899 | |
900 @node Errors, Executable Octave Programs, Command Line Editing, Getting Started | |
901 @section How Octave Reports Errors | |
902 @cindex error messages | |
903 @cindex messages, error | |
904 | |
905 There are two classes of errors that Octave produces when it encounters | |
906 input that it is unable to understand | |
907 an action. | |
908 | |
909 A @dfn{parse error} occurs if Octave cannot understand something you | |
910 have typed. For example, if you misspell a keyword, | |
911 | |
912 @example | |
913 octave:13> functon y = f (x) y = x^2; endfunction | |
914 @end example | |
915 | |
916 @noindent | |
917 Octave will respond immediately with a message like this: | |
918 | |
919 @example | |
920 parse error: | |
921 | |
922 functon y = f (x) y = x^2; endfunction | |
923 ^ | |
924 @end example | |
925 | |
926 @noindent | |
927 For most parse errors, Octave uses a caret (@samp{^}) to mark the point | |
928 on the line where it was unable to make sense of your input. In this | |
929 case, Octave generated an error message because the keyword | |
930 @code{function} was misspelled. Instead of seeing @samp{function f}, | |
931 Octave saw two consecutive variable names, which is invalid in this | |
932 context. It marked the error at the @code{y} because the first name by | |
933 itself was accepted as valid input. | |
934 | |
935 Another class of error message occurs occurs at evaluation time. These | |
936 errors are called @dfn{run-time errors}, or sometimes | |
937 @dfn{evaluation errors} because they occur when your program is being | |
938 @dfn{run}, or @dfn{evaluated}. For example, if after correcting the | |
939 mistake in the previous function definition, you type | |
940 | |
941 @example | |
942 octave:13> f () | |
943 @end example | |
944 | |
945 @noindent | |
946 Octave will respond with | |
947 | |
948 @example | |
949 @group | |
950 error: `x' undefined near line 1 column 24 | |
951 error: evaluating expression near line 1, column 24 | |
952 error: evaluating assignment expression near line 1, column 22 | |
953 error: called from `f' | |
954 @end group | |
955 @end example | |
956 | |
957 This error message has several parts, and gives you quite a bit of | |
958 information to help you locate the source of the error. The messages | |
959 are generated from the point of the innermost error, and provide a | |
960 traceback of enclosing expressions and function calls. | |
961 | |
962 In the example above, the first line indicates that a variable named | |
963 @samp{x} was found to be undefined near line 1 and column 24 of some | |
964 function or expression. For errors occurring within functions, lines | |
965 from the beginning of the file containing the function definition. For | |
966 errors occurring at the top level, the line number indicates the input | |
967 line number, which is usually displayed in the prompt string. | |
968 | |
969 The second and third lines in the example indicate that the error | |
970 occurred within an assignment expression, and the last line of the error | |
971 message indicates that the error occurred within the function @samp{f}. | |
972 If the function @samp{f} had been called from another function, for | |
973 example, @samp{g}, the list of errors would have ended with one more | |
974 line: | |
975 | |
976 @example | |
977 error: called from `g' | |
978 @end example | |
979 | |
980 These lists of function calls usually make it fairly easy to trace the | |
981 path your program took before the error occurred, and to correct the | |
982 error before trying again. | |
983 | |
984 @node Executable Octave Programs, Comments, Errors, Getting Started | |
80 @section Executable Octave Programs | 985 @section Executable Octave Programs |
81 @cindex executable scripts | 986 @cindex executable scripts |
82 @cindex scripts | 987 @cindex scripts |
83 @cindex self contained programs | 988 @cindex self contained programs |
84 @cindex program, self contained | 989 @cindex program, self contained |
94 the following lines: | 999 the following lines: |
95 | 1000 |
96 @example | 1001 @example |
97 @group | 1002 @group |
98 #! @value{OCTAVEHOME}/bin/octave -qf | 1003 #! @value{OCTAVEHOME}/bin/octave -qf |
99 | |
100 # a sample Octave program | 1004 # a sample Octave program |
101 printf ("Hello, world!\n"); | 1005 printf ("Hello, world!\n"); |
102 @end group | 1006 @end group |
103 @end example | 1007 @end example |
104 | 1008 |
135 Self-contained Octave scripts are useful when you want to write a | 1039 Self-contained Octave scripts are useful when you want to write a |
136 program which users can invoke without knowing that the program is | 1040 program which users can invoke without knowing that the program is |
137 written in the Octave language. | 1041 written in the Octave language. |
138 | 1042 |
139 If you invoke an executable Octave script with command line arguments, | 1043 If you invoke an executable Octave script with command line arguments, |
140 the arguments are available in the built-in variable @var{argv}. | 1044 the arguments are available in the built-in variable @code{argv}. |
141 @xref{Command Line Options}. For example, the following program will | 1045 @xref{Command Line Options}. For example, the following program will |
142 reproduce the command line that is used to execute it. | 1046 reproduce the command line that is used to execute it. |
143 | 1047 |
144 @example | 1048 @example |
145 @group | 1049 @group |
146 #! @value{OCTAVEHOME}/bin/octave -qf | 1050 #! @value{OCTAVEHOME}/bin/octave -qf |
147 | |
148 printf ("%s", program_name); | 1051 printf ("%s", program_name); |
149 for i = 1:nargin | 1052 for i = 1:nargin |
150 printf (" %s", argv(i,:)); | 1053 printf (" %s", argv(i,:)); |
151 endfor | 1054 endfor |
152 printf ("\n"); | 1055 printf ("\n"); |
153 @end group | 1056 @end group |
154 @end example | 1057 @end example |
155 | 1058 |
156 @node Errors, Help, Executable Octave Programs, Basics | 1059 @node Comments, , Executable Octave Programs, Getting Started |
157 @section Errors | 1060 @section Comments in Octave Programs |
158 | 1061 @cindex @samp{#} |
159 There are two classes of errors that Octave produces when it encounters | 1062 @cindex @samp{%} |
160 input that it is unable to understand | 1063 @cindex comments |
161 an action. | 1064 @cindex use of comments |
162 | 1065 @cindex documenting Octave programs |
163 A @dfn{parse error} occurs if Octave cannot understand something you | 1066 @cindex programs |
164 have typed. For example, if you misspell a keyword, | 1067 |
165 | 1068 A @dfn{comment} is some text that is included in a program for the sake |
166 @example | 1069 of human readers, and that is not really part of the program. Comments |
167 octave:13> functon y = f (x) y = x^2; endfunction | 1070 can explain what the program does, and how it works. Nearly all |
168 @end example | 1071 programming languages have provisions for comments, because programs are |
169 | 1072 typically hard to understand without them. |
170 @noindent | 1073 |
171 Octave will respond immediately with a message like this: | 1074 In the Octave language, a comment starts with either the sharp sign |
172 | 1075 character, @samp{#}, or the percent symbol @samp{%} and continues to the |
173 @example | 1076 end of the line. The Octave interpreter ignores the rest of a |
174 parse error: | 1077 line following a sharp sign or percent symbol. For example, we could |
175 | 1078 have put the following into the function @code{f}: |
176 functon y = f (x) y = x^2; endfunction | |
177 ^ | |
178 @end example | |
179 | |
180 @noindent | |
181 For most parse errors, Octave uses a caret (@samp{^}) to mark the point | |
182 on the line where it was unable to make sense of your input. In this | |
183 case, Octave generated an error message because the keyword | |
184 @code{function} was misspelled. Instead of seeing @samp{function f}, | |
185 Octave saw two consecutive variable names, which is invalid in this | |
186 context. It marked the error at the @code{y} because the first name by | |
187 itself was accepted as valid input. | |
188 | |
189 Another class of error message occurs occurs at evaluation time. These | |
190 errors are called @dfn{run-time errors}, or sometimes | |
191 @dfn{evaluation errors} because they occur when your program is being | |
192 @dfn{run}, or @dfn{evaluated}. For example, if after correcting the | |
193 mistake in the previous function definition, you type | |
194 | |
195 @example | |
196 octave:13> f () | |
197 @end example | |
198 | |
199 @noindent | |
200 Octave will respond with | |
201 | 1079 |
202 @example | 1080 @example |
203 @group | 1081 @group |
204 error: `x' undefined near line 1 column 24 | 1082 function xdot = f (x, t) |
205 error: evaluating expression near line 1, column 24 | 1083 |
206 error: evaluating assignment expression near line 1, column 22 | 1084 # usage: f (x, t) |
207 error: called from `f' | 1085 # |
1086 # This function defines the right hand | |
1087 # side functions for a set of nonlinear | |
1088 # differential equations. | |
1089 | |
1090 r = 0.25; | |
1091 @dots{} | |
1092 endfunction | |
208 @end group | 1093 @end group |
209 @end example | 1094 @end example |
210 | 1095 |
211 This error message has several parts, and gives you quite a bit of | 1096 The @code{help} command (@pxref{Getting Help}) is able to find the first |
212 information to help you locate the source of the error. The messages | 1097 block of comments in a function (even those that are composed directly |
213 are generated from the point of the innermost error, and provide a | 1098 on the command line). This means that users of Octave can use the same |
214 traceback of enclosing expressions and function calls. | 1099 commands to get help for built-in functions, and for functions that you |
215 | 1100 have defined. For example, after defining the function @code{f} above, |
216 In the example above, the first line indicates that a variable named | 1101 the command @kbd{help f} produces the output |
217 @samp{x} was found to be undefined near line 1 and column 24 of some | 1102 |
218 function or expression. For errors occurring within functions, lines | 1103 @example |
219 from the beginning of the file containing the function definition. For | 1104 @group |
220 errors occurring at the top level, the line number indicates the input | 1105 usage: f (x, t) |
221 line number, which is usually displayed in the prompt string. | 1106 |
222 | 1107 This function defines the right hand |
223 The second and third lines in the example indicate that the error | 1108 side functions for a set of nonlinear |
224 occurred within an assignment expression, and the last line of the error | 1109 differential equations. |
225 message indicates that the error occurred within the function @samp{f}. | 1110 @end group |
226 If the function @samp{f} had been called from another function, for | 1111 @end example |
227 example, @samp{g}, the list of errors would have ended with one more | 1112 |
228 line: | 1113 Although it is possible to put comment lines into keyboard-composed |
229 | 1114 throw-away Octave programs, it usually isn't very useful, because the |
230 @example | 1115 purpose of a comment is to help you or another person understand the |
231 error: called from `g' | 1116 program at a later time. |
232 @end example | 1117 |
233 | |
234 These lists of function calls usually make it fairly easy to trace the | |
235 path your program took before the error occurred, and to correct the | |
236 error before trying again. | |
237 | |
238 @node Help, Command Line Editing, Errors, Basics | |
239 @section Help | |
240 | |
241 @deffn {Command} help | |
242 Octave's @code{help} command can be used to print brief usage-style | |
243 messages, or to display information directly from an on-line version of | |
244 the printed manual, using the GNU Info browser. If invoked without any | |
245 arguments, @code{help} prints a list of all the available operators, | |
246 functions, and built-in variables. If the first argument is @code{-i}, | |
247 the @code{help} command searches the index of the on-line version of | |
248 this manual for the given topics. | |
249 | |
250 For example, the command | |
251 | |
252 @example | |
253 help help | |
254 @end example | |
255 | |
256 @noindent | |
257 prints a short message describing the @code{help} command, and | |
258 | |
259 @example | |
260 help -i help | |
261 @end example | |
262 | |
263 @noindent | |
264 starts the GNU Info browser at this node in the on-line version of the | |
265 manual. | |
266 @end deffn | |
267 | |
268 The help command can give you information about operators, but not the | |
269 comma and semicolons that are used as command separators. To get help | |
270 for those, you must type @code{help comma} or @code{help semicolon}. | |
271 | |
272 @defvr {Built-in Variable} INFO_FILE | |
273 The variable @code{INFO_FILE} names the location of the Octave info file. | |
274 The default value is @code{"@value{OCTAVEHOME}/info/octave.info"}. | |
275 @end defvr | |
276 | |
277 @defvr {Built-in Variable} INFO_PROGRAM | |
278 The variable @code{INFO_PROGRAM} names the info program to run. Its | |
279 initial value is | |
280 @code{@value{OCTAVEHOME}/libexec/octave/VERSION/exec/ARCH/info}, but | |
281 that value can be overridden by the environment variable | |
282 @code{OCTAVE_INFO_PROGRAM}, or the command line argument | |
283 @code{--info-program NAME}, or by setting the value of | |
284 @code{INFO_PROGRAM} in a startup script. | |
285 @end defvr | |
286 | |
287 @defvr {Built-in Variable} suppress_verbose_help_message | |
288 If the value of @code{suppress_verbose_help_message} is nonzero, Octave | |
289 will not add additional help information to the end of the output from | |
290 the @code{help} command and usage messages for built-in commands. | |
291 @end defvr | |
292 | |
293 @node Command Line Editing, Command History Functions, Help, Basics | |
294 @section Command Line Editing | |
295 | |
296 @defvr {Built-in Variable} PS1 | |
297 The primary prompt string. When executing interactively, Octave | |
298 displays the primary prompt @code{PS1} when it is ready to read a | |
299 command. Octave allows the prompt to be customized by inserting a | |
300 number of backslash-escaped special characters that are decoded as | |
301 follows: | |
302 | |
303 @table @samp | |
304 @item \t | |
305 The time. | |
306 @item \d | |
307 The date. | |
308 @item \n | |
309 Begins a new line by printing the equivalent of a carriage return | |
310 followed by a line feed. | |
311 @item \s | |
312 The name of the program (usually just @code{octave}). | |
313 @item \w | |
314 The current working directory. | |
315 @item \W | |
316 The basename of the current working directory. | |
317 @item \u | |
318 The username of the current user. | |
319 @item \h | |
320 The hostname. | |
321 @item \H | |
322 The hostname, up to the first `.'. | |
323 @item \# | |
324 The command number of this command, counting from when Octave starts. | |
325 @item \! | |
326 The history number of this command. This differs from @samp{\#} by the | |
327 number of commands in the history list when Octave starts. | |
328 @item \$ | |
329 If the effective UID is 0, a #, otherwise a $. | |
330 @item \nnn | |
331 The character whose character code in octal is @samp{nnn}. | |
332 @item \\ | |
333 A backslash. | |
334 @end table | |
335 | |
336 The default value of @code{PS1} is @code{"\s:\#> "}. To change it, use a | |
337 command like | |
338 | |
339 @example | |
340 octave:13> PS1 = "\\u@@\\H> " | |
341 @end example | |
342 | |
343 @noindent | |
344 which will result in the prompt @samp{boris@@kremvax> } for the user | |
345 @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two | |
346 backslashes are required to enter a backslash into a string. | |
347 @xref{String Constants}. | |
348 @end defvr | |
349 | |
350 @defvr {Built-in Variable} PS2 | |
351 The secondary prompt string, which is printed when Octave is | |
352 expecting additional input to complete a command. For example, when | |
353 defining a function over several lines, Octave will print the value of | |
354 @code{PS1} at the beginning of each line after the first. Octave allows | |
355 @code{PS2} to be customized in the same way as @code{PS1}. The default | |
356 value of @code{PS2} is @code{"> "}. | |
357 @end defvr | |
358 | |
359 @defvr {Built-in Variable} PS4 | |
360 If Octave is invoked with the @code{--echo-input} option, the value of | |
361 @code{PS4} is printed before each line of input that is echoed. Octave | |
362 allows @code{PS4} to be customized in the same way as @code{PS1}. The | |
363 default value of @code{PS4} is @code{"+ "}. @xref{Invoking Octave}, for | |
364 a description of @code{--echo-input}. | |
365 @end defvr | |
366 | |
367 @defvr {Built-in Variable} completion_append_char | |
368 The value of @code{completion_append_char} is used as the character to | |
369 append to successful command-line completion attempts. The default | |
370 value is @code{" "} (a single space). | |
371 @end defvr | |
372 | |
373 @node Command History Functions, , Command Line Editing, Basics | |
374 @section Command History Functions | |
375 | |
376 Octave provides three functions for viewing, editing, and re-running | |
377 chunks of commands from the history list. | |
378 | |
379 @deffn {Command} history options | |
380 If invoked with no arguments, @code{history} displays a list of commands | |
381 that you have executed. Valid options are: | |
382 | |
383 @table @code | |
384 @item -w file | |
385 Write the current history to the named file. If the name is omitted, | |
386 use the default history file (normally @file{~/.octave_hist}). | |
387 | |
388 @item -r file | |
389 Read the named file, replacing the current history list with its | |
390 contents. If the name is omitted, use the default history file | |
391 (normally @file{~/.octave_hist}). | |
392 | |
393 @item N | |
394 Only display the most recent @code{N} lines of history. | |
395 | |
396 @item -q | |
397 Don't number the displayed lines of history. This is useful for cutting | |
398 and pasting commands if you are using the X Window System. | |
399 @end table | |
400 | |
401 For example, to display the five most recent commands that you have | |
402 typed without displaying line numbers, use the command | |
403 @samp{history -q 5}. | |
404 @end deffn | |
405 | |
406 @deffn {Command} edit_history options | |
407 If invoked with no arguments, @code{edit_history} allows you to edit the | |
408 history list using the editor named by the variable @code{EDITOR}. The | |
409 commands to be edited are first copied to a temporary file. When you | |
410 exit the editor, Octave executes the commands that remain in the file. | |
411 It is often more convenient to use @code{edit_history} to define functions | |
412 rather than attempting to enter them directly on the command line. | |
413 By default, the block of commands is executed as soon as you exit the | |
414 editor. To avoid executing any commands, simply delete all the lines | |
415 from the buffer before exiting the editor. | |
416 | |
417 The @code{edit_history} command takes two optional arguments specifying | |
418 the history numbers of first and last commands to edit. For example, | |
419 the command | |
420 | |
421 @example | |
422 edit_history 13 | |
423 @end example | |
424 | |
425 @noindent | |
426 extracts all the commands from the 13th through the last in the history | |
427 list. The command | |
428 | |
429 @example | |
430 edit_history 13 169 | |
431 @end example | |
432 | |
433 @noindent | |
434 only extracts commands 13 through 169. Specifying a larger number for | |
435 the first command than the last command reverses the list of commands | |
436 before placing them in the buffer to be edited. If both arguments are | |
437 omitted, the previous command in the history list is used. | |
438 @end deffn | |
439 | |
440 @defvr {Built-in Variable} EDITOR | |
441 A string naming the editor to use with the @code{edit_history} command. | |
442 If the environment variable @code{EDITOR} is set when Octave starts, its | |
443 value is used as the default. Otherwise, @code{EDITOR} is set to | |
444 @code{"vi"}. | |
445 @end defvr | |
446 | |
447 @deffn {Command} run_history | |
448 Similar to @code{edit_history}, except that the editor is not invoked, | |
449 and the commands are simply executed as they appear in the history list. | |
450 @end deffn | |
451 | |
452 @defvr {Built-in Variable} history_file | |
453 This variable specifies the name of the file used to store command | |
454 history. The default value is @code{"~/.octave_hist"}, but may be | |
455 overridden by the environment variable @code{OCTAVE_HISTFILE}. | |
456 @end defvr | |
457 | |
458 @defvr {Built-in Variable} history_size | |
459 This variable specifies how many entries to store in the history file. | |
460 The default value is @code{1024}, but may be overridden by the | |
461 environment variable @code{OCTAVE_HISTSIZE}. | |
462 @end defvr | |
463 | |
464 @defvr {Built-in Variable} saving_history | |
465 If the value of @code{saving_history} is @code{"true"}, command entered | |
466 on the command line are saved in the file specified by the variable | |
467 @code{history_file}. | |
468 @end defvr | |
469 | |
470 @deffn {Command} diary | |
471 The @code{diary} command allows you to create a list of all commands | |
472 @emph{and} the output they produce, mixed together just as you see them | |
473 on your terminal. | |
474 | |
475 For example, the command | |
476 | |
477 @example | |
478 diary on | |
479 @end example | |
480 | |
481 @noindent | |
482 tells Octave to start recording your session in a file called | |
483 @file{diary} in your current working directory. To give Octave the name | |
484 of the file write to, use the a command like | |
485 | |
486 @example | |
487 diary my-diary.txt | |
488 @end example | |
489 | |
490 @noindent | |
491 Then Octave will write all of your commands to the file | |
492 @file{my-diary.txt}. | |
493 | |
494 To stop recording your session, use the command | |
495 | |
496 @example | |
497 diary off | |
498 @end example | |
499 | |
500 @noindent | |
501 Without any arguments, @code{diary} toggles the current diary state. | |
502 @end deffn | |
503 | |
504 @deffn {Command} echo options | |
505 Control whether commands are displayed as they are executed. Valid | |
506 options are: | |
507 | |
508 @table @code | |
509 @item on | |
510 Enable echoing of commands as they are executed in script files. | |
511 | |
512 @item off | |
513 Disable echoing of commands as they are executed in script files. | |
514 | |
515 @item on all | |
516 Enable echoing of commands as they are executed in script files and | |
517 functions. | |
518 | |
519 @item off all | |
520 Disable echoing of commands as they are executed in script files and | |
521 functions. | |
522 @end table | |
523 | |
524 @noindent | |
525 If invoked without any arguments, @code{echo} toggles the current echo | |
526 state. | |
527 @end deffn | |
528 | |
529 @defvr {Built-in Variable} echo_executing_commands | |
530 @end defvr |