forked from s3lase/v6shell
-
Notifications
You must be signed in to change notification settings - Fork 3
/
osh.1
1583 lines (1575 loc) · 42.5 KB
/
osh.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
.\"
.\" Copyright (c) 2003-2014
.\" Jeffrey Allen Neitzel <jan (at) v6shell (dot) org>.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY JEFFREY ALLEN NEITZEL ``AS IS'', AND ANY
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
.\" DISCLAIMED. IN NO EVENT SHALL JEFFREY ALLEN NEITZEL BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
.\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" @(#)$Id$
.\"
.\" Derived from: Sixth Edition UNIX /usr/man/man1/sh.1
.\"
.\" Copyright (C) Caldera International Inc. 2001-2002. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code and documentation must retain the above
.\" copyright notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed or owned by Caldera
.\" International, Inc.
.\" 4. Neither the name of Caldera International, Inc. nor the names of other
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
.\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
.\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" .SS Aliases (+) derived from:
.\" - /usr/src/bin/csh/csh.1 (.Ss Alias substitution):
.\" $OpenBSD: csh.1,v 1.66 2011/09/03 22:59:08 jmc Exp $
.\" $NetBSD: csh.1,v 1.10 1995/03/21 09:02:35 cgd Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)csh.1 8.2 (Berkeley) 1/21/94
.\"
.\" Includes public domain content derived from:
.\" - /usr/src/bin/ksh/sh.1
.\" $OpenBSD: sh.1,v 1.91 2011/09/03 22:59:08 jmc Exp $
.\"
.TH OSH 1 "@OSH_DATE@" "@OSH_VERSION@" "General Commands"
.SH NAME
osh \- old shell (command interpreter)
.SH SYNOPSIS
.B osh
[\fB\-v\fR]
[\fB\-\fR |
\fB\-c\fR [\fIstring\fR] |
\fB\-i\fR |
\fB\-l\fR |
\fB\-t\fR |
\fIfile\fR [\fIarg1 ...\fR]]
.SH DESCRIPTION
.B Osh
is an enhanced,
backward-compatible port of the
standard command interpreter from Sixth Edition UNIX.
It may be used either as an interactive shell
or as a non-interactive shell.
Throughout this manual,
`(+)' indicates those cases where
.B osh
is known to differ from the original
.IR sh (1),
as it appeared in Sixth Edition UNIX.
.PP
The options are as follows:
.TP
.B \-
The shell reads and executes command lines
from the standard input until
end-of-file or
.BR exit .
.TP
\fB\-c\fR [\fIstring\fR]
If a
.I string
is specified,
the shell executes it
as a command line and exits.
Otherwise,
the shell treats it as the
.B \-
option.
.TP
.B \-i
(+)
The shell behaves as an interactive shell
by reading and executing commands from the
appropriate rc files if possible
(see
.I "Startup and shutdown"
below)
before prompting the user, reading, and
executing command lines from the standard input.
The shell prints a diagnostic and exits with a
non-zero status if it is not connected to a terminal.
.TP
.B \-l
(+)
The shell behaves as a login shell
by reading and executing commands from the
appropriate rc files if possible
(see
.I "Startup and shutdown"
below)
before prompting the user, reading, and
executing command lines from the standard input.
The shell prints a diagnostic and exits with a
non-zero status if it is not connected to a terminal.
.TP
.B \-t
The shell reads a single command line
from the standard input,
executes it,
and exits.
.TP
.B \-v
(+)
The shell verbosely prints the words
of each command line to the standard error
after performing parameter substitution
and word splitting,
but before executing the resulting command line.
.PP
The shell may also be invoked non-interactively
to read, interpret, and execute a command file.
The specified
.I file
and any arguments
are treated as positional parameters
(see
.I "Parameter substitution"
below)
during execution of the command file.
.PP
Otherwise,
if no arguments except for
.B \-v
are specified and if both
the standard input and standard error are
connected to a terminal,
the shell is interactive.
An interactive shell prompts the user
with a `%\ ' (or `#\ ' for the superuser)
before reading each command line from the terminal.
.PP
(+) When an interactive shell starts,
it reads and executes commands
from the appropriate rc files if possible
(see
.I "Startup and shutdown"
below)
before reading and executing command lines
from the terminal.
.SS Metacharacters
A
.I "syntactic metacharacter"
is any one of the following:
.PP
.RS 6
\fB|\fR
\fB^\fR
\fB;\fR
\fB&\fR
\fB(\fR
\fB)\fR
\fB<\fR
\fB>\fR
\fBspace\fR
\fBtab\fR
.RE
.PP
When such a character is unquoted,
it has special meaning to the shell.
The shell uses it to separate words
(see
.I Commands
and
.I "Command\ lines"
below).
A
.I "quoting metacharacter"
is any one of the following:
.PP
.RS 6
\fB"\fR
\fB'\fR
\fB\\\fR
.RE
.PP
See
.I "Quoting"
below.
The
.I "substitution metacharacter"
is a:
.PP
.RS 6
\fB$\fR
.RE
.PP
See
.I "Parameter substitution"
and
.I "Variable substitution"
below.
Finally,
a
.I "pattern metacharacter"
is any one of the following:
.PP
.RS 6
\fB*\fR
\fB?\fR
\fB[\fR
.RE
.PP
See
.I "File name generation"
below.
.SS Commands
Each command is a sequence of non-blank command arguments,
or words,
separated by one or more blanks (\fBspaces\fR or \fBtabs\fR).
The first argument specifies the name of a command to be executed.
Except for certain special arguments described below,
the arguments other than the command name are passed
without interpretation to the invoked command.
.PP
If the first argument names a special command,
the shell executes it (see
.I "Special\ commands"
below).
(+) Otherwise,
the shell treats it either as an alias
(see
.I "Aliases"
below)
or as an external command,
which is located as follows.
.PP
(+) If the command name contains no `/' characters,
the sequence of directories in the environment variable PATH
is searched for the first occurrence
of an executable file by that name,
which the shell attempts to execute.
However,
if the command name contains one or more `/' characters,
the shell attempts to execute it without
performing any PATH search.
.PP
(+) If an executable file does not begin with
the proper magic number or a `#!shell' sequence,
it is assumed to be a shell command file,
and a new shell is automatically invoked to execute it.
The environment variable EXECSHELL
specifies the shell which is invoked
to execute such a file.
.PP
If a command cannot be found or executed,
a diagnostic is printed.
.SS Command lines
Commands separated by \fB|\fR or \fB^\fR constitute a chain of
.IR filters ,
or a
.IR pipeline .
The standard output of each command but the last
is taken as the standard input of the next command.
Each command is run as a separate process, connected
by pipes (see
.IR pipe (2))
to its neighbors.
.PP
A
.IR "command\ line" ,
or
.IR list ,
consists of one or more pipelines separated,
and perhaps terminated by \fB;\fR or \fB&\fR.
The semicolon designates sequential execution.
The ampersand designates asynchronous execution,
which causes the preceding pipeline to be executed
without waiting for it to finish.
The process ID of each command in such a pipeline is reported,
so that it may be used if necessary for a subsequent
.IR kill (1).
.PP
A list contained within parentheses such as
.BI ( \ list \ )
is executed in a subshell and may appear
in place of a simple command as a filter.
.PP
If a command line is syntactically incorrect,
a diagnostic is printed.
.SS Termination reporting
All terminations other than exit and interrupt
are considered to be abnormal.
If a sequential process terminates abnormally,
a message is printed.
The termination report for an asynchronous process
is given upon execution of the first
sequential command subsequent to its termination,
or when the
.B wait
special command is executed.
The following is a list of the possible
termination messages:
.PP
.nf
Hangup
Quit
Illegal instruction
Trace/BPT trap
IOT trap
EMT trap
Floating exception
Killed
Bus error
Memory fault
Bad system call
Broken pipe (+)
.fi
.PP
For an asynchronous process,
its process ID is prepended to the appropriate message.
If a core image is produced,
`\ \-\-\ Core\ dumped' is appended
to the appropriate message.
.SS I/O redirection
Each of the following argument forms
is interpreted as a
.I redirection
by the shell itself.
Such a redirection may appear anywhere among
the arguments of a simple command,
or before or after a parenthesized command list,
and is associated with that command or command list.
.PP
A redirection of the form \fB<\fR\fIarg\fR causes the file \fIarg\fR
to be used as the standard input (file descriptor 0)
for the associated command.
.PP
A redirection of the form \fB>\fR\fIarg\fR causes the file \fIarg\fR
to be used as the standard output (file descriptor 1)
for the associated command.
If \fIarg\fR does not already exist, it is created;
otherwise, it is truncated at the outset.
.PP
A redirection of the form \fB>>\fR\fIarg\fR is the same as \fB>\fR\fIarg\fR,
except if \fIarg\fR already exists the command output is
always appended to the end of the file.
.PP
For example, either of the following command lines:
.PP
.nf
% date >.dirlist ; pwd >>.dirlist ; ls \-l >>.dirlist
% ( date ; pwd ; ls \-l ) >.dirlist
.fi
.PP
creates on the file `.dirlist',
the current date and time,
followed by the name and a long listing
of the current working directory.
.PP
(+) A \fB<\-\fR redirection causes input
for the associated command to be redirected
from the standard input which existed when
the shell was invoked.
This allows a command file to be used as a filter.
.PP
A \fB>\fR\fIarg\fR or \fB>>\fR\fIarg\fR redirection associated with any
but the last command of a pipeline is ineffectual,
as is a \fB<\fR\fIarg\fR redirection with any but the first.
.PP
The standard error (file descriptor 2)
is never subject to redirection by the shell itself.
Thus,
commands may write diagnostics to a location
where they have a chance to be seen.
However,
.B fd2
provides a way to redirect the diagnostic output
to another location.
.PP
If the file for a redirection cannot be opened or created,
a diagnostic is printed.
.SS Quoting
The shell treats all
.I single
(\fB'\fR)
and
.I backslash
(\fB\\\fR)
.I quoted
characters literally,
including characters which have
special meaning to the shell
(see
.I Metacharacters
above).
If such characters are quoted,
they represent themselves and may be passed
as part of arguments.
.PP
(+) Like the quoting behavior described above,
.I double
(\fB"\fR) quotes
cause the shell to treat characters literally.
However,
double quotes also allow the shell to perform
parameter and variable substitution
via the dollar (\fB$\fR) metacharacter,
whereas
.I single
(\fB'\fR) quotes
and
.I backslash
(\fB\\\fR) quotes
do not.
.PP
Individual characters, and sequences of characters,
are quoted when enclosed by a matched pair of
.I double
(\fB"\fR) or
.I single
(\fB'\fR) quotes.
For example:
.PP
.nf
% awk '{ print NR "\\t" $0 }' README ^ more
.fi
.PP
causes
.IR awk (1)
to write each line from the `README' file,
preceded by its line number and a tab,
to the standard output which is piped to
.IR more (1)
for viewing.
The outer single quotes prevent the shell from trying
to interpret any part of the string,
which is then passed as a single argument to awk.
.PP
An individual
.I backslash
(\fB\\\fR) quotes,
or
.IR escapes ,
the next individual character.
A backslash followed by a newline is a special case
which allows continuation of command-line input
onto the next line.
Each backslash-newline sequence in the input
is translated into a blank.
.PP
If a double or single quote appears
but is not part of a matched pair,
a diagnostic is printed.
.SS Parameter substitution
When the shell is invoked with arguments besides
.BR \-v ,
it has additional string processing capabilities
which are not otherwise available.
Such a shell may be invoked as follows:
.PP
.nf
\fBosh\fR [\fB\-v\fR] \fIname\fR [\fIarg1 ...\fR]
.fi
.PP
If the first character of
.I name
is not
.BR \- ,
it is taken as the name of a
.IR "command file" ,
or
.IR "shell script" ,
which is opened as the standard input
for a new shell instance.
Thus,
the new shell reads and interprets command lines
from the named file.
.PP
Otherwise,
.I name
is taken as one of the shell options,
and a new shell instance is invoked
to read and interpret command lines
from its standard input.
However,
notice that the
.B \-c
option followed by a
.I string
is the one case where
the shell does not read and interpret command lines
from its standard input.
Instead,
the string itself is taken as a command line
and executed.
.PP
In each command line,
an unquoted character sequence of the form \fB$\fR\fIN\fR,
where
.I N
is a digit,
is treated as a
.I "positional parameter"
by the shell.
Each occurrence of a positional parameter in the
command line is substituted with the value of the
\fIN\fRth argument to the invocation of the shell
(\fIargN\fR).
\fB$\fR\fI0\fR is substituted with
.IR name .
.PP
In all shell instances,
\fB$$\fR is substituted with the process ID of
the current shell.
The value is represented as a 5-digit ASCII string,
padded on the left with zeros when the process ID
is less than 10000.
.PP
(+) All shell instances attempt to set
the special parameters in the following list.
`(*)' indicates those which are always set.
Otherwise,
the parameter is unset when the shell
cannot determine its value.
.TP 10
\fB$\fR\fI#\fR (*)
The number of positional parameters currently available
to the shell.
.TP
\fB$\fR\fI*\fR
The values of the positional parameters currently available
to the shell, from \fB$\fR\fI1\fR through the end of its argument list.
.TP
\fB$\fR\fI?\fR (*)
The exit status of the last sequential command from the
.I previous
command line.
.TP
\fB$\fR\fId\fR
The value of the environment variable OSHDIR.
.TP
\fB$\fR\fIe\fR
The value of the environment variable EXECSHELL.
.TP
\fB$\fR\fIh\fR
The value of the environment variable HOME.
.TP
\fB$\fR\fIm\fR
The value of the environment variable MANPATH.
.TP
\fB$\fR\fIp\fR
The value of the environment variable PATH.
.TP
\fB$\fR\fIt\fR
The terminal name with which the standard input
was associated when the shell was invoked,
as determined by
.IR ttyname (3).
The value (if any) is equivalent to that
given by `tty\ <\-'.
.TP
\fB$\fR\fIu\fR
The effective user name of the current user,
as determined by
.IR getpwuid (3).
The value (if any) is equivalent to that
given by `id\ \-un'.
.TP
\fB$\fR\fIv\fR (*)
The version of the current shell represented
as a one-word, read-only string.
The
.B version
special command is another option (see
.B version
in
.I "Special\ commands"
below).
.PP
All substitution on a command line is performed
.I before
the line is interpreted.
Thus,
no action which alters the value of any parameter
can have any effect on a reference to that parameter
occurring on the
.I same
line.
.PP
A positional-parameter value may contain
any number of metacharacters.
Each one which is
.IR unquoted ,
or
.IR unescaped ,
within a positional-parameter value retains
its special meaning when the value is substituted
in a command line by the invoked shell.
.PP
Take the following two shell invocations for example:
.PP
.nf
% osh \-c '$1' 'echo Hello World! >/dev/null'
% osh \-c '$1' 'echo Hello World! \\>/dev/null'
Hello World! >/dev/null
.fi
.PP
In the first invocation,
the \fB>\fR in the value substituted by \fB$\fR\fI1\fR
retains its special meaning.
This causes all output from
.B echo
to be redirected to \fI/dev/null\fR.
However,
in the second invocation,
the meaning of \fB>\fR is
.I escaped
by \fB\\\fR
in the value substituted by \fB$\fR\fI1\fR.
This causes the shell to pass `>/dev/null'
as a single argument to echo instead of interpreting
it as a redirection.
.SS Variable substitution (+)
The shell can substitute simple variables set by the user.
A user may cause the shell to set and unset
variables by using the
.B set
and
.B unset
special commands.
.PP
A variable consists of a name,
a single ASCII character,
which matches
either the [A-Z] range
or the [a-cfgi-lnoq-sw-z] range,
inclusive.
A variable must also contain a value set by the user.
.PP
Variables may be used both in interactive shells
and in non-interactive shells.
However,
notice that variables are not functional
when a non-interactive shell is invoked
either with the
.B \-c
option followed by a
.I string
or with the
.B \-t
option.
Such a shell only executes one command line,
but setting and using a variable requires
executing two command lines in the same shell,
one to set it and one to use it.
.PP
Three examples of variable usage follow:
.PP
.nf
% : Example One
% unset C
% set C
% if $? -eq 1 -a X"$C" = XC echo 'C is unset.'
C is unset.
% : Example Two
% set C ''
% ( set C ) >/dev/null
% if $? -eq 0 -a X"$C" = X echo 'C == "'"$C"'"'
C == ""
% set H 'Hello ' ; set W 'World!'
% if X"$H$W" != X -a X"$H$W" != XHW echo "$H$W"
Hello World!
% : Example Three
% alias now "date '+%A, %Y-%m-%d, %T %Z';:"
% alias loadavg "uname -n|sed 's/\\([^.]*\\).*/\\1/'|tr -d \\\\n;\\
echo \-n ': ';uptime|sed 's/^.*user[s,][ ,] *//';:"
% set C '( now ; loadavg )' ; : 'C == Command Line (or List)'
% ( set C ) >/dev/null
% if $? -eq 0 -a X"$C" != X echo "C == `$C'"
C == `( now ; loadavg )'
% $C | awk '{ print NR "\\t" $0 }'
1 Wednesday, 2012-05-23, 19:03:59 UTC
2 serenity: load average: 0.09, 0.04, 0.05
.fi
.PP
As with parameters
(see
.I "Parameter substitution"
above),
all substitution on a command line is performed
.I before
the line is interpreted.
Thus,
no action which alters the value of any variable
can have any effect on a reference to that variable
occurring on the
.I same
line.
.PP
Also,
a variable value may contain
any number of metacharacters.
Each one which is
.IR unquoted ,
or
.IR unescaped ,
within a variable value retains
its special meaning when the value
is substituted in a command line.
.PP
If a variable name passed as an argument to
.B set
or
.B unset
is invalid,
a diagnostic is printed.
Similarly,
if a variable value causes an error,
a diagnostic is printed.
.SS File name generation
Prior to executing a command,
the shell scans each argument for
unquoted \fB*\fR, \fB?\fR, or \fB[\fR characters.
If one or more of these characters appears,
the argument is treated as a
.I pattern
and causes the shell to search for file names which
.I match
it.
Otherwise,
the argument is used as is.
.PP
The meaning of each pattern character is as follows:
.IP o 4
The \fB*\fR character in a pattern matches any string of
characters in a file name (including the null string).
.IP o
The \fB?\fR character in a pattern matches any single character
in a file name.
.IP o
The \fB[...]\fR brackets in a pattern specifies a class of characters
which matches any single file-name character in the class.
Within the brackets,
each character is taken to be a member of the class.
A pair of characters separated by an unquoted \fB\-\fR specifies
the class as a range which matches each character lexically
between the first and second member of the pair, inclusive.
A \fB\-\fR matches itself when quoted or when first or last
in the class.
.PP
Any other character in a pattern matches itself in a file name.
.PP
Notice that the `.' character at the beginning of a file name,
or immediately following a `/',
is always special in that it must be matched explicitly.
The same is true of the `/' character itself.
.PP
If the pattern contains no `/' characters,
the current directory is always used.
Otherwise,
the specified directory is the one obtained by taking the pattern
up to the last `/' before the first unquoted \fB*\fR, \fB?\fR, or \fB[\fR.
The matching process matches the remainder of the pattern
after this `/' against the files in the specified directory.
.PP
In any event,
a list of file names is obtained from the current
(or specified) directory which match the given pattern.
This list is sorted in ascending ASCII order,
and the new sequence of arguments
replaces the given pattern.
The same process is carried out for each
of the given pattern arguments;
the resulting lists are
.I not
merged.
Finally,
the shell
attempts to execute the command
with the resulting argument list.
.PP
If a pattern argument refers to
a directory which cannot be opened,
a `No\ directory' diagnostic is printed.
.PP
If a command has only
.I one
pattern argument,
a `No\ match' diagnostic is printed if it fails
to match any files.
However,
if a command has more than one pattern argument,
a diagnostic is printed only when they
.I all
fail to match any files.
Otherwise,
each pattern argument failing to match
any files is removed from the argument list.
.SS Startup and shutdown (+)
If the first character of the argv[0] used to
invoke an interactive shell is `\-' (e.g.,\ \-osh),
it is a login shell and tries to read and execute commands
from the following four rc init files in sequence:
.IR @SYSCONFDIR@/osh.login ,
.IR @SYSCONFDIR@/osh.oshrc ,
.IR $h/.osh.login ,
and
.IR $h/.oshrc .
The same is true when the shell is invoked with the
.B \-l
option,
regardless of the value of argv[0].
.PP
In the case where an interactive shell is not
a login shell according to its argv[0],
it tries to read and execute commands
from the following two rc init files in sequence:
.I @SYSCONFDIR@/osh.oshrc
and
.IR $h/.oshrc .
The same is true when the shell is invoked with the
.B \-i
option,
regardless of the value of argv[0].
.PP
In any case,
after the shell finishes its startup actions,
it then prompts the user, reads, and executes
command lines from the standard input as usual.
.PP
If the shell is invoked as a login shell,
it tries to read and execute commands from
.I @SYSCONFDIR@/osh.logout
and
.I $h/.osh.logout
in sequence upon logout.
These two rc logout files may be used if necessary
for cleanup upon termination of a login session by
an EOT (see
.I "End of file"
below)
or a SIGHUP signal (see
.I "Signals"
below).
.PP
Notice that
the shell only performs the startup and shutdown actions
described above for readable, regular rc files.
If any rc file is
.I not
readable,
the shell ignores it and continues as normal.
If any rc file is
.I not
a regular file (or a link to a regular file),
the shell ignores it, prints a diagnostic,
and continues as normal.
.PP
In the normal case,
a SIGINT or SIGQUIT signal received by the shell
during execution of any rc file causes
it to cease execution of that file
without terminating.
Thus,
it may be desirable to use the
.B trap
special command to ignore these
and other signals in some cases.
For example,
this is particularly true for
.IR @SYSCONFDIR@/osh.login ,
.IR @SYSCONFDIR@/osh.oshrc ,
and
.IR @SYSCONFDIR@/osh.logout .
.PP
The
.B exit
special command
always causes the shell to terminate if it occurs
in any rc file.
.SS History file (+)
If the shell is invoked as an interactive shell,
it tries to open the
.I $h/.osh.history
file to save the user's command-line history.
Notice that the history file must already exist
as a writable,
regular file (or a link to a regular file)
when the shell is invoked to save
the user's command-line history.
Otherwise,
it will not do so.
.PP
An interactive shell reads each command line from
its terminal and writes the words of each one to
the history file as a history entry after performing
parameter substitution and word splitting.
.PP
The shell does not read the history file or have any features
that allow the user to make direct use of the saved history.
Such features are available via standard external commands
and also via the
.I history
command file that is available in the v6scripts collection.
See http://v6shell.org/v6scripts/history.osh for full details.
.PP
Notice that the shell never creates or removes the
.I $h/.osh.history
file.
It always leaves these actions to the user.
For example:
.PP
.nf
% history -r ; history -c ; exec osh -l
.fi
.PP
causes
.I history
to remove the existing history file (if any),
to create a new (empty) one, and causes
the current shell to replace itself with
a new login shell,
while opening the new history file.
This,
and future,
interactive shells then save the user's
command-line history as long as
the history file exists.
.PP
If desired,
the user can use the history file to repeat
any command line as a command substitution with
.IR sed (1)
and