-
Notifications
You must be signed in to change notification settings - Fork 1
/
nxes.1
2816 lines (2816 loc) · 64.7 KB
/
nxes.1
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
.\" Begin attempt to rename executable es -> nxes
.\" XXX: I have no idea what I'm doing with roff pages
.\"---------------------------------------------------
.\" nxes.1 -- nxes manual page
.\" macros stolen from rc.1
.\"-------
.\" Man page portability notes
.\"
.\" These are some notes on conventions to maintain for greatest
.\" portability of this man page to various other versions of
.\" nroff.
.\"
.\" When you want a \ to appear in the output, use \e in the man page.
.\" (NOTE this comes up in the rc grammar, where to print out '\n' the
.\" man page must contain '\en'.)
.\"
.\" Evidently not all versions of nroff allow the omission of the
.\" terminal " on a macro argument. Thus what could be written
.\"
.\" .Cr "exec >[2] err.out
.\"
.\" in true nroffs must be written
.\"
.\" .Cr "exec >[2] err.out"
.\"
.\" instead.
.\"
.\" Use symbolic font names (e.g. R, I, B) instead of the standard
.\" font positions 1, 2, 3. Note that for Xf to work the standard
.\" font names must be single characters.
.\"
.\" Not all man macros have the RS and RE requests (I altered the Ds
.\" and De macros and the calls to Ds accordingly).
.\"
.\" Thanks to Michael Haardt (u31b3hs@cip-s01.informatik.rwth-aachen.de)
.\" for pointing out these problems.
.\"
.\" Note that sentences should end at the end of a line. nroff and
.\" troff will supply the correct intersentence spacing, but only if
.\" the sentences end at the end of a line. Explicit spaces, if given,
.\" are apparently honored and the normal intersentence spacing is
.\" supressed.
.\"
.\" DaviD W. Sanderson
.\"-------
.\" Dd distance to space vertically before a "display"
.\" These are what n/troff use for interparagraph distance
.\"-------
.if t .nr Dd .4v
.if n .nr Dd 1v
.\"-------
.\" Ds begin a display, indented .5 inches from the surrounding text.
.\"
.\" Note that uses of Ds and De may NOT be nested.
.\"-------
.de Ds
.\" .RS \\$1
.sp \\n(Ddu
.in +0.5i
.nf
..
.\"-------
.\" De end a display (no trailing vertical spacing)
.\"-------
.de De
.fi
.in
.\" .RE
..
.\"-------
.\" I stole the Xf macro from the -man macros on my machine (originally
.\" "}S", I renamed it so that it won't conflict).
.\"-------
.\" Set Cf to the name of the constant width font.
.\" It will be "C" or "(CW", typically.
.\" NOTEZ BIEN the lines defining Cf must have no trailing white space:
.\"-------
.if t .ds Cf C
.if n .ds Cf R
.\"-------
.\" Rc - Alternate Roman and Courier
.\"-------
.de Rc
.Xf R \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Ic - Alternate Italic and Courier
.\"-------
.de Ic
.Xf I \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Bc - Alternate Bold and Courier
.\"-------
.de Bc
.Xf B \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Cr - Alternate Courier and Roman
.\"-------
.de Cr
.Xf \\*(Cf R \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Ci - Alternate Courier and Italic
.\"-------
.de Ci
.Xf \\*(Cf I \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Cb - Alternate Courier and Bold
.\"-------
.de Cb
.Xf \\*(Cf B \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Xf - Alternate fonts
.\"
.\" \$1 - first font
.\" \$2 - second font
.\" \$3 - desired word with embedded font changes, built up by recursion
.\" \$4 - text for first font
.\" \$5 - \$9 - remaining args
.\"
.\" Every time we are called:
.\"
.\" If there is something in \$4
.\" then Call ourself with the fonts switched,
.\" with a new word made of the current word (\$3) and \$4
.\" rendered in the first font,
.\" and with the remaining args following \$4.
.\" else We are done recursing. \$3 holds the desired output
.\" word. We emit \$3, change to Roman font, and restore
.\" the point size to the default.
.\" fi
.\"
.\" Use Xi to add a little bit of space after italic text.
.\"-------
.de Xf
.ds Xi
.\"-------
.\" I used to test for the italic font both by its font position
.\" and its name. Now just test by its name.
.\"
.\" .if "\\$1"2" .if !"\\$5"" .ds Xi \^
.\"-------
.if "\\$1"I" .if !"\\$5"" .ds Xi \^
.\"-------
.\" This is my original code to deal with the recursion.
.\" Evidently some nroffs can't deal with it.
.\"-------
.\" .ie !"\\$4"" \{\
.\" . Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
.\" .\}
.\" .el \{\\$3
.\" . ft R \" Restore the default font, since we don't know
.\" . \" what the last font change was.
.\" . ps 10 \" Restore the default point size, since it might
.\" . \" have been changed by an argument to this macro.
.\" .\}
.\"-------
.\" Here is more portable (though less pretty) code to deal with
.\" the recursion.
.\"-------
.if !"\\$4"" .Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
.if "\\$4"" \\$3\fR\s10
..
.\"-------
.\" IS, IE -- sublist begin and end
.\"-------
.de IS
.ie \n(.g .RS
.el \{\
.nr )R +7m
.nr )P -.5v
.sp .7v \}
..
.de IE
.ie \n(.g .RE
.el \{\
.nr )R -7m
.nr )P +.5v
.sp .4v \}
..
.TH NXES 1 "5 March 1992"
.SH NAME
nxes \- extensible shell (EHI Fork)
.SH SYNOPSIS
.B nxes
.RB [ \-silevxnpo ]
.RB [ \-c
.IR command
|
.IR file ]
.RI [ arguments ]
.SH DESCRIPTION
.I Nxes
is a command interpreter and programming language which combines
the features of other Unix shells and the features of a functional
programming language such as Scheme.
The syntax is derived from
.IR rc (1).
.I Nxes
is intended for use both as an interactive shell and a programming
language for scripts.
.PP
.I Nxes
is an extremely customizable language.
The semantics can be altered radically by redefining functions that
are called to implement internal operations.
This manual page describes the default, initial configuration.
See the section entitled
.B "Hook Functions"
for details on entry points which can be redefined to give
the shell extended semantics.
.SH LANGUAGE
.I Nxes
is an interpreter which reads commands and executes them.
The simplest form of command in
.I nxes
is a sequence of words separated by white space (space and tab) characters.
A word is either a string or a program fragment (see below).
The first word is the command to be executed; the remaining
words are passed as arguments to that command.
If the first word is a string, it is a interpreted as the
name of a program or shell function to run.
If the name is the name of a shell function, that function
is executed.
Otherwise, the name is used as the name of an executable file.
If the name begins with
.Cr / ,
.Cr ./ ,
or
.Cr ../ ,
then it is used as the absolute path name of a file;
if not,
.I nxes
looks for an executable file in the directories named by
.Cr $path .
.PP
Commands are terminated by newline or semicolon
.Rc ( ; ).
A command may also be terminated by an ampersand
.Rc ( & ),
which causes the command to be run in the background:
the shell does not wait for the command
to finish before continuing execution.
Background processes have an implicit redirection of
.Cr /dev/null
as their standard input that may be overridden by an explicit redirection.
.SS Quoting
.IR Nxes
gives several characters special meaning;
special characters automatically terminate words.
The following characters, along with space, tab, and newline, are special:
.Ds
.Cr "# $ & \' ( ) ; < = > \e ^ \` { | }"
.De
.PP
The single quote
.Rc ( ' )
prevents special treatment of any character other than itself.
Any characters between single quotes, including newlines, backslashes,
and control characters, are treated as an uninterpreted string.
A quote character itself may be quoted by placing two quotes in a row.
A single quote character is therefore represented by the sequence
.Cr '''' .
The empty string is represented by
.Cr '' .
Thus:
.Ds
.Cr "echo 'What''s the plan, Stan?'"
.De
.PP
prints out
.Ds
.Cr "What's the plan, Stan?"
.De
.PP
The backslash
.Cr ( \e )
quotes the immediately following character, if it is
one of the special characters, except for newline.
In addition,
.IR nxes
recognizes backslash sequences similar to those used in C strings:
.IS
.TP
.Cr \ea
alert (bell)
.TP
.Cr \eb
backspace
.TP
.Cr \ee
escape
.TP
.Cr \ef
form-feed
.TP
.Cr \en
newline
.TP
.Cr \er
carriage return
.TP
.Cr \et
tab
.TP
.Ci \ex nn
hexadecimal character
.IR nn
.TP
.Ci \e nnn
octal character
.IR nnn
.IE
.SS Comments
The number sign
.Rc ( # )
begins a comment in
.IR nxes .
All characters up to but not including the next newline are ignored.
.SS "Line continuation"
A long logical line may be continued over several physical lines by
terminating each line (except the last) with a backslash
.Rc ( \e ).
The backslash-newline sequence is treated as a space.
Note that line continuation does not work in comments, where the backslash is
treated as part of the comment, and inside quoted strings, where the backslash
and newline are quoted.
.SS Lists
The primary data structure in
.IR nxes
is the list, which is a sequence of words.
Parentheses are used to group lists.
The empty list is represented by
.Cr "()" .
Lists have no hierarchical structure;
a list inside another list is expanded so that the
outer list contains all the elements of the inner list.
Thus, the following are all equivalent:
.Ds
.Cr "one two three"
.Cr "(one two three)"
.Cr "((one) () ((two three)))"
.De
.PP
Note that the null string,
.Cr "''" ,
and the empty list,
.Cr "()" ,
are two very
different things.
Assigning the null string to variable is a valid
operation, but it does not remove its definition.
.SS Concatenation
Two lists may be joined by the concatenation operator
.Rc ( ^ ).
A single word is a list of length one, so
.Ds
.Cr "echo foo^bar"
.De
.PP
produces the output
.Ds
.Cr foobar
.De
.PP
For lists of more than one element,
concatenation produces the cross (Cartesian) product of
the elements in both lists:
.Ds
.Cr "echo (a\- b\- c\-)^(1 2)"
.De
.PP
produces the output
.Ds
.Cr "a\-1 a\-2 b\-1 b\-2 c\-1 c\-2"
.De
.SS "Variables"
A list may be assigned to a variable, using the notation:
.Ds
.Ic var " = " list
.De
.PP
Any sequence of non-special characters, except a sequence including
only digits, may be used as a variable name.
.I Nxes
exports all user-defined variables into the environment unless
it is explicitly told not to.
.PP
The value of a variable is referenced with the notation:
.Ds
.Ci $ var
.De
.PP
Any variable which has not been assigned a value returns the empty list
when referenced.
In addition, multiple references are allowed:
.Ds
.Cr "a = foo"
.Cr "b = a"
.Cr "echo $$b"
.De
.PP
prints
.Ds
.Cr foo
.De
.PP
A variable's definition may also be removed by
assigning the empty list to a variable:
.Ds
.Ic var =
.De
.PP
Multiple variables may be assigned with a single assignment statment.
The left hand side of the assignment operation consists of a list of
variables which are assigned, one by one, to the values in the list
on the right hand side. If there are more variables than values in
the list, the empty list is assigned to the remaining variables.
If there are fewer variables than elements in the list, the last
variable is bound to all the remaining list values.
.PP
For example,
.Ds
.Cr "(a b) = 1 2 3"
.De
.PP
has the same effect as
.Ds
.Cr "a = 1"
.Cr "b = 2 3"
.Ds
.PP
and
.Ds
.Cr "(a b c) = 1 2"
.De
.PP
is the same as
.Ds
.Cr "a = 1"
.Cr "b = 2"
.Cr "c ="
.Ds
.PP
Note that when assigning values to more than one variable,
the list of variables must be enclosed in parentheses.
.PP
For ``free careting'' (see below) to work correctly,
.I nxes
must make certain assumptions
about what characters may appear in a variable name.
.I Nxes
assumes that a variable name consists only of alphanumeric characters,
percent
.Rc ( % ),
star
.Rc ( * ),
dash
.Rc ( - ),
and underscore
.Rc ( \|_\| ).
To reference a variable with other
characters in its name, quote the variable name.
Thus:
.Ds
.Cr "echo $'we$Ird\Variab!le'"
.De
.PP
A variable name produced by some complex operation,
such as concatenation, should be enclosed in parentheses:
.Ds
.Ci $( var )
.De
.PP
Thus:
.Ds
.Cr "Good\-Morning = Bonjour"
.Cr "Guten = Good"
.Cr "Morgen = Morning"
.Cr "echo $($Guten^\-^$Morgen)"
.De
.PP
prints
.Ds
.Cr "Bonjour"
.De
.PP
Each element of the list in parentheses is treated as an
independent variable and expanded separately.
Thus, given the above definitions,
.Ds
.Cr "echo $(Guten Morgen)"
.De
.PP
prints
.Ds
.Cr "Good Morning"
.De
.PP
To count the number of elements in a variable, use
.Ds
.Ci $# var
.De
.PP
This returns a single-element list with the number of elements in
.Ci $ var\fR.
.SS Subscripting
Variables may be indexed with the notation
.Ds
.Ci $ var ( n )
.De
.PP
where
.I n
is a list of integers or ranges.
Subscript indexes are based at one.
The list of subscripts need
not be in order or even unique.
Thus, if
.Ds
.Cr "a = one two three"
.De
.PP
then
.Ds
.Cr "echo $a(3 3 3)"
.De
.PP
prints
.Ds
.Cr "three three three"
.De
.PP
Subscript indices which refer to nonexistent elements
expand to the empty list. Thus, given the definition above
.Ds
.Cr "echo $a(3 1 4 1 5 9 2 6 5)"
.De
.PP
prints
.Ds
.Cr "three one one two"
.De
.PP
Subscript ranges are of the form
.Ic lo ... hi
and refer to all the elements between
.I lo
and
.IR hi .
If
.I lo
is omitted, then
.Cr 1
is used as a default value; if
.I hi
is omitted, the length of the list is used.
Thus
.Ds
.Cr "* = $*(2 ...)"
.De
.PP
removes the first element of
.Cr * ,
similar to the effect of
.Cr shift
in
.IR rc (1)
or
.IR sh (1).
.PP
The notation
.Ci "$" n\fR,
where
.I n
is an integer, is a shorthand for
.Ci $*( n )\fR.
Thus,
.IR nxes 's
arguments may be referred to as
.Cr "$1" ,
.Cr "$2" ,
and so on.
.PP
Note that the list of subscripts may be given by any
.IR nxes
expression, so
.Ds
.Cr "$var(\`{awk 'BEGIN{for(i=1;i<=10;i++)print i;exit }'})"
.De
.PP
returns the first 10 elements of
.Cr $var .
.SS "Free Carets"
.I Nxes
inserts carets (concatenation operators) for free in certain situations,
in order to save some typing on the user's behalf.
For example, the following are all equivalent:
.Ds
.Cr "cc \-O \-g \-c malloc.c alloca.c"
.Cr "cc \-^(O g c) (malloc alloca)^.c"
.Cr "opts=O g c; files=malloc alloca; cc \-$opts $files.c"
.De
.PP
.I Nxes
inserts a free-caret between the
.Rc `` \- ''
and
.Cr "$opts" ,
as well
as between
.Cr $files
and
.Cr ".c" .
The rule for free carets is as follows:
if a word or keyword is immediately
followed by another word, keyword, dollar-sign or
backquote without any intervening spaces, then
.I nxes
inserts a caret between them.
.SS "Flattened Lists"
To create a single-element list from a multi-element list,
with the components space-separated, use
.Ds
.Ci $^ var
.De
.PP
Flattening is useful when the normal list concatenation rules need to be
bypassed.
For example, to append a single period at the end of
.Cr $path ,
use:
.Ds
.Cr "echo $^path."
.De
.SS "Wildcard Expansion"
.I Nxes
expands wildcards in filenames if possible.
When the characters
.Cr "*" ,
.Cr [
or
.Cr ?
occur in an argument or command,
.I nxes
looks at the
argument as a pattern for matching against files.
(Contrary to the behavior some other shells exhibit,
.I nxes
will only perform pattern matching if a metacharacter occurs unquoted and
literally in the input.
Thus,
.Ds
.Cr "foo = '*'"
.Cr "echo $foo"
.De
.PP
will always echo just a star.
In order for non-literal metacharacters to be expanded, an
.Cr eval
statement must be used in order to rescan the input.)
Pattern matching occurs according to the following rules:
a
.Cr "*"
matches any number (including zero) of
characters.
A
.Cr ?
matches any single character, and a
.Cr [
followed by a
number of characters followed by a
.Cr ]
matches a single character in that
class.
The rules for character class matching are the same as those for
.IR ed (1),
with the exception that character class negation is achieved
with the tilde
.Rc ( ~ ),
not the caret
.Rc ( ^ ),
since the caret already means
something else in
.IR nxes .
The filename component separator, slash
.Rc ( / ),
must appear explicitly in patterns.
.Cr "*"
and
.Cr ?
do not match a dot character
.Rc ( . )
at the beginning of a filename component.
.PP
A tilde
.Rc ( ~ )
as the first character of an argument is used to refer to home directories.
A tilde alone or followed by a slash
.Rc ( / )
is replaced by the value of
.Cr $home ,
which is usually the home directory of the current user.
A tilde followed by a username is replaced with the home directory
of that user, according to
.IR getpwent (3).
.SS "Pattern Matching"
The tilde
.Rc ( ~ )
operator is used in
.I nxes
for matching strings against wildcard patterns.
The command
.Ds
.Cr "~ \fIsubject\fP \fIpattern\fP \fIpattern\fP ..."
.De
.PP
returns a true value if and only if the subject matches any of the patterns.
The matching follows the same rules as wildcard expansion, except that slashes
.Rc ( / )
are not considered significant, leading dots
.Rc ( . )
do not have to be matched explicitly,
and home directory expansion does not occur.
Thus
.Ds
.Cr "~ foo f*"
.De
.PP
returns zero (true), while
.Ds
.Cr "~ (bar baz) f*"
.De
.PP
returns one (false).
The null list is matched by the null list, so
.Ds
.Cr "~ $foo ()"
.De
.PP
checks to see whether
.Cr $foo
is empty or not.
This may also be achieved
by the test
.Ds
.Cr "~ $#foo 0"
.De
.PP
Note that inside a
.Cr ~
command
.I nxes
does not match patterns against file
names, so it is not necessary to quote the characters
.Cr "*" ,
.Cr [
and
.Cr "?" .
However,
.I nxes
does expand the subject against filenames if it contains
metacharacters.
Thus, the command
.Ds
.Cr "~ * ?"
.De
.PP
returns true if any of the files in the current directory have a
single-character name.
Note that if the
.Cr ~
command is given a list as its first
argument, then a successful match against any of the elements of that
list will cause
.Cr ~
to return true.
For example:
.Ds
.Cr "~ (foo goo zoo) z*"
.De
.PP
is true.
.SS "Pattern Extraction"
The double-tilde
.Rc ( ~~ )
operator is used in
.I nxes
for extracting the parts of strings that match patterns.
The command
.Ds
.Cr "~~ \fIsubject\fP \fIpattern\fP \fIpattern\fP ..."
.De
.PP
returns the parts of each matching subject which correspond to the
wildcards.
.PP
Each subject is checked in order against each pattern; if it matches
the pattern, the parts of the subject which matched each
.Cr "*" ,
.Cr "?" ,
or
.Cr "[]"
character range are extracted, and processing moves on to the next
subject. If the subject does not match, the next pattern is tried.
.PP
For example, the result of the extraction operation
.Ds
.Cr "~~ (foo.c foo.x bar.h) *.[ch]"
.De
.PP
is the list
.Cr "(foo c bar h)" .
.SS "Command Substitution"
A list may be formed from the output of a command by using backquote
substitution:
.Ds
.Ci "\`{" " command " }
.De
.PP
returns a list formed from the standard output of the command in braces.
The characters stored in the variable
.Cr $ifs
(for ``input field separator'')
are used to split the output into list elements.
By default,
.Cr $ifs
has the value space-tab-newline.
The braces may be omitted if the command is a single word.
Thus
.Cr \`ls
may be used instead of
.Cr "\`{ls}" .
This last feature is useful when defining functions that expand
to useful argument lists.
A frequent use is:
.Ds
.Cr "fn src { echo *.[chy] }"
.De
.PP
followed by
.Ds
.Cr "wc \`src"
.De
.PP
(This will print out a word-count of all C and Yacc source files in the current
directory.)
.PP
In order to override the value of
.Cr $ifs
for a single command substitution, use:
.Ds
.Ci "\`\`" " ifs-list " { " command " }
.De
.PP
.Cr $ifs
will be temporarily ignored and the command's output will be split as specified by
the list following the double backquote.
For example:
.Ds
.Cr "\`\` :\en {cat /etc/passwd}"
.De
.PP
splits up
.Cr /etc/passwd
into fields.
.SS "Return Values"
The return value of a command is obtained with the construct
.Ds
.Ci "<={" " command " }
.De
.PP
The return value of an external program is its exit status
(which in other shells can be found in special variables such as
.Cr $?
or
.Cr $status ),
as either a small integer or the name of signal.
Thus
.Ds
.Cr "echo <={test \-f /etc/motd} <={test \-w /vmunix} <=a.out"
.De
.PP
might produce the output
.Ds
.Cr "0 1 sigsegv+core"
.De
.PP
along with any output or error messages from the programs.
.PP
.I Nxes
functions and primitives can produce ``rich return values,''
that is, arbitrary lists as return values.
.PP
When return values are interpreted as truth values,
an extension of the normal shell conventions apply.
If any element of a list is not equal to
.Rc `` 0 ''
(or the empty string), that list is considered false.
.PP
The return value of an assignment operation is the assigned value.
.SS "Logical Operators"
There are a number of operators in
.I nxes
which depend on the exit status of a command.
.Ds
.Ic command1 " && " command2
.De
.PP
executes the first command and then executes the second command if and only if
the first command has a ``true'' return value.
.Ds
.Ic command1 " || " command2
.De
.PP
executes the first command and then executes the second command if and only if
the first command has a ``false'' return value.
.Ds
.Ci ! " command"
.De
.PP
inverts the truth value of the exit status of a command.
.SS "Input and output"
.PP
The standard output of a command may be redirected to a file with
.Ds
.Cr "command > file"
.De
.PP
and the standard input may be taken from a file with
.Ds
.Cr "command < file"
.De
.PP
File descriptors other than 0 and 1 may be specified also.
For example, to redirect standard error to a file, use:
.Ds
.Cr "command >[2] file"
.De
.PP
In order to duplicate a file descriptor, use
.Ci >[ n = m ]\fR.
Thus to redirect both standard output and standard error
to the same file, use
.Ds
.Cr "command > file >[2=1]"
.De
.PP
To close a file descriptor that may be open, use
.Ci >[ n =]\fR.
For example, to
close file descriptor 7:
.Ds
.Cr "command >[7=]"
.De
.PP
In order to place the output of a command at the end of an already
existing file, use:
.Ds
.Cr "command >> file"
.De
.PP
If the file does not exist, then it is created.
.PP
To open a file for reading and writing, use the
.Cr <>
redirection operator;
for reading and appending, use
.Cr <>> .
Both of these operators use file descriptor 0 (standard input)
by default.
Similarly,
.Cr ><
truncates a file and opens it for reading and writing, and
.Cr >><
opens a file for reading and appending;
these operators use file descriptor 1 by default.
.PP
``Here documents'' are supported as in
.IR sh (1)
with the use of
.Ds
.Cr "command << 'eof-marker'"
.De
.PP
If the end-of-file marker is quoted,
then no variable substitution occurs inside the here document.
Otherwise, every variable is substituted
by its space-separated-list value (see
.BR "Flat Lists" ,
below),
and if a
.Cr ^
character follows a variable name, it is deleted.
This allows the unambiguous use of variables adjacent to text, as in
.Ds