-
Notifications
You must be signed in to change notification settings - Fork 39
/
oksh.1
5635 lines (5635 loc) · 133 KB
/
oksh.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
.\" $OpenBSD: ksh.1,v 1.220 2023/10/20 18:51:09 schwarze Exp $
.\"
.\" Public Domain
.\"
.Dd $Mdocdate: October 20 2023 $
.Dt OKSH 1
.Os
.Sh NAME
.Nm oksh ,
.Nm rksh
.Nd public domain Korn shell
.Sh SYNOPSIS
.Nm oksh
.Bk -words
.Op Fl +abCefhiklmnpruvXx
.Op Fl +o Ar option
.Op Fl c Ar string | Fl s | Ar file Op Ar argument ...
.Ek
.Sh DESCRIPTION
.Nm
is a command interpreter intended for both interactive and shell
script use.
Its command language is a superset of the
.Xr sh 1
shell language.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl c Ar string
.Nm
will execute the command(s) contained in
.Ar string .
.It Fl i
Interactive shell.
A shell is
.Dq interactive
if this
option is used or if both standard input and standard error are attached
to a
.Xr tty 4 .
An interactive shell has job control enabled, ignores the
.Dv SIGINT ,
.Dv SIGQUIT ,
and
.Dv SIGTERM
signals, and prints prompts before reading input (see the
.Ev PS1
and
.Ev PS2
parameters).
For non-interactive shells, the
.Ic trackall
option is on by default (see the
.Ic set
command below).
.It Fl l
Login shell.
If the basename the shell is called with (i.e. argv[0])
starts with
.Ql -
or if this option is used,
the shell is assumed to be a login shell and the shell reads and executes
the contents of
.Pa /etc/profile
and
.Pa $HOME/.profile
if they exist and are readable.
.It Fl p
Privileged shell.
A shell is
.Dq privileged
if this option is used
or if the real user ID or group ID does not match the
effective user ID or group ID (see
.Xr getuid 2
and
.Xr getgid 2 ) .
A privileged shell does not process
.Pa $HOME/.profile
nor the
.Ev ENV
parameter (see below).
Instead, the file
.Pa /etc/suid_profile
is processed.
Clearing the privileged option causes the shell to set
its effective user ID (group ID) to its real user ID (group ID).
.It Fl r
Restricted shell.
A shell is
.Dq restricted
if this
option is used;
if the basename the shell was invoked with was
.Dq rksh ;
or if the
.Ev SHELL
parameter is set to
.Dq rksh .
The following restrictions come into effect after the shell processes any
profile and
.Ev ENV
files:
.Pp
.Bl -bullet -compact
.It
The
.Ic cd
command is disabled.
.It
The
.Ev SHELL ,
.Ev ENV ,
and
.Ev PATH
parameters cannot be changed.
.It
Command names can't be specified with absolute or relative paths.
.It
The
.Fl p
option of the built-in command
.Ic command
can't be used.
.It
Redirections that create files can't be used (i.e.\&
.Sq Cm > ,
.Sq Cm >| ,
.Sq Cm >> ,
.Sq Cm <> ) .
.El
.It Fl s
The shell reads commands from standard input; all non-option arguments
are positional parameters.
.El
.Pp
In addition to the above, the options described in the
.Ic set
built-in command can also be used on the command line:
both
.Op Fl +abCefhkmnuvXx
and
.Op Fl +o Ar option
can be used for single letter or long options, respectively.
.Pp
If neither the
.Fl c
nor the
.Fl s
option is specified, the first non-option argument specifies the name
of a file the shell reads commands from.
If there are no non-option
arguments, the shell reads commands from the standard input.
The name of the shell (i.e. the contents of $0)
is determined as follows: if the
.Fl c
option is used and there is a non-option argument, it is used as the name;
if commands are being read from a file, the file is used as the name;
otherwise, the basename the shell was called with (i.e. argv[0]) is used.
.Pp
If the
.Ev ENV
parameter is set when an interactive shell starts (or,
in the case of login shells,
after any profiles are processed), its value is subjected to parameter,
command, arithmetic, and tilde
.Pq Sq ~
substitution and the resulting file
(if any) is read and executed.
In order to have an interactive (as opposed to login) shell
process a startup file,
.Ev ENV
may be set and exported (see below) in
.Pa $HOME/.profile
\- future interactive shell invocations will process any file pointed to by
.Ev $ENV :
.Pp
.Dl export ENV=$HOME/.kshrc
.Pp
.Pa $HOME/.kshrc
is then free to specify instructions for interactive shells.
For example, the global configuration file may be sourced:
.Bd -literal -offset indent
\&. /etc/ksh.kshrc
.Ed
.Pp
The above strategy may be employed to keep
setup procedures for login shells in
.Pa $HOME/.profile
and setup procedures for interactive shells in
.Pa $HOME/.kshrc .
Of course, since login shells are also interactive,
any commands placed in
.Pa $HOME/.kshrc
will be executed by login shells too.
.Pp
The exit status of the shell is 127 if the command file specified on the
command line could not be opened, or non-zero if a fatal syntax error
occurred during the execution of a script.
In the absence of fatal errors,
the exit status is that of the last command executed, or zero, if no
command is executed.
.Ss Command syntax
The shell begins parsing its input by breaking it into
.Em words .
Words, which are sequences of characters, are delimited by unquoted whitespace
characters (space, tab, and newline) or meta-characters
.Po
.Ql < ,
.Ql > ,
.Ql | ,
.Ql \&; ,
.Ql \&( ,
.Ql \&) ,
and
.Ql &
.Pc .
Aside from delimiting words, spaces and tabs are ignored, while newlines
usually delimit commands.
The meta-characters are used in building the following
.Em tokens :
.Sq Cm < ,
.Sq Cm <& ,
.Sq Cm << ,
.Sq Cm > ,
.Sq Cm >& ,
.Sq Cm >> ,
etc. are used to specify redirections (see
.Sx Input/output redirection
below);
.Ql |
is used to create pipelines;
.Ql |&
is used to create co-processes (see
.Sx Co-processes
below);
.Ql \&;
is used to separate commands;
.Ql &
is used to create asynchronous pipelines;
.Ql &&
and
.Ql ||
are used to specify conditional execution;
.Ql ;;
is used in
.Ic case
statements;
.Ql (( .. ))
is used in arithmetic expressions;
and lastly,
.Ql \&( .. )\&
is used to create subshells.
.Pp
Whitespace and meta-characters can be quoted individually using a backslash
.Pq Sq \e ,
or in groups using double
.Pq Sq \&"
or single
.Pq Sq '
quotes.
The following characters are also treated specially by the
shell and must be quoted if they are to represent themselves:
.Ql \e ,
.Ql \&" ,
.Ql ' ,
.Ql # ,
.Ql $ ,
.Ql ` ,
.Ql ~ ,
.Ql { ,
.Ql } ,
.Ql * ,
.Ql \&? ,
and
.Ql \&[ .
The first three of these are the above mentioned quoting characters (see
.Sx Quoting
below);
.Ql # ,
if used at the beginning of a word, introduces a comment \(em everything after
the
.Ql #
up to the nearest newline is ignored;
.Ql $
is used to introduce parameter, command, and arithmetic substitutions (see
.Sx Substitution
below);
.Ql `
introduces an old-style command substitution (see
.Sx Substitution
below);
.Ql ~
begins a directory expansion (see
.Sx Tilde expansion
below);
.Ql {
and
.Ql }
delimit
.Xr csh 1 Ns -style
alternations (see
.Sx Brace expansion
below);
and finally,
.Ql * ,
.Ql \&? ,
and
.Ql \&[
are used in file name generation (see
.Sx File name patterns
below).
.Pp
As words and tokens are parsed, the shell builds commands, of which there
are two basic types:
.Em simple-commands ,
typically programs that are executed, and
.Em compound-commands ,
such as
.Ic for
and
.Ic if
statements, grouping constructs, and function definitions.
.Pp
A simple-command consists of some combination of parameter assignments
(see
.Sx Parameters
below),
input/output redirections (see
.Sx Input/output redirections
below),
and command words; the only restriction is that parameter assignments come
before any command words.
The command words, if any, define the command
that is to be executed and its arguments.
The command may be a shell built-in command, a function,
or an external command
(i.e. a separate executable file that is located using the
.Ev PATH
parameter; see
.Sx Command execution
below).
.Pp
All command constructs have an exit status.
For external commands,
this is related to the status returned by
.Xr wait 2
(if the command could not be found, the exit status is 127; if it could not
be executed, the exit status is 126).
The exit status of other command
constructs (built-in commands, functions, compound-commands, pipelines, lists,
etc.) are all well-defined and are described where the construct is
described.
The exit status of a command consisting only of parameter
assignments is that of the last command substitution performed during the
parameter assignment or 0 if there were no command substitutions.
.Pp
Commands can be chained together using the
.Ql |
token to form pipelines, in which the standard output of each command but the
last is piped (see
.Xr pipe 2 )
to the standard input of the following command.
The exit status of a pipeline is that of its last command, unless the
.Ic pipefail
option is set.
A pipeline may be prefixed by the
.Ql \&!
reserved word, which causes the exit status of the pipeline to be logically
complemented: if the original status was 0, the complemented status will be 1;
if the original status was not 0, the complemented status will be 0.
.Pp
.Em Lists
of commands can be created by separating pipelines by any of the following
tokens:
.Ql && ,
.Ql || ,
.Ql & ,
.Ql |& ,
and
.Ql \&; .
The first two are for conditional execution:
.Dq Ar cmd1 No && Ar cmd2
executes
.Ar cmd2
only if the exit status of
.Ar cmd1
is zero;
.Ql ||
is the opposite \(em
.Ar cmd2
is executed only if the exit status of
.Ar cmd1
is non-zero.
.Ql &&
and
.Ql ||
have equal precedence which is higher than that of
.Ql & ,
.Ql |& ,
and
.Ql \&; ,
which also have equal precedence.
The
.Ql &&
and
.Ql ||
operators are
.Qq left-associative .
For example, both of these commands will print only
.Qq bar :
.Bd -literal -offset indent
$ false && echo foo || echo bar
$ true || echo foo && echo bar
.Ed
.Pp
The
.Ql &
token causes the preceding command to be executed asynchronously; that is,
the shell starts the command but does not wait for it to complete (the shell
does keep track of the status of asynchronous commands; see
.Sx Job control
below).
When an asynchronous command is started when job control is disabled
(i.e. in most scripts), the command is started with signals
.Dv SIGINT
and
.Dv SIGQUIT
ignored and with input redirected from
.Pa /dev/null
(however, redirections specified in the asynchronous command have precedence).
The
.Ql |&
operator starts a co-process which is a special kind of asynchronous process
(see
.Sx Co-processes
below).
A command must follow the
.Ql &&
and
.Ql ||
operators, while it need not follow
.Ql & ,
.Ql |& ,
or
.Ql \&; .
The exit status of a list is that of the last command executed, with the
exception of asynchronous lists, for which the exit status is 0.
.Pp
Compound commands are created using the following reserved words.
These words
are only recognized if they are unquoted and if they are used as the first
word of a command (i.e. they can't be preceded by parameter assignments or
redirections):
.Bd -literal -offset indent
case esac in until (( }
do fi name while ))
done for select ! [[
elif function then ( ]]
else if time ) {
.Ed
.Pp
.Sy Note :
Some shells (but not this one) execute control structure commands in a
subshell when one or more of their file descriptors are redirected, so any
environment changes inside them may fail.
To be portable, the
.Ic exec
statement should be used instead to redirect file descriptors before the
control structure.
.Pp
In the following compound command descriptions, command lists (denoted as
.Em list )
that are followed by reserved words must end with a semicolon, a newline, or
a (syntactically correct) reserved word.
For example, the following are all valid:
.Bd -literal -offset indent
$ { echo foo; echo bar; }
$ { echo foo; echo bar<newline> }
$ { { echo foo; echo bar; } }
.Ed
.Pp
This is not valid:
.Pp
.Dl $ { echo foo; echo bar }
.Bl -tag -width Ds
.It Pq Ar list
Execute
.Ar list
in a subshell.
There is no implicit way to pass environment changes from a
subshell back to its parent.
.It { Ar list ; No }
Compound construct;
.Ar list
is executed, but not in a subshell.
Note that
.Ql {
and
.Ql }
are reserved words, not meta-characters.
.It Xo Ic case Ar word Cm in
.Oo Op \&(
.Ar pattern
.Op | Ar pattern
.No ... )
.Ar list No ;;\ \& Oc ... Cm esac
.Xc
The
.Ic case
statement attempts to match
.Ar word
against a specified
.Ar pattern ;
the
.Ar list
associated with the first successfully matched pattern is executed.
Patterns used in
.Ic case
statements are the same as those used for file name patterns except that the
restrictions regarding
.Ql \&.
and
.Ql /
are dropped.
Note that any unquoted space before and after a pattern is
stripped; any space within a pattern must be quoted.
Both the word and the
patterns are subject to parameter, command, and arithmetic substitution, as
well as tilde substitution.
For historical reasons, open and close braces may be used instead of
.Cm in
and
.Cm esac
e.g.\&
.Ic case $foo { *) echo bar; } .
The exit status of a
.Ic case
statement is that of the executed
.Ar list ;
if no
.Ar list
is executed, the exit status is zero.
.It Xo Ic for Ar name
.Op Cm in Op Ar word ... ;
.Cm do Ar list ; Cm done
.Xc
For each
.Ar word
in the specified word list, the parameter
.Ar name
is set to the word and
.Ar list
is executed.
If
.Cm in
is not used to specify a word list, the positional parameters
($1, $2, etc.)\&
are used instead.
For historical reasons, open and close braces may be used instead of
.Cm do
and
.Cm done
e.g.\&
.Ic for i; { echo $i; } .
The exit status of a
.Ic for
statement is the last exit status of
.Ar list .
If there are no items,
.Ar list
is not executed and the exit status is zero.
.It Xo Ic if Ar list ;
.Cm then Ar list ;
.Oo Cm elif Ar list ;
.Cm then Ar list ; Oc ...
.Oo Cm else Ar list ; Oc
.Cm fi
.Xc
If the exit status of the first
.Ar list
is zero, the second
.Ar list
is executed; otherwise, the
.Ar list
following the
.Cm elif ,
if any, is executed with similar consequences.
If all the lists following the
.Ic if
and
.Cm elif Ns s
fail (i.e. exit with non-zero status), the
.Ar list
following the
.Cm else
is executed.
The exit status of an
.Ic if
statement is that of non-conditional
.Ar list
that is executed; if no non-conditional
.Ar list
is executed, the exit status is zero.
.It Xo Ic select Ar name
.Oo Cm in Ar word No ... Oc ;
.Cm do Ar list ; Cm done
.Xc
The
.Ic select
statement provides an automatic method of presenting the user with a menu and
selecting from it.
An enumerated list of the specified
.Ar word Ns (s)
is printed on standard error, followed by a prompt
.Po
.Ev PS3 :
normally
.Sq #?\ \&
.Pc .
A number corresponding to one of the enumerated words is then read from
standard input,
.Ar name
is set to the selected word (or unset if the selection is not valid),
.Ev REPLY
is set to what was read (leading/trailing space is stripped), and
.Ar list
is executed.
If a blank line (i.e. zero or more
.Ev IFS
characters) is entered, the menu is reprinted without executing
.Ar list .
.Pp
When
.Ar list
completes, the enumerated list is printed if
.Ev REPLY
is
.Dv NULL ,
the prompt is printed, and so on.
This process continues until an end-of-file
is read, an interrupt is received, or a
.Ic break
statement is executed inside the loop.
If
.Dq in word ...
is omitted, the positional parameters are used
(i.e. $1, $2, etc.).
For historical reasons, open and close braces may be used instead of
.Cm do
and
.Cm done
e.g.\&
.Ic select i; { echo $i; } .
The exit status of a
.Ic select
statement is zero if a
.Ic break
statement is used to exit the loop, non-zero otherwise.
.It Xo Ic until Ar list ;
.Cm do Ar list ;
.Cm done
.Xc
This works like
.Ic while ,
except that the body is executed only while the exit status of the first
.Ar list
is non-zero.
.It Xo Ic while Ar list ;
.Cm do Ar list ;
.Cm done
.Xc
A
.Ic while
is a pre-checked loop.
Its body is executed as often as the exit status of the first
.Ar list
is zero.
The exit status of a
.Ic while
statement is the last exit status of the
.Ar list
in the body of the loop; if the body is not executed, the exit status is zero.
.It Xo Ic function Ar name
.No { Ar list ; No }
.Xc
Defines the function
.Ar name
(see
.Sx Functions
below).
Note that redirections specified after a function definition are
performed whenever the function is executed, not when the function definition
is executed.
.It Ar name Ns () Ar command
Mostly the same as
.Ic function
(see
.Sx Functions
below).
.It Xo Ic time Op Fl p
.Op Ar pipeline
.Xc
The
.Ic time
reserved word is described in the
.Sx Command execution
section.
.It Ic (( Ar expression Cm ))
The arithmetic expression
.Ar expression
is evaluated; equivalent to
.Ic let Ar expression
(see
.Sx Arithmetic expressions
and the
.Ic let
command, below).
.It Ic [[ Ar expression Cm ]]
Similar to the
.Ic test
and
.Ic \&[ No ... Cm \&]
commands (described later), with the following exceptions:
.Bl -bullet -offset indent
.It
Field splitting and file name generation are not performed on arguments.
.It
The
.Fl a
.Pq AND
and
.Fl o
.Pq OR
operators are replaced with
.Ql &&
and
.Ql || ,
respectively.
.It
Operators (e.g.\&
.Sq Fl f ,
.Sq = ,
.Sq \&! )
must be unquoted.
.It
The second operand of the
.Sq = ,
.Sq ==
and
.Sq !=
expressions are patterns (e.g. the comparison
.Ic [[ foobar = f*r ]]
succeeds).
.It
The
.Ql <
and
.Ql >
binary operators do not need to be quoted with the
.Ql \e
character.
.It
The single argument form of
.Ic test ,
which tests if the argument has a non-zero length, is not valid; explicit
operators must always be used e.g. instead of
.No \&[ Ar str No \&]
use
.No \&[[ -n Ar str No \&]] .
.It
Parameter, command, and arithmetic substitutions are performed as expressions
are evaluated and lazy expression evaluation is used for the
.Ql &&
and
.Ql ||
operators.
This means that in the following statement,
.Ic $(< foo)
is evaluated if and only if the file
.Pa foo
exists and is readable:
.Bd -literal -offset indent
$ [[ -r foo && $(< foo) = b*r ]]
.Ed
.El
.El
.Ss Quoting
Quoting is used to prevent the shell from treating characters or words
specially.
There are three methods of quoting.
First,
.Ql \e
quotes the following character, unless it is at the end of a line, in which
case both the
.Ql \e
and the newline are stripped.
Second, a single quote
.Pq Sq '
quotes everything up to the next single quote (this may span lines).
Third, a double quote
.Pq Sq \&"
quotes all characters, except
.Ql $ ,
.Ql `
and
.Ql \e ,
up to the next unquoted double quote.
.Ql $
and
.Ql `
inside double quotes have their usual meaning (i.e. parameter, command, or
arithmetic substitution) except no field splitting is carried out on the
results of double-quoted substitutions.
If a
.Ql \e
inside a double-quoted string is followed by
.Ql \e ,
.Ql $ ,
.Ql ` ,
or
.Ql \&" ,
it is replaced by the second character; if it is followed by a newline, both
the
.Ql \e
and the newline are stripped; otherwise, both the
.Ql \e
and the character following are unchanged.
.Ss Aliases
There are two types of aliases: normal command aliases and tracked aliases.
Command aliases are normally used as a short hand for a long or often used
command.
The shell expands command aliases (i.e. substitutes the alias name
for its value) when it reads the first word of a command.
An expanded alias is re-processed to check for more aliases.
If a command alias ends in a
space or tab, the following word is also checked for alias expansion.
The alias expansion process stops when a word that is not an alias is found,
when a quoted word is found, or when an alias word that is currently being
expanded is found.
.Pp
The following command aliases are defined automatically by the shell:
.Pp
.Bl -item -compact -offset indent
.It
.Ic autoload Ns ='typeset -fu'
.It
.Ic functions Ns ='typeset -f'
.It
.Ic hash Ns ='alias -t'
.It
.Ic history Ns ='fc -l'
.It
.Ic integer Ns ='typeset -i'
.It
.Ic local Ns ='typeset'
.It
.Ic login Ns ='exec login'
.It
.Ic nohup Ns ='nohup '
.It
.Ic r Ns ='fc -s'
.It
.Ic stop Ns ='kill -STOP'
.El
.Pp
Tracked aliases allow the shell to remember where it found a particular
command.
The first time the shell does a path search for a command that is
marked as a tracked alias, it saves the full path of the command.
The next
time the command is executed, the shell checks the saved path to see that it
is still valid, and if so, avoids repeating the path search.
Tracked aliases can be listed and created using
.Ic alias -t .
Note that changing the
.Ev PATH
parameter clears the saved paths for all tracked aliases.
If the
.Ic trackall
option is set (i.e.\&
.Ic set -o Ic trackall
or
.Ic set -h ) ,
the shell tracks all commands.
This option is set automatically for non-interactive shells.
For interactive shells, only the following commands are
automatically tracked:
.Xr cat 1 ,
.Xr cc 1 ,
.Xr chmod 1 ,
.Xr cp 1 ,
.Xr date 1 ,
.Xr ed 1 ,
.Sy emacs ,
.Xr grep 1 ,
.Xr ls 1 ,
.Xr mail 1 ,
.Xr make 1 ,
.Xr mv 1 ,
.Xr pr 1 ,
.Xr rm 1 ,
.Xr sed 1 ,
.Xr sh 1 ,
.Xr vi 1 ,
and
.Xr who 1 .
.Ss Substitution
The first step the shell takes in executing a simple-command is to perform
substitutions on the words of the command.
There are three kinds of
substitution: parameter, command, and arithmetic.
Parameter substitutions,
which are described in detail in the next section, take the form
.Pf $ Ar name
or
.Pf ${ Ar ... Ns } ;
command substitutions take the form
.Pf $( Ar command )
or
.Pf ` Ar command Ns ` ;
and arithmetic substitutions take the form
.Pf $(( Ar expression ) ) .
.Pp
If a substitution appears outside of double quotes, the results of the
substitution are generally subject to word or field splitting according to
the current value of the
.Ev IFS
parameter.
The
.Ev IFS
parameter specifies a list of characters which are used to break a string up
into several words; any characters from the set space, tab, and newline that
appear in the
.Ev IFS
characters are called
.Dq IFS whitespace .
Sequences of one or more
.Ev IFS
whitespace characters, in combination with zero or one
.Pf non- Ev IFS
whitespace
characters, delimit a field.
As a special case, leading and trailing
.Ev IFS
whitespace is stripped (i.e. no leading or trailing empty field is created by
it); leading
.Pf non- Ev IFS
whitespace does create an empty field.
.Pp
Example: If
.Ev IFS
is set to
.Dq <space>: ,
and VAR is set to
.Dq <space>A<space>:<space><space>B::D ,
the substitution for $VAR results in four fields:
.Sq A ,
.Sq B ,
.Sq
(an empty field),
and
.Sq D .
Note that if the
.Ev IFS
parameter is set to the
.Dv NULL
string, no field splitting is done; if the parameter is unset, the default
value of space, tab, and newline is used.
.Pp
Also, note that the field splitting applies only to the immediate result of
the substitution.
Using the previous example, the substitution for $VAR:E
results in the fields:
.Sq A ,
.Sq B ,
.Sq ,
and
.Sq D:E ,
not
.Sq A ,
.Sq B ,
.Sq ,
.Sq D ,
and
.Sq E .
This behavior is POSIX compliant, but incompatible with some other shell
implementations which do field splitting on the word which contained the
substitution or use
.Dv IFS
as a general whitespace delimiter.
.Pp
The results of substitution are, unless otherwise specified, also subject to
brace expansion and file name expansion (see the relevant sections below).
.Pp
A command substitution is replaced by the output generated by the specified
command, which is run in a subshell.
For
.Pf $( Ar command )
substitutions, normal quoting rules are used when