1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>shell</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>shell</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
shell
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
The Erlang Shell
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P>The module <CODE>shell</CODE> implements an Erlang shell.
<P>The shell is a user interface program
for entering expression sequences. The expressions are
evaluated and a value is returned.
A history mechanism saves previous commands and their
values, which can then be incorporated in later commands.
How many commands and results to save can be determined by the user,
either interactively, by calling <CODE>shell:history/1</CODE> and
<CODE>shell:results/1</CODE>, or by setting the application configuration
parameters <CODE>shell_history_length</CODE> and
<CODE>shell_saved_results</CODE> for the application <CODE>stdlib</CODE>.
<P>Variable bindings, and local process dictionary changes
which are generated in user expressions, are preserved and the variables
can be used in later commands to access their values. The
bindings can also be forgotten so the variables can be re-used.
<P>The special shell commands all have the syntax of (local)
function calls. They are evaluated as
normal function calls and many commands can be used in one
expression sequence.
<P>If a command (local function call) is not recognized by the
shell, an attempt is first made to find the function in the
module <CODE>user_default</CODE>, where customized local commands
can be placed. If found, then the function is evaluated.
Otherwise, an attempt is made to evaluate the function in the
module <CODE>shell_default</CODE>. The module
<CODE>user_default</CODE> must be explicitly loaded.
<P>The shell also permits the user to start multiple concurrent
jobs. A job can be regarded as a set of processes which can
communicate with the shell.
<P>There is some support for reading and printing records in
the shell. During compilation record expressions are translated
to tuple expressions. In runtime it is not known whether a tuple
actually represents a record. Nor are the record definitions
used by compiler available at runtime. So in order to read the
record syntax and print tuples as records when possible, record
definitions have to be maintained by the shell itself. The shell
commands for reading, defining, forgetting, listing, and
printing records are described below. Note that each job has its
own set of record definitions. To facilitate matters record
definitions in the modules <CODE>shell_default</CODE> and
<CODE>user_default</CODE> (if loaded) are read each time a new job is
started. For instance, adding the line
<PRE>
-include_lib("kernel/include/file.hrl").
</PRE>
<P>to <CODE>user_default</CODE> makes the definition of <CODE>file_info</CODE>
readily available in the shell.
<P>The shell runs in two modes:
<P>
<UL>
<LI>
<CODE>Normal (possibly restricted)</CODE> mode, in which
commands can be edited and expressions evaluated.
</LI>
<LI>
Job Control Mode <CODE>JCL</CODE>, in which jobs can be
started, killed, detached and connected.
</LI>
</UL>
<P>Only the currently connected job can 'talk' to the shell.
</DIV>
<H3>Shell Commands</H3>
<DIV CLASS=REFBODY>
<P>
<DL>
<DT>
<CODE>b()</CODE>
</DT>
<DD>
Prints the current variable bindings.
<BR>
</DD>
<DT>
<CODE>f()</CODE>
</DT>
<DD>
Removes all variable bindings.
<BR>
</DD>
<DT>
<CODE>f(X)</CODE>
</DT>
<DD>
Removes the binding of variable <CODE>X</CODE>.
<BR>
</DD>
<DT>
<CODE>h()</CODE>
</DT>
<DD>
Prints the history list.
<BR>
</DD>
<DT>
<CODE>history(N)</CODE>
</DT>
<DD>
Sets the number of previous commands to keep in the
history list to <CODE>N</CODE>. The previous number is returned.
The default number is 20.
<BR>
</DD>
<DT>
<CODE>results(N)</CODE>
</DT>
<DD>
Sets the number of results from previous commands to keep in
the history list to <CODE>N</CODE>. The previous number is returned.
The default number is 20.
<BR>
</DD>
<DT>
<CODE>e(N)</CODE>
</DT>
<DD>
Repeats the command <CODE>N</CODE>, if <CODE>N</CODE> is positive. If
it is negative, the <CODE>N</CODE>th previous command is repeated
(i.e., <CODE>e(-1)</CODE> repeats the previous command).
<BR>
</DD>
<DT>
<CODE>v(N)</CODE>
</DT>
<DD>
Uses the return value of the command <CODE>N</CODE> in the
current command, if <CODE>N</CODE> is positive. If it is negative,
the return value of the <CODE>N</CODE>th previous command is used
(i.e., <CODE>v(-1)</CODE> uses the value of the previous command).
<BR>
</DD>
<DT>
<CODE>help()</CODE>
</DT>
<DD>
Evaluates <CODE>shell_default:help()</CODE>.
<BR>
</DD>
<DT>
<CODE>c(File)</CODE>
</DT>
<DD>
Evaluates <CODE>shell_default:c(File)</CODE>. This compiles
and loads code in <CODE>File</CODE> and purges old versions of
code, if necessary. Assumes that the file and module names
are the same.
<BR>
</DD>
<DT>
<CODE>rd(RecordName, RecordDefinition)</CODE>
</DT>
<DD>
Defines a record in the shell. <CODE>RecordName</CODE> is
an atom and <CODE>RecordDefinition</CODE> lists the field names
and the default values. Usually record definitions are made
known to the shell by use of the <CODE>rr</CODE> commands
described below, but sometimes it is handy to define records
on the fly.
<BR>
</DD>
<DT>
<CODE>rf()</CODE>
</DT>
<DD>
Removes all record definitions, then reads record
definitions from the modules <CODE>shell_default</CODE> and
<CODE>user_default</CODE> (if loaded). Returns the names of the
records defined.
<BR>
</DD>
<DT>
<CODE>rf(RecordNames)</CODE>
</DT>
<DD>
Removes selected record definitions.
<CODE>RecordNames</CODE> is a record name or a list of record names.
Use <CODE>'_'</CODE> to remove all record definitions.
<BR>
</DD>
<DT>
<CODE>rl()</CODE>
</DT>
<DD>
Prints all record definitions.
<BR>
</DD>
<DT>
<CODE>rl(RecordNames)</CODE>
</DT>
<DD>
Prints selected record definitions.
<CODE>RecordNames</CODE> is a record name or a list of record names.
<BR>
</DD>
<DT>
<CODE>rp(Term)</CODE>
</DT>
<DD>
Prints a term using the record definitions known to the
shell. All of <CODE>Term</CODE> is printed; the depth is not
limited as is the case when a return value is printed.
<BR>
</DD>
<DT>
<CODE>rr(Module)</CODE>
</DT>
<DD>
Reads record definitions from a module's BEAM file. If
there are no record definitions in the BEAM file, the
source file is located and read instead. Returns the names
of the record definitions read. <CODE>Module</CODE> is an atom.
<BR>
</DD>
<DT>
<CODE>rr(Wildcard)</CODE>
</DT>
<DD>
Reads record definitions from files. Existing
definitions of any of the record names read are replaced.
<CODE>Wildcard</CODE> is a wildcard string as defined in
<CODE>filelib(3)</CODE> but not an atom.
<BR>
</DD>
<DT>
<CODE>rr(WildcardOrModule, RecordNames)</CODE>
</DT>
<DD>
Reads record definitions from files but
discards record names not mentioned in <CODE>RecordNames</CODE> (a
record name or a list of record names).
<BR>
</DD>
<DT>
<CODE>rr(WildcardOrModule, RecordNames, Options)</CODE>
</DT>
<DD>
Reads record definitions from files. The compiler
options <CODE>{i,Dir}</CODE>, <CODE>{d,Macro}</CODE>, and
<CODE>{d,Macro,Value}</CODE> are recognized and used
for setting up the include path and macro definitions. Use
<CODE>'_'</CODE> as value of <CODE>RecordNames</CODE> to read all record
definitions.
<BR>
</DD>
</DL>
</DIV>
<H3>Example</H3>
<DIV CLASS=REFBODY>
<P>The following example is a long dialogue with the shell. Commands
starting with <CODE>></CODE> are inputs to the shell. All other lines
are output from the shell. All commands in this example are explained at the end of the dialogue.
.
<PRE>
strider 1> <STRONG>erl</STRONG>
Erlang (BEAM) emulator version 5.3 [hipe] [threads:0]
Eshell V5.3 (abort with ^G)
1><STRONG> Str = "abcd".</STRONG>
"abcd"
2> <STRONG>L = length(Str).</STRONG>
4
3> <STRONG>Descriptor = {L, list_to_atom(Str)}.</STRONG>
{4,abcd}
4> <STRONG>L.</STRONG>
4
5> <STRONG>b().</STRONG>
Descriptor = {4,abcd}
L = 4
Str = "abcd"
ok
6> <STRONG>f(L).</STRONG>
ok
7> <STRONG>b().</STRONG>
Descriptor = {4,abcd}
Str = "abcd"
ok
8> <STRONG>f(L).</STRONG>
** 1: variable 'L' is unbound **
9> <STRONG>{L, _} = Descriptor.</STRONG>
{4,abcd}
10> <STRONG>L.</STRONG>
4
11> <STRONG>{P, Q, R} = Descriptor.</STRONG>
** exited: {{badmatch,{4,abcd}},[{erl_eval,expr,3}]} **
12> <STRONG>P.</STRONG>
** 1: variable 'P' is unbound **
13> <STRONG>Descriptor.</STRONG>
{4,abcd}
14><STRONG> {P, Q} = Descriptor.</STRONG>
{4,abcd}
15> <STRONG>P.</STRONG>
4
16> <STRONG>f().</STRONG>
ok
17> <STRONG>put(aa, hello).</STRONG>
undefined
18> <STRONG>get(aa).</STRONG>
hello
19> <STRONG>Y = test1:demo(1).</STRONG>
11
20> <STRONG>get().</STRONG>
[{aa,worked}]
21> <STRONG>put(aa, hello).</STRONG>
worked
22> <STRONG>Z = test1:demo(2).</STRONG>
=ERROR REPORT==== 19-Feb-2003::10:04:14 ===
Error in process <0.40.0> with exit value: {{badmatch,1},[{test1,demo,1},
{erl_eval,expr,4},{shell,eval_loop,2}]}
** exited: {{badmatch,1},
[{test1,demo,1},{erl_eval,expr,4},{shell,eval_loop,2}]} **
23> <STRONG>Z.</STRONG>
** 1: variable 'Z' is unbound **
24> <STRONG>get(aa).</STRONG>
hello
25> <STRONG>erase(), put(aa, hello).</STRONG>
undefined
26> <STRONG>spawn(test1, demo, [1]).</STRONG>
<0.57.0>
27> <STRONG>get(aa).</STRONG>
hello
28> <STRONG>io:format("hello hello\n").</STRONG>
hello hello
ok
29> <STRONG>e(28).</STRONG>
hello hello
ok
30> <STRONG>v(28).</STRONG>
ok
31> <STRONG>c(ex).</STRONG>
{ok,ex}
32> <STRONG>rr(ex).</STRONG>
[rec]
33> <STRONG>rl(rec).</STRONG>
-record(rec, {a,
b = val()}).
ok
34> <STRONG>#rec{}.</STRONG>
** exited: {undef,[{shell_default,val,[]},
{erl_eval,do_apply,5},
{erl_eval,expr_list,6},
{erl_eval,expr,5},
{shell,eval_loop,2}]} **
35> <STRONG>#rec{b = 3}.</STRONG>
{rec,undefined,3}
36> <STRONG>rp(v(-1)).</STRONG>
#rec{a = undefined,
b = 3}
ok
37> <STRONG>rd(rec, {f = orddict:new()}).</STRONG>
rec
38> <STRONG>rp(#rec{}).</STRONG>
#rec{f = []}
ok
39> <STRONG>rd(rec, {c}), A.</STRONG>
** 1: variable 'A' is unbound **
40> <STRONG>rp(#rec{}).</STRONG>
#rec{c = undefined}
ok
41> <STRONG>test1:loop(0).</STRONG>
Hello Number: 0
Hello Number: 1
Hello Number: 2
Hello Number: 3
User switch command
--> i
--> c
.
.
.
Hello Number: 3374
Hello Number: 3375
Hello Number: 3376
Hello Number: 3377
Hello Number: 3378
** exited: killed **
42> <STRONG>halt().</STRONG>
strider 2>
</PRE>
</DIV>
<H3>Comments</H3>
<DIV CLASS=REFBODY>
<P>Command 1 sets the variable <CODE>Str</CODE> to the string
<CODE>"abcd"</CODE>.
<P>Command 2 sets <CODE>L</CODE> to the length of the string evaluating
the BIF <CODE>atom_to_list</CODE>.
<P>Command 3 builds the tuple <CODE>Descriptor</CODE>.
<P>Command 4 prints the value of the variable <CODE>L</CODE>.
<P>Command 5 evaluates the internal shell command <CODE>b()</CODE>, which
is an abbreviation of "bindings". This prints
the current shell variables and their bindings. The <CODE>ok</CODE> at
the end is the return value of the <CODE>b()</CODE> function.
<P>Command 6 <CODE>f(L)</CODE> evaluates the internal shell command
<CODE>f(L)</CODE> (abbreviation of "forget"). The value of the variable
<CODE>L</CODE> is removed.
<P>Command 7 prints the new bindings.
<P>Command 8 shows that <CODE>L</CODE> is no longer bound to a value.
<P>Command 9 performs a pattern matching operation on
<CODE>Descriptor</CODE>, binding a new value to <CODE>L</CODE>.
<P>Command 10 prints the current value of <CODE>L</CODE>.
<P>Command 11 tries to match <CODE>{P, Q, R}</CODE> against
<CODE>Descriptor</CODE> which is <CODE>{4, abc}</CODE>.
The match fails and none of the new variables become bound.
The printout starting with "<CODE>** exited:</CODE>" is not the value
of the expression (the expression had no value because its
evaluation failed), but rather a warning printed by the system
to inform the user that an error has occurred. The values of the
other variables (<CODE>L</CODE>, <CODE>Str</CODE>, etc.) are unchanged.
<P>Commands 12 and 13 show that <CODE>P</CODE> is unbound because the
previous command failed, and that <CODE>Descriptor</CODE> has not
changed.
<P>Commands 14 and 15 show a correct match where <CODE>P</CODE> and
<CODE>Q</CODE> are bound.
<P>Command 16 clears all bindings.
<P>The next few commands assume that <CODE>test1:demo(X)</CODE> is
defined in the following way:
<PRE>
demo(X) ->
put(aa, worked),
X = 1,
X + 10.
</PRE>
<P>Commands 17 and 18 set and inspect the value of the item
<CODE>aa</CODE> in the process dictionary.
<P>Command 19 evaluates <CODE>test1:demo(1)</CODE>. The evaluation
succeeds and the changes made in the process dictionary become
visible to the shell. The new value of the dictionary item
<CODE>aa</CODE> can be seen in command 20.
<P>Commands 21 and 22 change the value of the dictionary item
<CODE>aa</CODE> to <CODE>hello</CODE> and call <CODE>test1:demo(2)</CODE>. Evaluation
fails and the changes made to the dictionary in
<CODE>test1:demo(2)</CODE>, before the error occurred, are discarded.
<P>Commands 23 and 24 show that <CODE>Z</CODE> was not bound and that the
dictionary item <CODE>aa</CODE> has retained its original value.
<P>Commands 25, 26 and 27 show the effect of evaluating
<CODE>test1:demo(1)</CODE> in the background. In this case, the
expression is evaluated in a newly spawned process. Any
changes made in the process dictionary are local to the newly
spawned process and therefore not visible to the shell.
<P>Commands 28, 29 and 30 use the history facilities of the shell.
<P>Command 29 is <CODE>e(28)</CODE>. This re-evaluates command
28. Command 30 is <CODE>v(28)</CODE>. This uses the value (result) of
command 28. In the cases of a pure function (a function
with no side effects), the result is the same. For a function
with side effects, the result can be different.
<P>The next few commands show some record manipulation. It is
assumed that <CODE>ex.erl</CODE> defines a record like this:
<PRE>
-record(rec, {a, b = val()}).
val() ->
3.
</PRE>
<P>Commands 31 and 32 compiles the file <CODE>ex.erl</CODE> and reads
the record definitions in <CODE>ex.beam</CODE>. If the compiler did not
output any record definitions on the BEAM file, <CODE>rr(ex)</CODE>
tries to read record definitions from the source file instead.
<P>Command 33 prints the definition of the record named
<CODE>rec</CODE>.
<P>Command 34 tries to create a <CODE>rec</CODE> record, but fails
since the function <CODE>val/0</CODE> is undefined. Command 35 shows
the workaround: explicitly assign values to record fields that
cannot otherwise be initialized.
<P>Command 36 prints the newly created record using record
definitions maintained by the shell.
<P>Command 37 defines a record directly in the shell. The
definition replaces the one read from the file <CODE>ex.beam</CODE>.
<P>Command 38 creates a record using the new definition, and
prints the result.
<P>Command 39 and 40 show that record definitions are updated
as side effects. The evaluation of the command fails but
the definition of <CODE>rec</CODE> has been carried out.
<P>For the next command, it is assumed that <CODE>test1:loop(N)</CODE> is
defined in the following way:
<PRE>
loop(N) ->
io:format("Hello Number: ~w~n", [N]),
loop(N+1).
</PRE>
<P>Command 41 evaluates <CODE>test1:loop(0)</CODE>, which puts the
system into an infinite loop. At this point the user types
<CODE>Control G</CODE>, which suspends output from the current process,
which is stuck in a loop, and activates <CODE>JCL</CODE> mode. In <CODE>JCL</CODE>
mode the user can start and stop jobs.
<P>In this particular case, the <CODE>i</CODE> command ("interrupt") is
used to terminate the looping program, and the <CODE>c</CODE> command
is used to connect to the shell again. Since the process was
running in the background before we killed it, there will be
more printouts before the "<CODE>** exited: killed **</CODE>" message is
shown.
<P>The <CODE>halt()</CODE> command exits the Erlang runtime system.
</DIV>
<H3>JCL Mode</H3>
<DIV CLASS=REFBODY>
<P>When the shell starts, it starts a single evaluator
process. This process, together with any local processes which
it spawns, is referred to as a <CODE>job</CODE>. Only the current job,
which is said to be <CODE>connected</CODE>, can perform operations
with standard IO. All other jobs, which are said to be <CODE>detached</CODE>, are
<CODE>blocked</CODE> if they attempt to use standard IO.
<P>All jobs which do not use standard IO run in the normal way.
<P>The shell escape key <STRONG><CODE>^G</CODE></STRONG> (Control G) detaches the current job
and activates <CODE>JCL</CODE> mode. The <CODE>JCL</CODE> mode prompt is <CODE>"-->"</CODE>. If <CODE> "?"</CODE> is entered at the prompt, the following help message is
displayed:
<PRE>
--> ?
c [nn] - connect to job
i [nn] - interrupt job
k [nn] - kill job
j - list all jobs
s - start local shell
r [node] - start remote shell
q - quit Erlang
? | h - this message
</PRE>
<P>The <CODE>JCL</CODE> commands have the following meaning:
<P>
<DL>
<DT>
<CODE>c [nn]</CODE>
</DT>
<DD>
Connects to job number <CODE><nn></CODE> or the current
job. The standard shell is resumed. Operations which use
standard IO by the current job will be interleaved with
user inputs to the shell.
<BR>
</DD>
<DT>
<CODE>i [nn]</CODE>
</DT>
<DD>
Stops the current evaluator process for job number
<CODE>nn</CODE> or the current job, but does not kill the shell
process. Accordingly, any variable bindings and the process dictionary
will be preserved and the job can be connected again.
This command can be used to interrupt an endless loop.
<BR>
</DD>
<DT>
<CODE>k [nn]</CODE>
</DT>
<DD>
Kills job number <CODE>nn</CODE> or the current
job. All spawned processes in the job are
killed, provided they have not evaluated the
<CODE>group_leader/1</CODE> BIF and are located on
the local machine. Processes spawned on remote nodes will
not be killed.
<BR>
</DD>
<DT>
<CODE>j</CODE>
</DT>
<DD>
Lists all jobs. A list of all known jobs is
printed. The current job name is prefixed with '*'.
<BR>
</DD>
<DT>
<CODE>s</CODE>
</DT>
<DD>
Starts a new job. This will be assigned the new index
<CODE>[nn]</CODE> which can be used in references.
<BR>
</DD>
<DT>
<CODE>r [node]</CODE>
</DT>
<DD>
Starts a remote job on <CODE>node</CODE>. This is used in
distributed Erlang to allow a shell running on one node to
control a number of applications running on a network of
nodes.
<BR>
</DD>
<DT>
<CODE>q</CODE>
</DT>
<DD>
Quits Erlang. Note that this option is disabled if
Erlang is started with the ignore break, <CODE>+Bi</CODE>,
system flag (which may be useful e.g. when running
a restricted shell, see below).
<BR>
</DD>
<DT>
<CODE>?</CODE>
</DT>
<DD>
Displays this message.
<BR>
</DD>
</DL>
<P>It is possible to alter the behaviour of shell escape by means
of the <CODE>stdlib</CODE> application variable <CODE>shell_esc</CODE>. The value of
the variable can be either <CODE>jcl</CODE> (<CODE>erl -stdlib shell_esc jcl</CODE>)
or <CODE>abort</CODE> (<CODE>erl -stdlib shell_esc abort</CODE>). The
first option sets ^G to activate <CODE>JCL</CODE> mode (which is also
default behaviour). The latter sets ^G to terminate the current
shell and start a new one. <CODE>JCL</CODE> mode can not be invoked when
<CODE>shell_esc</CODE> is set to <CODE>abort</CODE>.
<P>If you want an Erlang node to have a remote job active from the start
(rather than the default local job), you start Erlang with the
<CODE>-remsh</CODE> flag. Example: <CODE>erl -sname this_node -remsh other_node@other_host</CODE>
</DIV>
<H3>Restricted Shell</H3>
<DIV CLASS=REFBODY>
<P>The shell may be started in a
restricted mode. In this mode, the shell evaluates a function call
only if allowed. This feature makes it possible to, for example,
prevent a user from accidentally calling a function from the
prompt that could harm a running system (useful in combination
with the the system flag <STRONG><CODE>+Bi</CODE></STRONG>).
<P>When the restricted shell evaluates an expression and
encounters a function call, it calls a predicate function (with
information about the function call in question). This predicate
function returns <CODE>true</CODE> to let the shell go ahead with the
evaluation, or <CODE>false</CODE> to abort it. There are two possible
predicate functions for the user to implement:
<P><STRONG><CODE>local_allowed(Func, ArgList, State) -> {true,NewState} |
{false,NewState}</CODE></STRONG>
<P>to determine if the call to the local function <CODE>Func</CODE>
with arguments <CODE>ArgList</CODE> should be allowed.
<P><STRONG><CODE>non_local_allowed(FuncSpec, ArgList, State) ->
{true,NewState} | {false,NewState}</CODE></STRONG>
<P>to determine if the call to non-local function
<CODE>FuncSpec</CODE> (<CODE>{Module,Func}</CODE> or a fun) with arguments
<CODE>ArgList</CODE> should be allowed.
<P>These predicate functions are in fact called from local and
non-local evaluation function handlers, described in the
<A HREF="erl_eval.html">erl_eval</A>
manual page. (Arguments in <CODE>ArgList</CODE> are evaluated before the
predicates are called).
<P>The <CODE>State</CODE> argument is a tuple
<CODE>{ShellState,ExprState}</CODE>. The return value <CODE>NewState</CODE>
has the same form. This may be used to carry a state between calls
to the predicate functions. Data saved in <CODE>ShellState</CODE> lives
through an entire shell session. Data saved in <CODE>ExprState</CODE>
lives only through the evaluation of the current expression.
<P>There are two ways to start a restricted shell session:
<P>
<UL>
<LI>
Use the stdlib application variable <CODE>restricted_shell</CODE>
and specify, as its value, the name of the predicate function
module. Example (with predicate functions implemented in
pred_mod.erl): <CODE>$ erl -stdlib restricted_shell pred_mod</CODE>
</LI>
<LI>
From a normal shell session, call function
<CODE>shell:start_restricted/1</CODE>. This exits the current evaluator
and starts a new one in restricted mode.
</LI>
</UL>
<P><STRONG>Notes:</STRONG>
<P>
<UL>
<LI>
When restricted shell mode is activated or
deactivated, new jobs started on the node will run in restricted
or normal mode respectively.
</LI>
<LI>
If restricted mode has been enabled on a
particular node, remote shells connecting to this node will also
run in restricted mode.
</LI>
<LI>
The predicate functions can not be used to allow or disallow
execution of functions called from compiled code (only functions
called from expressions entered at the shell prompt).
</LI>
</UL>
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="history/1"><STRONG><CODE>history(N) -> integer()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>N = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Sets the number of previous commands to keep in the
history list to <CODE>N</CODE>. The previous number is returned.
The default number is 20.
</DIV>
<P><A NAME="results/1"><STRONG><CODE>results(N) -> integer()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>N = integer()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Sets the number of results from previous commands to keep in
the history list to <CODE>N</CODE>. The previous number is returned.
The default number is 20.
</DIV>
<P><A NAME="start_restricted/1"><STRONG><CODE>start_restricted(Module) -> ok</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Module = atom()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Exits a normal shell and starts a restricted
shell. <CODE>Module</CODE> specifies the module for the predicate
functions <CODE>local_allowed/3</CODE> and <CODE>non_local_allowed/3</CODE>.
The function is meant to be called from the shell.
</DIV>
<P><A NAME="stop_restricted/0"><STRONG><CODE>stop_restricted() -> ok</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Exits a restricted shell and starts a normal shell. The function
is meant to be called from the shell.
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Robert Virding - support@erlang.ericsson.se<BR>
Peter Andersson - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|