xref: /illumos-gate/usr/src/man/man1/ksh93.1 (revision bbf21555)
1c10c16deSRichard Lowe'\" te
2c10c16deSRichard Lowe.\" Copyright (c) 1982-2007 AT&T Knowledge Ventures
3b30d1939SAndy Fiddaman.\" To view license terms, see http://www.eclipse.org/org/documents/epl-v10.html
4c10c16deSRichard Lowe.\" Portions Copyright (c) 2009, Sun Microsystems, Inc.
5b30d1939SAndy Fiddaman.\" Portions Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
6e49fc963SAndy Fiddaman.Dd March 8, 2021
7e49fc963SAndy Fiddaman.Dt KSH93 1
8e49fc963SAndy Fiddaman.Os
9e49fc963SAndy Fiddaman.Sh NAME
10e49fc963SAndy Fiddaman.Nm ksh93 ,
11e49fc963SAndy Fiddaman.Nm rksh93
12e49fc963SAndy Fiddaman.Nd  Korn Shell, a standard and restricted command and programming language
13e49fc963SAndy Fiddaman.Sh SYNOPSIS
14e49fc963SAndy Fiddaman.Nm ksh93
15e49fc963SAndy Fiddaman.Op Sy \&+ Ns Fl abcefhikmnoprstuvxBCD
16e49fc963SAndy Fiddaman.Op Fl R Ar file
17e49fc963SAndy Fiddaman.Op Sy \&+ Ns Fl o Ar option
18e49fc963SAndy Fiddaman\&...
19e49fc963SAndy Fiddaman.Op Fl
20e49fc963SAndy Fiddaman.Op Ar arg No ...
21e49fc963SAndy Fiddaman.Nm rksh93
22e49fc963SAndy Fiddaman.Op Sy \&+ Ns Fl abcefhikmnoprstuvxBCD
23e49fc963SAndy Fiddaman.Op Fl R Ar file
24e49fc963SAndy Fiddaman.Op Sy \&+ Ns Fl o Ar option
25e49fc963SAndy Fiddaman\&...
26e49fc963SAndy Fiddaman.Op Fl
27e49fc963SAndy Fiddaman.Op Ar arg No ...
28e49fc963SAndy Fiddaman.Sh DESCRIPTION
29e49fc963SAndy Fiddaman.Nm
30e49fc963SAndy Fiddamanis a command and programming language that executes commands read
31e49fc963SAndy Fiddamanfrom a terminal or a file.
32e49fc963SAndy Fiddaman.Nm rksh93
33e49fc963SAndy Fiddamanis a restricted version of the command interpreter
34e49fc963SAndy Fiddaman.Nm ksh93 .
35e49fc963SAndy Fiddaman.Nm rksh93
36e49fc963SAndy Fiddamanis used to set up login names and execution environments whose capabilities are
37e49fc963SAndy Fiddamanmore controlled than those of the standard shell.
38e49fc963SAndy Fiddaman.Pp
39e49fc963SAndy FiddamanSee
40e49fc963SAndy Fiddaman.Sx Invocation
41e49fc963SAndy Fiddamanfor the meaning of arguments to the shell.
42e49fc963SAndy Fiddaman.Ss "Definitions"
43e49fc963SAndy FiddamanA
44e49fc963SAndy Fiddaman.Sy metacharacter
45e49fc963SAndy Fiddamanis defined as one of the following characters:
46e49fc963SAndy Fiddaman.Pp
47e49fc963SAndy Fiddaman.Dl ; & ( \  ) | < > NEWLINE SPACE TAB
48e49fc963SAndy Fiddaman.Pp
49e49fc963SAndy FiddamanA
50e49fc963SAndy Fiddaman.Sy blank
51e49fc963SAndy Fiddamanis a TAB or a SPACE.
52e49fc963SAndy Fiddaman.Pp
53e49fc963SAndy FiddamanAn
54e49fc963SAndy Fiddaman.Sy identifier
55e49fc963SAndy Fiddamanis a sequence of letters, digits, or underscores starting with a letter or
56e49fc963SAndy Fiddamanunderscore.
57e49fc963SAndy FiddamanIdentifiers are used as components of variable names.
58e49fc963SAndy Fiddaman.Pp
59e49fc963SAndy FiddamanA
60e49fc963SAndy Fiddaman.Sy vname
61e49fc963SAndy Fiddamanis a sequence of one or more identifiers separated by a period
62e49fc963SAndy Fiddaman.Pq Sy \&.
63e49fc963SAndy Fiddamanand optionally preceded by a period
64e49fc963SAndy Fiddaman.Pq Sy \&. .
65e49fc963SAndy Fiddaman.Sy vname Ns s
66e49fc963SAndy Fiddamanare used as function and variable names.
67e49fc963SAndy Fiddaman.Pp
68e49fc963SAndy FiddamanA
69e49fc963SAndy Fiddaman.Sy word
70e49fc963SAndy Fiddamanis a sequence of characters from the character set defined by the current
71e49fc963SAndy Fiddamanlocale, excluding non-quoted
72e49fc963SAndy Fiddaman.Sy metacharacter Ns s .
73e49fc963SAndy Fiddaman.Pp
74e49fc963SAndy FiddamanA
75e49fc963SAndy Fiddaman.Sy command
76e49fc963SAndy Fiddamanis a sequence of characters in the syntax of the shell language.
77e49fc963SAndy FiddamanThe shell reads each command and carries out the desired action either directly
78e49fc963SAndy Fiddamanor by invoking separate utilities.
79e49fc963SAndy FiddamanA built-in command is a command that is carried out by the shell itself without
80e49fc963SAndy Fiddamancreating a separate process.
81e49fc963SAndy FiddamanSome commands are built-in purely for convenience and are not documented in
82e49fc963SAndy Fiddamanthis manual page.
83e49fc963SAndy FiddamanBuilt-ins that cause side effects in the shell environment and built-ins that
84e49fc963SAndy Fiddamanare found before performing a path search
85e49fc963SAndy Fiddaman.Pq see Sx Execution
86e49fc963SAndy Fiddamanare documented in this manual page.
87e49fc963SAndy FiddamanFor historical reasons, some of these built-ins behave differently than other
88e49fc963SAndy Fiddamanbuilt-ins and are called special built-ins.
89e49fc963SAndy Fiddaman.Ss "Commands"
90e49fc963SAndy FiddamanA
91e49fc963SAndy Fiddaman.Sy simple-command
92e49fc963SAndy Fiddamanis a list of variable assignments
93e49fc963SAndy Fiddaman.Pq see Sx Variable Assignments
94e49fc963SAndy Fiddamanor a sequence of
95e49fc963SAndy Fiddaman.Sy blank Ns -separated
96e49fc963SAndy Fiddamanwords which can be preceded by a list of variable assignments.
97e49fc963SAndy FiddamanSee the
98e49fc963SAndy Fiddaman.Sx Environment
99e49fc963SAndy Fiddamansection of this manual page.
100e49fc963SAndy Fiddaman.Pp
101e49fc963SAndy FiddamanThe first word specifies the name of the command to be executed.
102e49fc963SAndy FiddamanExcept as specified in this section, the remaining words are passed as
103e49fc963SAndy Fiddamanarguments to the invoked command.
104e49fc963SAndy FiddamanThe command name is passed as argument 0.
105e49fc963SAndy FiddamanSee
106e49fc963SAndy Fiddaman.Xr exec 2 .
107e49fc963SAndy FiddamanThe
108e49fc963SAndy Fiddaman.Em value
109e49fc963SAndy Fiddamanof a simple-command is its exit status.
110e49fc963SAndy FiddamanIf it terminates normally, its value is between
111e49fc963SAndy Fiddaman.Sy 0
112e49fc963SAndy Fiddamanand
113e49fc963SAndy Fiddaman.Sy 255 .
114e49fc963SAndy FiddamanIf it terminates abnormally, its value is
115e49fc963SAndy Fiddaman.Sy 256 +
116e49fc963SAndy Fiddaman.Em signum .
117e49fc963SAndy FiddamanThe name of the signal corresponding to the exit status can be obtained by way
118e49fc963SAndy Fiddamanof the
119e49fc963SAndy Fiddaman.Fl l
120e49fc963SAndy Fiddamanoption of the
121e49fc963SAndy Fiddaman.Ic kill
122e49fc963SAndy Fiddamanbuilt-in utility.
123e49fc963SAndy Fiddaman.Pp
124e49fc963SAndy FiddamanA
125e49fc963SAndy Fiddaman.Sy pipeline
126e49fc963SAndy Fiddamanis a sequence of one or more commands separated by
127e49fc963SAndy Fiddaman.Sy \&| .
128c10c16deSRichard LoweThe standard output of each command but the last is connected by a
129e49fc963SAndy Fiddaman.Xr pipe 2
130e49fc963SAndy Fiddamanto the standard input of the next command.
131e49fc963SAndy FiddamanEach command, except possibly the last, is run as a separate process.
132e49fc963SAndy FiddamanThe shell waits for the last command to terminate.
133e49fc963SAndy FiddamanThe exit status of a pipeline is the exit status of the last command unless the
134e49fc963SAndy Fiddaman.Sy pipefail
135e49fc963SAndy Fiddamanoption is enabled.
136e49fc963SAndy FiddamanEach pipeline can be preceded by the reserved word
137e49fc963SAndy Fiddaman.Sy \&! .
138e49fc963SAndy FiddamanThis causes the exit status of the
139e49fc963SAndy Fiddamanpipeline to become
140e49fc963SAndy Fiddaman.Sy 0
141e49fc963SAndy Fiddamanif the exit status of the last command is
142e49fc963SAndy Fiddaman.Sy non-zero ,
143e49fc963SAndy Fiddamanand
144e49fc963SAndy Fiddaman.Sy 1
145e49fc963SAndy Fiddamanif the exit status of the last command is
146e49fc963SAndy Fiddaman.Sy 0 .
147e49fc963SAndy Fiddaman.Pp
148e49fc963SAndy FiddamanA
149e49fc963SAndy Fiddaman.Sy list
150e49fc963SAndy Fiddamanis a sequence of one or more pipelines separated by
151e49fc963SAndy Fiddaman.Sy \&; ,
152e49fc963SAndy Fiddaman.Sy \&& ,
153e49fc963SAndy Fiddaman.Sy \&|& ,
154e49fc963SAndy Fiddaman.Sy \&&& ,
155e49fc963SAndy Fiddamanor
156e49fc963SAndy Fiddaman.Sy \&| ,
157e49fc963SAndy Fiddamanand optionally terminated by
158e49fc963SAndy Fiddaman.Sy \&; ,
159e49fc963SAndy Fiddaman.Sy \&& ,
160e49fc963SAndy Fiddamanor
161e49fc963SAndy Fiddaman.Sy \&|& .
162e49fc963SAndy FiddamanOf these
163e49fc963SAndy Fiddamanfive symbols,
164e49fc963SAndy Fiddaman.Sy \&; ,
165e49fc963SAndy Fiddaman.Sy \&& ,
166e49fc963SAndy Fiddamanand
167e49fc963SAndy Fiddaman.Sy \&|&
168e49fc963SAndy Fiddamanhave equal precedence, which is lower than that of
169e49fc963SAndy Fiddaman.Sy \&&&
170e49fc963SAndy Fiddamanand
171e49fc963SAndy Fiddaman.Sy || .
172e49fc963SAndy FiddamanThe symbols
173e49fc963SAndy Fiddaman.Sy \&&&
174e49fc963SAndy Fiddamanand
175e49fc963SAndy Fiddaman.Sy ||
176e49fc963SAndy Fiddamanhave equal precedence.
177e49fc963SAndy Fiddaman.Pp
178e49fc963SAndy FiddamanA semicolon
179e49fc963SAndy Fiddaman.Pq Sy \&;
180e49fc963SAndy Fiddamancauses sequential execution of the preceding pipeline.
181e49fc963SAndy FiddamanAn ampersand
182e49fc963SAndy Fiddaman.Pq Sy \&&
183e49fc963SAndy Fiddamancauses asynchronous execution of the preceding pipeline, that is, the shell
184e49fc963SAndy Fiddamandoes
185e49fc963SAndy Fiddaman.Em not
186e49fc963SAndy Fiddamanwait for that pipeline to finish.
187e49fc963SAndy FiddamanThe symbol
188e49fc963SAndy Fiddaman.Sy \&|&
189e49fc963SAndy Fiddamancauses asynchronous execution of the preceding pipeline with a two-way pipe
190e49fc963SAndy Fiddamanestablished to the parent shell.
191e49fc963SAndy FiddamanThe standard input and output of the spawned pipeline can be written to and
192e49fc963SAndy Fiddamanread from by the parent shell by applying the redirection operators
193e49fc963SAndy Fiddaman.Sy \&<&
194e49fc963SAndy Fiddamanand
195e49fc963SAndy Fiddaman.Sy \&>&
196e49fc963SAndy Fiddamanwith
197e49fc963SAndy Fiddaman.Cm arg p
198e49fc963SAndy Fiddamanto
199e49fc963SAndy Fiddamancommands and by using
200e49fc963SAndy Fiddaman.Fl p
201e49fc963SAndy Fiddamanoption of the built-in commands
202e49fc963SAndy Fiddaman.Ic read
203e49fc963SAndy Fiddamanand
204e49fc963SAndy Fiddaman.Ic print .
205e49fc963SAndy FiddamanThe symbol
206e49fc963SAndy Fiddaman.Sy \&&&
207e49fc963SAndy Fiddaman.Pq Sy ||
208e49fc963SAndy Fiddamancauses the
209e49fc963SAndy Fiddaman.Ar list
210e49fc963SAndy Fiddamanfollowing it to be executed only if the preceding pipeline returns a zero
211e49fc963SAndy Fiddaman.Pq non-zero
212e49fc963SAndy Fiddamanvalue.
213e49fc963SAndy FiddamanOne or more NEWLINEs can appear in a
214e49fc963SAndy Fiddaman.Ar list
215e49fc963SAndy Fiddamaninstead of a semicolon, to delimit a command.
216e49fc963SAndy FiddamanThe first
217e49fc963SAndy Fiddaman.Ar item
218e49fc963SAndy Fiddamanof the first
219e49fc963SAndy Fiddaman.Ar pipeline
220e49fc963SAndy Fiddamanof a
221e49fc963SAndy Fiddaman.Ar list
222e49fc963SAndy Fiddamanthat is a simple command not beginning with a redirection, and not occurring
223e49fc963SAndy Fiddamanwithin a
224e49fc963SAndy Fiddaman.Ic while ,
225e49fc963SAndy Fiddaman.Ic until ,
226e49fc963SAndy Fiddamanor
227e49fc963SAndy Fiddaman.Ic if
228e49fc963SAndy Fiddaman.Ar list ,
229e49fc963SAndy Fiddamancan be preceded by a semicolon.
230e49fc963SAndy FiddamanThis semicolon is ignored unless the
231e49fc963SAndy Fiddaman.Sy showme
232e49fc963SAndy Fiddamanoption is enabled as described with the
233e49fc963SAndy Fiddaman.Ic set
234e49fc963SAndy Fiddamanbuilt-in.
235e49fc963SAndy Fiddaman.Pp
236e49fc963SAndy FiddamanA
237e49fc963SAndy Fiddaman.Sy command
238e49fc963SAndy Fiddamanis either a simple-command or one of commands in the following list.
239e49fc963SAndy FiddamanUnless otherwise stated, the value returned by a command is that of the
240c10c16deSRichard Lowelast simple-command executed in the command.
241e49fc963SAndy Fiddaman.Pp
242e49fc963SAndy Fiddaman.Bl -tag -width Ds -compact
243e49fc963SAndy Fiddaman.It Xo
244e49fc963SAndy Fiddaman.Ic for Ar vname
245e49fc963SAndy Fiddaman.Op Cm in Ar word No ...
246e49fc963SAndy Fiddaman.Ic ;do Ar list Ic ;done
247e49fc963SAndy Fiddaman.Xc
248e49fc963SAndy Fiddaman.Pp
249e49fc963SAndy FiddamanEach time a
250e49fc963SAndy Fiddaman.Ic for
251e49fc963SAndy Fiddamancommand is executed,
252e49fc963SAndy Fiddaman.Ar vname
253e49fc963SAndy Fiddamanis set to the next
254e49fc963SAndy Fiddaman.Ar word
255e49fc963SAndy Fiddamantaken from the
256e49fc963SAndy Fiddaman.Ic in
257e49fc963SAndy Fiddaman.Ar word
258e49fc963SAndy Fiddamanlist.
259e49fc963SAndy FiddamanIf
260e49fc963SAndy Fiddaman.Ic in
261e49fc963SAndy Fiddaman.Ar word ...
262e49fc963SAndy Fiddamanis omitted, the
263e49fc963SAndy Fiddaman.Ic for
264e49fc963SAndy Fiddamancommand executes the
265e49fc963SAndy Fiddaman.Ic do
266e49fc963SAndy Fiddaman.Ar list
267e49fc963SAndy Fiddamanonce for each positional parameter that is set starting from 1.
268e49fc963SAndy FiddamanExecution ends when there are no more words in the list.
269e49fc963SAndy FiddamanSee
270e49fc963SAndy Fiddaman.Sx Parameter Expansion .
271e49fc963SAndy Fiddaman.Pp
272e49fc963SAndy Fiddaman.It Xo
273e49fc963SAndy Fiddaman.Ic for
274e49fc963SAndy Fiddaman.Sy ((
275e49fc963SAndy Fiddaman.Op Ar expr1
276e49fc963SAndy Fiddaman.Sy \&; Op Ar expr2
277e49fc963SAndy Fiddaman.Sy \&; Op Ar expr3
278e49fc963SAndy Fiddaman.Sy ))
279e49fc963SAndy Fiddaman.Ic ;do Ar list Ic ;done
280e49fc963SAndy Fiddaman.Xc
281e49fc963SAndy Fiddaman.Pp
282e49fc963SAndy FiddamanThe arithmetic expression
283e49fc963SAndy Fiddaman.Ar expr1
284e49fc963SAndy Fiddamanis evaluated first.
285e49fc963SAndy FiddamanThe arithmetic expression
286e49fc963SAndy Fiddaman.Ar expr2
287e49fc963SAndy Fiddamanis repeatedly evaluated until it evaluates to
288e49fc963SAndy Fiddaman.Sy zero
289e49fc963SAndy Fiddamanand when
290e49fc963SAndy Fiddaman.Sy non-zero ,
291e49fc963SAndy Fiddaman.Ar list
292e49fc963SAndy Fiddamanis executed and the arithmetic expression
293e49fc963SAndy Fiddaman.Ar expr3
294e49fc963SAndy Fiddamanis evaluated.
295e49fc963SAndy FiddamanIf any expression is omitted, then it behaves as if it evaluated to
296e49fc963SAndy Fiddaman.Sy 1 .
297e49fc963SAndy FiddamanSee
298e49fc963SAndy Fiddaman.Sx Arithmetic Evaluation .
299e49fc963SAndy Fiddaman.Pp
300e49fc963SAndy Fiddaman.It Xo
301e49fc963SAndy Fiddaman.Ic select Ar vname
302e49fc963SAndy Fiddaman.Op Sy in Ar word No ...
303e49fc963SAndy Fiddaman.Ic ;do Ar list Ic ;done
304e49fc963SAndy Fiddaman.Xc
305e49fc963SAndy Fiddaman.Pp
306e49fc963SAndy FiddamanA
307e49fc963SAndy Fiddaman.Ic select
308e49fc963SAndy Fiddamancommand prints on standard error (file descriptor 2) the set of
309e49fc963SAndy Fiddaman.Ar words ,
310e49fc963SAndy Fiddamaneach preceded by a number.
311e49fc963SAndy FiddamanIf
312e49fc963SAndy Fiddaman.Ic in Ar word ...
313e49fc963SAndy Fiddamanis omitted, the positional parameters starting from
314e49fc963SAndy Fiddaman.Sy 1
315e49fc963SAndy Fiddamanare used instead.
316e49fc963SAndy FiddamanSee
317e49fc963SAndy Fiddaman.Sx Parameter Expansion .
318e49fc963SAndy FiddamanThe
319e49fc963SAndy Fiddaman.Ev PS3
320e49fc963SAndy Fiddamanprompt is printed and a line is read from the standard input.
321e49fc963SAndy FiddamanIf this line consists of the number of one of the listed
322e49fc963SAndy Fiddaman.Ar word Ns No s ,
323e49fc963SAndy Fiddamanthen the value of the variable
324e49fc963SAndy Fiddaman.Ar vname
325e49fc963SAndy Fiddamanis set to the
326e49fc963SAndy Fiddaman.Ar word
327e49fc963SAndy Fiddamancorresponding to this number.
328e49fc963SAndy FiddamanIf this line is empty, the selection list is printed again.
329e49fc963SAndy FiddamanOtherwise the value of the variable
330e49fc963SAndy Fiddaman.Ar vname
331e49fc963SAndy Fiddamanis set to
332e49fc963SAndy Fiddaman.Dv NULL .
333e49fc963SAndy FiddamanThe contents of the line read from standard input is saved in the variable
334e49fc963SAndy Fiddaman.Ev REPLY .
335e49fc963SAndy FiddamanThe
336e49fc963SAndy Fiddaman.Ar list
337e49fc963SAndy Fiddamanis executed for each selection until a break or
338e49fc963SAndy Fiddaman.Dv EOF
339e49fc963SAndy Fiddamanis encountered.
340e49fc963SAndy FiddamanIf the
341e49fc963SAndy Fiddaman.Ev REPLY
342e49fc963SAndy Fiddamanvariable is set to
343e49fc963SAndy Fiddaman.Dv NULL
344e49fc963SAndy Fiddamanby the execution of
345e49fc963SAndy Fiddaman.Ar list ,
346e49fc963SAndy Fiddamanthe selection list is printed before displaying the
347e49fc963SAndy Fiddaman.Ev PS3
348e49fc963SAndy Fiddamanprompt for the next selection.
349e49fc963SAndy Fiddaman.Pp
350e49fc963SAndy Fiddaman.It Xo
351e49fc963SAndy Fiddaman.Ic case Ar word Ic in
352e49fc963SAndy Fiddaman.Oo \&
353e49fc963SAndy Fiddaman.Op Sy \&(
354e49fc963SAndy Fiddaman.Ar pattern Oo \&| Ar pattern Oc No ... Sy \&)
355e49fc963SAndy Fiddaman.Ar list Sy ;;
356e49fc963SAndy Fiddaman.Oc No ...
357e49fc963SAndy Fiddaman.Ic esac
358e49fc963SAndy Fiddaman.Xc
359e49fc963SAndy Fiddaman.Pp
360e49fc963SAndy FiddamanA
361e49fc963SAndy Fiddaman.Ic case
362e49fc963SAndy Fiddamancommand executes the
363e49fc963SAndy Fiddaman.Ar list
364e49fc963SAndy Fiddamanassociated with the first
365e49fc963SAndy Fiddaman.Ar pattern
366e49fc963SAndy Fiddamanthat matches
367e49fc963SAndy Fiddaman.Ar word .
368e49fc963SAndy FiddamanThe form of the patterns is the same as that used for file name generation.
369e49fc963SAndy FiddamanSee
370e49fc963SAndy Fiddaman.Sx File Name Generation .
371e49fc963SAndy Fiddaman.Pp
372e49fc963SAndy FiddamanThe
373e49fc963SAndy Fiddaman.Sy \&;\&;
374e49fc963SAndy Fiddamanoperator causes execution of
375e49fc963SAndy Fiddaman.Ic case
376e49fc963SAndy Fiddamanto terminate.
377e49fc963SAndy FiddamanIf
378e49fc963SAndy Fiddaman.Sy \&;&
379e49fc963SAndy Fiddamanis used in place of
380e49fc963SAndy Fiddaman.Sy \&;\&;
381e49fc963SAndy Fiddamanthe next subsequent list, if any, is executed.
382e49fc963SAndy Fiddaman.Pp
383e49fc963SAndy Fiddaman.It Xo
384e49fc963SAndy Fiddaman.Ic if Ar list Ic ;then Ar list
385e49fc963SAndy Fiddaman.Op Ic ;elif Ar list Ic ;then Ar list
386e49fc963SAndy Fiddaman.No ...
387e49fc963SAndy Fiddaman.Op Ic ;else Ar list
388e49fc963SAndy Fiddaman.Ic ;fi
389e49fc963SAndy Fiddaman.Xc
390e49fc963SAndy Fiddaman.Pp
391e49fc963SAndy FiddamanThe
392e49fc963SAndy Fiddaman.Ar list
393e49fc963SAndy Fiddamanfollowing
394e49fc963SAndy Fiddaman.Ic if
395e49fc963SAndy Fiddamanis executed and, if it returns a
396e49fc963SAndy Fiddaman.Sy zero
397e49fc963SAndy Fiddamanexit status, the
398e49fc963SAndy Fiddaman.Ar list
399e49fc963SAndy Fiddamanfollowing the first
400e49fc963SAndy Fiddaman.Ic then
401e49fc963SAndy Fiddamanis executed.
402e49fc963SAndy FiddamanOtherwise, the
403e49fc963SAndy Fiddaman.Ar list
404e49fc963SAndy Fiddamanfollowing
405e49fc963SAndy Fiddaman.Ic elif
406e49fc963SAndy Fiddamanis executed, and, if its value is
407e49fc963SAndy Fiddaman.Sy zero ,
408e49fc963SAndy Fiddamanthe
409e49fc963SAndy Fiddaman.Ar list
410e49fc963SAndy Fiddamanfollowing the next
411e49fc963SAndy Fiddaman.Ic then
412e49fc963SAndy Fiddamanis executed.
413e49fc963SAndy FiddamanFailing each successive
414e49fc963SAndy Fiddaman.Ic elif
415e49fc963SAndy Fiddaman.Ar list ,
416e49fc963SAndy Fiddamanthe
417e49fc963SAndy Fiddaman.Ic else
418e49fc963SAndy Fiddaman.Ar list
419e49fc963SAndy Fiddamanis executed.
420e49fc963SAndy FiddamanIf the
421e49fc963SAndy Fiddaman.Ic if
422e49fc963SAndy Fiddaman.Ar list
423e49fc963SAndy Fiddamanhas
424e49fc963SAndy Fiddaman.Sy non-zero
425e49fc963SAndy Fiddamanexit status and there is no
426e49fc963SAndy Fiddaman.Ic else
427e49fc963SAndy Fiddaman.Ar list ,
428e49fc963SAndy Fiddamanthen the
429e49fc963SAndy Fiddaman.Ic if
430e49fc963SAndy Fiddamancommand returns a
431e49fc963SAndy Fiddaman.Sy zero
432c10c16deSRichard Loweexit status.
433e49fc963SAndy Fiddaman.Pp
434e49fc963SAndy Fiddaman.It Ic while Ar list Ic ;do Ar list Ic ;done
435e49fc963SAndy Fiddaman.It Ic until Ar list Ic ;do Ar list Ic ;done
436e49fc963SAndy Fiddaman.Pp
437e49fc963SAndy FiddamanA
438e49fc963SAndy Fiddaman.Ic while
439e49fc963SAndy Fiddamancommand repeatedly executes the while
440e49fc963SAndy Fiddaman.Ar list
441e49fc963SAndy Fiddamanand, if the exit status of the last command in the list is zero, executes the
442e49fc963SAndy Fiddaman.Ic do
443e49fc963SAndy Fiddaman.Ar list ,
444e49fc963SAndy Fiddamanotherwise the loop terminates.
445e49fc963SAndy FiddamanIf no commands in the
446e49fc963SAndy Fiddaman.Ic do
447e49fc963SAndy Fiddaman.Ar list
448e49fc963SAndy Fiddamanare executed, then the
449e49fc963SAndy Fiddaman.Ic while
450e49fc963SAndy Fiddamancommand returns a
451e49fc963SAndy Fiddaman.Sy zero
452e49fc963SAndy Fiddamanexit status.
453e49fc963SAndy Fiddaman.Ic until
454e49fc963SAndy Fiddamancan be used in place of
455e49fc963SAndy Fiddaman.Ic while
456e49fc963SAndy Fiddamanto negate the loop termination test.
457e49fc963SAndy Fiddaman.Pp
458e49fc963SAndy Fiddaman.It Sy (( Ns Ar expression Ns Sy ))
459e49fc963SAndy Fiddaman.Pp
460e49fc963SAndy FiddamanThe
461e49fc963SAndy Fiddaman.Ar expression is evaluated using the rules for arithmetic evaluation described
462e49fc963SAndy Fiddamanin this manual page.
463e49fc963SAndy FiddamanIf the value of the arithmetic expression is
464e49fc963SAndy Fiddaman.Sy non-zero ,
465e49fc963SAndy Fiddamanthe exit status is
466e49fc963SAndy Fiddaman.Sy 0 .
467e49fc963SAndy FiddamanOtherwise the exit status is
468e49fc963SAndy Fiddaman.Sy 1 .
469e49fc963SAndy Fiddaman.Pp
470e49fc963SAndy Fiddaman.It Sy \&( Ns Ar list Ns Sy \&)
471e49fc963SAndy Fiddaman.Pp
472e49fc963SAndy FiddamanExecute
473e49fc963SAndy Fiddaman.Ar list
474e49fc963SAndy Fiddamanin a separate environment.
475e49fc963SAndy FiddamanIf two adjacent open parentheses are needed for nesting, a SPACE must be
476e49fc963SAndy Fiddamaninserted to avoid evaluation as an arithmetic command as described in this
477e49fc963SAndy Fiddamansection.
478e49fc963SAndy Fiddaman.Pp
479e49fc963SAndy Fiddaman.It Sy { Ar list Ns Sy ;}
480e49fc963SAndy Fiddaman.Pp
481e49fc963SAndy Fiddaman.Ar list
482e49fc963SAndy Fiddamanis simply executed.
483e49fc963SAndy FiddamanUnlike the metacharacters,
484e49fc963SAndy Fiddaman.Sy \&(
485e49fc963SAndy Fiddamanand
486e49fc963SAndy Fiddaman.Sy \&) ,
487e49fc963SAndy Fiddaman.Sy \&{
488e49fc963SAndy Fiddamanand
489e49fc963SAndy Fiddaman.Sy \&}
490e49fc963SAndy Fiddamanare
491e49fc963SAndy Fiddaman.Sy reserved words
492e49fc963SAndy Fiddamanand must occur at the beginning of a line or after a
493e49fc963SAndy Fiddaman.Sy \&;
494e49fc963SAndy Fiddamanto be recognized.
495e49fc963SAndy Fiddaman.Pp
496e49fc963SAndy Fiddaman.It Sy [[ Ar expression Sy ]]
497e49fc963SAndy Fiddaman.Pp
498e49fc963SAndy FiddamanEvaluates
499e49fc963SAndy Fiddaman.Ar expression
500e49fc963SAndy Fiddamanand returns a
501e49fc963SAndy Fiddaman.Sy zero
502e49fc963SAndy Fiddamanexit status when
503e49fc963SAndy Fiddaman.Ar expression
504e49fc963SAndy Fiddamanis true.
505e49fc963SAndy FiddamanSee
506e49fc963SAndy Fiddaman.Sx Conditional Expressions
507e49fc963SAndy Fiddamanfor a description of
508e49fc963SAndy Fiddaman.Ar expression .
509e49fc963SAndy Fiddaman.Pp
510e49fc963SAndy Fiddaman.It Ic function Ar varname Sy { Ar list Sy ;}
511e49fc963SAndy Fiddaman.It Ar varname Sy \&() Sy { Ar list Sy ;}
512e49fc963SAndy Fiddaman.Pp
513e49fc963SAndy FiddamanDefine a function which is referenced by
514e49fc963SAndy Fiddaman.Ar varname .
515e49fc963SAndy FiddamanA function whose
516e49fc963SAndy Fiddaman.Ar varname
517e49fc963SAndy Fiddamancontains a dot
518e49fc963SAndy Fiddaman.Pq Sy \&.
519e49fc963SAndy Fiddamanis called a discipline function and the portion of the
520e49fc963SAndy Fiddaman.Ar varname
521e49fc963SAndy Fiddamanpreceding the last
522e49fc963SAndy Fiddaman.Sy \&.
523e49fc963SAndy Fiddamanmust refer to an existing variable.
524e49fc963SAndy Fiddaman.Pp
525e49fc963SAndy FiddamanThe body of the function is the
526e49fc963SAndy Fiddaman.Ar list
527e49fc963SAndy Fiddamanof commands between
528e49fc963SAndy Fiddaman.Sy {
529e49fc963SAndy Fiddamanand
530e49fc963SAndy Fiddaman.Sy } .
531e49fc963SAndy FiddamanA function defined with the
532e49fc963SAndy Fiddaman.Ic function
533e49fc963SAndy Fiddaman.Ar varname
534e49fc963SAndy Fiddamansyntax can also be used as an argument to the
535e49fc963SAndy Fiddaman.Sy \&.
536e49fc963SAndy Fiddamanspecial built-in command to get the equivalent behavior as if the
537e49fc963SAndy Fiddaman.Ar varname
538e49fc963SAndy Fiddaman.Sy ()
539e49fc963SAndy Fiddamansyntax were used to define it.
540e49fc963SAndy FiddamanSee
541e49fc963SAndy Fiddaman.Sx Functions .
542e49fc963SAndy Fiddaman.Pp
543e49fc963SAndy Fiddaman.It Ic namespace Ar identifier Sy { Ar list Sy };
544e49fc963SAndy Fiddaman.Pp
545e49fc963SAndy FiddamanDefines or uses the name space
546e49fc963SAndy Fiddaman.Ar identifier
547e49fc963SAndy Fiddamanand runs the commands in
548e49fc963SAndy Fiddaman.Ar list
549e49fc963SAndy Fiddamanin this name space.
550e49fc963SAndy FiddamanSee
551e49fc963SAndy Fiddaman.Sx Name Spaces .
552e49fc963SAndy Fiddaman.Pp
553e49fc963SAndy Fiddaman.It Ic time Op Ar pipeline
554e49fc963SAndy Fiddaman.Pp
555e49fc963SAndy FiddamanIf
556e49fc963SAndy Fiddaman.Ar pipeline
557e49fc963SAndy Fiddamanis omitted, the user and system time for the current shell and completed child
558e49fc963SAndy Fiddamanprocesses is printed on standard error.
559e49fc963SAndy FiddamanOtherwise,
560e49fc963SAndy Fiddaman.Ar pipeline
561e49fc963SAndy Fiddamanis executed and the elapsed time as well as the user and system time are
562e49fc963SAndy Fiddamanprinted on standard error.
563e49fc963SAndy FiddamanThe
564e49fc963SAndy Fiddaman.Ev TIMEFORMAT
565e49fc963SAndy Fiddamanvariable can be set to a format string that specifies how the timing
566e49fc963SAndy Fiddamaninformation should be displayed.
567e49fc963SAndy FiddamanSee
568e49fc963SAndy Fiddaman.Sx Shell Variables
569e49fc963SAndy Fiddamanfor a description of the
570e49fc963SAndy Fiddaman.Ev TIMEFORMAT
571e49fc963SAndy Fiddamanvariable.
572e49fc963SAndy Fiddaman.El
573e49fc963SAndy Fiddaman.Pp
574c10c16deSRichard LoweThe following reserved words are recognized as reserved only when they are the
575c10c16deSRichard Lowefirst word of a command and are not quoted:
576e49fc963SAndy Fiddaman.Bl -column -offset Ds xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx xxxxxxxxxxx
577e49fc963SAndy Fiddaman.It Cm case Ta Cm do Ta Cm done Ta Cm else
578e49fc963SAndy Fiddaman.It Cm elif Ta Cm esac Ta Cm for Ta Cm fi
579e49fc963SAndy Fiddaman.It Cm function Ta Cm if Ta Cm select Ta Cm then
580e49fc963SAndy Fiddaman.It Cm time Ta Cm until Ta Cm while Ta Sy { }
581e49fc963SAndy Fiddaman.It Sy [[ ]] Ta Sy \&! Ta Ta
582e49fc963SAndy Fiddaman.El
583e49fc963SAndy Fiddaman.Ss "Variable Assignments"
584c10c16deSRichard LoweOne or more variable assignments can start a simple command or can be arguments
585e49fc963SAndy Fiddamanto the
586e49fc963SAndy Fiddaman.Ic typeset ,
587e49fc963SAndy Fiddaman.Ic enum ,
588e49fc963SAndy Fiddaman.Ic export , or
589e49fc963SAndy Fiddaman.Ic readonly
590e49fc963SAndy Fiddamanspecial built-in commands.
591e49fc963SAndy FiddamanThe syntax for an
592e49fc963SAndy Fiddaman.Ar assignment
593e49fc963SAndy Fiddamanis of the form:
594e49fc963SAndy Fiddaman.Pp
595e49fc963SAndy Fiddaman.Bl -tag -width Ds -compact
596e49fc963SAndy Fiddaman.Sm off
597e49fc963SAndy Fiddaman.It Ar varname Sy = Ar word
598e49fc963SAndy Fiddaman.It Ar varname Oo Ar word Oc Sy = Ar word
599e49fc963SAndy Fiddaman.Sm on
600e49fc963SAndy Fiddaman.Pp
601e49fc963SAndy FiddamanNo space is permitted between
602e49fc963SAndy Fiddaman.Ar varname
603e49fc963SAndy Fiddamanand the
604e49fc963SAndy Fiddaman.Sy \&=
605e49fc963SAndy Fiddamanor between
606e49fc963SAndy Fiddaman.Sy \&=
607e49fc963SAndy Fiddamanand
608e49fc963SAndy Fiddaman.Ar word .
609e49fc963SAndy FiddamanThe variable
610e49fc963SAndy Fiddaman.Ar varname
611e49fc963SAndy Fiddamanis unset before the assignment.
612e49fc963SAndy Fiddaman.Pp
613e49fc963SAndy Fiddaman.Sm off
614e49fc963SAndy Fiddaman.It Ar varname Sy =( Ar assignlist Sy \&)
615e49fc963SAndy Fiddaman.Sm on
616e49fc963SAndy Fiddaman.Pp
617e49fc963SAndy FiddamanNo space is permitted between
618e49fc963SAndy Fiddaman.Ar varname
619e49fc963SAndy Fiddamanand the
620e49fc963SAndy Fiddaman.Sy = .
621e49fc963SAndy FiddamanAn
622e49fc963SAndy Fiddaman.Ar assignlist
623e49fc963SAndy Fiddamancan be one of the following:
624e49fc963SAndy Fiddaman.Bl -tag -width Ds
625e49fc963SAndy Fiddaman.It Ar word No ...
626e49fc963SAndy Fiddaman.Pp
627c10c16deSRichard LoweIndexed array assignment.
628e49fc963SAndy Fiddaman.Sm off
629e49fc963SAndy Fiddaman.It Oo Ar word Oc Sy = Ar word \  No ...
630e49fc963SAndy Fiddaman.Sm on
631e49fc963SAndy Fiddaman.Pp
632e49fc963SAndy FiddamanAssociative array assignment.
633e49fc963SAndy FiddamanIf prefixed by
634e49fc963SAndy Fiddaman.Ic typeset Fl a ,
635e49fc963SAndy Fiddamancreates an indexed array instead.
636e49fc963SAndy Fiddaman.It Ar assignment No ...
637e49fc963SAndy Fiddaman.Pp
638e49fc963SAndy FiddamanCompound variable assignment.
639e49fc963SAndy FiddamanThis creates a compound variable
640e49fc963SAndy Fiddaman.Ar varname
641e49fc963SAndy Fiddamanwith sub-variables of the form
642e49fc963SAndy Fiddaman.Ar varname.name ,
643e49fc963SAndy Fiddamanwhere
644e49fc963SAndy Fiddaman.Ar name
645e49fc963SAndy Fiddamanis the name
646e49fc963SAndy Fiddamanportion of assignment.
647e49fc963SAndy FiddamanThe value of
648e49fc963SAndy Fiddaman.Ar varname
649e49fc963SAndy Fiddamancontains all the assignment elements.
650e49fc963SAndy FiddamanAdditional assignments made to sub-variables of
651e49fc963SAndy Fiddaman.Ar varname
652e49fc963SAndy Fiddamanare also displayed as part of the value of
653e49fc963SAndy Fiddaman.Ar varname .
654e49fc963SAndy FiddamanIf no
655e49fc963SAndy Fiddaman.Ar assignment Ns No s
656e49fc963SAndy Fiddamanare specified,
657e49fc963SAndy Fiddaman.Ar varname
658e49fc963SAndy Fiddamanis a compound variable allowing subsequence child elements to be defined.
659e49fc963SAndy Fiddaman.It Ic typeset Oo Ar options Oc Ar assignment No ...
660e49fc963SAndy Fiddaman.Pp
661e49fc963SAndy FiddamanNested variable assignment.
662e49fc963SAndy FiddamanMultiple assignments can be specified by separating each of them with a
663e49fc963SAndy Fiddaman.Sy \&; .
664e49fc963SAndy FiddamanThe previous value is unset before the assignment.
665e49fc963SAndy Fiddaman.It Ic \&. Ar filename
666e49fc963SAndy Fiddaman.Pp
667e49fc963SAndy FiddamanInclude the assignment commands contained in
668e49fc963SAndy Fiddaman.Ar filename .
669e49fc963SAndy Fiddaman.El
670e49fc963SAndy Fiddaman.Pp
671e49fc963SAndy FiddamanIn addition, a
672e49fc963SAndy Fiddaman.Sy +=
673e49fc963SAndy Fiddamancan be used in place of the
674e49fc963SAndy Fiddaman.Sy \&=
675e49fc963SAndy Fiddamanto signify adding to or appending to the previous value.
676e49fc963SAndy FiddamanWhen
677e49fc963SAndy Fiddaman.Sy +=
678e49fc963SAndy Fiddamanis applied to an arithmetic type,
679e49fc963SAndy Fiddaman.Ar word
680e49fc963SAndy Fiddamanis evaluated as an arithmetic expression and added to the current value.
681e49fc963SAndy FiddamanWhen applied to a string variable, the value defined by
682e49fc963SAndy Fiddaman.Ar word
683e49fc963SAndy Fiddamanis appended to the value.
684e49fc963SAndy FiddamanFor compound assignments, the previous value is not unset and the new values
685e49fc963SAndy Fiddamanare appended to the current ones provided that the types are compatible.
686e49fc963SAndy FiddamanThe right hand side of a variable assignment undergoes all the expansion listed
687e49fc963SAndy Fiddamanbelow except word splitting, brace expansion, and file name generation.
688e49fc963SAndy FiddamanWhen the left hand side is an assignment is a compound variable and the right
689e49fc963SAndy Fiddamanhand is the name of a compound variable, the compound variable on the right
690e49fc963SAndy Fiddamanwill be copied or appended to the compound variable on the left.
691e49fc963SAndy Fiddaman.El
692e49fc963SAndy Fiddaman.Ss "Comments"
693e49fc963SAndy FiddamanA word beginning with
694e49fc963SAndy Fiddaman.Ic #
695e49fc963SAndy Fiddamancauses that word and all the following characters up to a NEWLINE to be
696e49fc963SAndy Fiddamancommented, or ignored.
697e49fc963SAndy Fiddaman.Ss "Aliasing"
698c10c16deSRichard LoweThe first word of each command is replaced by the text of an alias if an alias
699e49fc963SAndy Fiddamanfor this word has been defined.
700e49fc963SAndy FiddamanAn alias name consists of any number of characters excluding metacharacters,
701e49fc963SAndy Fiddamanquoting characters, file expansion characters, parameter expansion characters,
702e49fc963SAndy Fiddamancommand substitution characters, the characters
703e49fc963SAndy Fiddaman.Sy /
704e49fc963SAndy Fiddamanand
705e49fc963SAndy Fiddaman.Sy = .
706e49fc963SAndy FiddamanThe replacement string can contain any valid shell script including the
707e49fc963SAndy Fiddamanmetacharacters listed in the
708e49fc963SAndy Fiddaman.Sx Commands
709e49fc963SAndy Fiddamansection.
710e49fc963SAndy FiddamanThe first word of each command in the replaced text, other than any that are in
711e49fc963SAndy Fiddamanthe process of being replaced, are tested for aliases.
712e49fc963SAndy FiddamanIf the last character of the alias value is a BLANK then the word following the
713e49fc963SAndy Fiddamanalias is also checked for alias substitution.
714e49fc963SAndy Fiddaman.Pp
715c10c16deSRichard LoweAliases can be used to redefine built-in commands but cannot be used to
716e49fc963SAndy Fiddamanredefine the reserved words listed in the
717e49fc963SAndy Fiddaman.Sx Commands
718e49fc963SAndy Fiddamansection.
719e49fc963SAndy FiddamanAliases can be created and listed with the
720e49fc963SAndy Fiddaman.Ic alias
721e49fc963SAndy Fiddamancommand and can be removed with the
722e49fc963SAndy Fiddaman.Ic unalias
723e49fc963SAndy Fiddamancommand.
724e49fc963SAndy Fiddaman.Pp
725e49fc963SAndy FiddamanAliasing is performed when scripts are read, not while they are executed.
726e49fc963SAndy FiddamanFor an alias to take effect, the
727e49fc963SAndy Fiddaman.Ic alias
728e49fc963SAndy Fiddamandefinition command has to be executed before the command which references the
729e49fc963SAndy Fiddamanalias is read.
730e49fc963SAndy FiddamanThe following aliases are compiled into the shell but can be unset or
731e49fc963SAndy Fiddamanredefined:
732e49fc963SAndy Fiddaman.Bd -literal -offset Ds
733c10c16deSRichard Loweautoload='typeset -fu'
734c10c16deSRichard Lowecommand='command '
735b30d1939SAndy Fiddamancompound='typeset -C'
736c10c16deSRichard Lowefc=hist
737c10c16deSRichard Lowefloat='typeset -lE'
738c10c16deSRichard Lowefunctions='typeset -f'
739c10c16deSRichard Lowehash='alias -t --'
740c10c16deSRichard Lowehistory='hist -l'
741c10c16deSRichard Loweinteger='typeset -li'
742c10c16deSRichard Lowenameref='typeset -n'
743c10c16deSRichard Lowenohup='nohup '
744c10c16deSRichard Lower='hist -s'
745c10c16deSRichard Loweredirect='command exec'
746c10c16deSRichard Lowesource='command .'
747c10c16deSRichard Lowestop='kill -s STOP'
748c10c16deSRichard Lowesuspend='kill -s STOP $$'
749c10c16deSRichard Lowetimes='{ { time;} 2>&1;}'
750c10c16deSRichard Lowetype='whence -v'
751e49fc963SAndy Fiddaman.Ed
752e49fc963SAndy Fiddaman.Ss "Tilde Substitution"
753c10c16deSRichard LoweAfter alias substitution is performed, each word is checked to see if it begins
754e49fc963SAndy Fiddamanwith an unquoted tilde
755e49fc963SAndy Fiddaman.Pq Sy \&~ .
756e49fc963SAndy FiddamanFor tilde substitution,
757e49fc963SAndy Fiddaman.Ar word
758e49fc963SAndy Fiddamanalso refers to the
759e49fc963SAndy Fiddaman.Ar word
760e49fc963SAndy Fiddamanportion of parameter expansion.
761e49fc963SAndy FiddamanSee
762e49fc963SAndy Fiddaman.Sx Parameter Expansion .
763e49fc963SAndy Fiddaman.Pp
764e49fc963SAndy FiddamanIf it does, the word up to a
765e49fc963SAndy Fiddaman.Sy /
766e49fc963SAndy Fiddamanis checked to see if it matches a user name in the password database.
767e49fc963SAndy FiddamanIf a match is found, the
768e49fc963SAndy Fiddaman.Sy ~
769e49fc963SAndy Fiddamanand the matched login name are replaced by the login directory of the matched
770e49fc963SAndy Fiddamanuser.
771e49fc963SAndy FiddamanIf no match is found, the original text is left unchanged.
772e49fc963SAndy FiddamanA
773e49fc963SAndy Fiddaman.Sy ~
774e49fc963SAndy Fiddamanby itself, or in front of a
775e49fc963SAndy Fiddaman.Sy / ,
776e49fc963SAndy Fiddamanis replaced by
777e49fc963SAndy Fiddaman.Ev $HOME .
778e49fc963SAndy FiddamanA
779e49fc963SAndy Fiddaman.Sy ~
780e49fc963SAndy Fiddamanfollowed by a
781e49fc963SAndy Fiddaman.Sy +
782e49fc963SAndy Fiddamanor
783e49fc963SAndy Fiddaman.Sy -
784e49fc963SAndy Fiddamanis replaced by the value of
785e49fc963SAndy Fiddaman.Ev $PWD
786e49fc963SAndy Fiddamanand
787e49fc963SAndy Fiddaman.Ev $OLDPWD
788e49fc963SAndy Fiddamanrespectively.
789e49fc963SAndy Fiddaman.Pp
790e49fc963SAndy FiddamanIn addition, when expanding a
791e49fc963SAndy Fiddaman.Ar variable assignment ,
792e49fc963SAndy Fiddamantilde substitution is attempted when the value of the assignment begins with a
793e49fc963SAndy Fiddaman.Sy ~ ,
794e49fc963SAndy Fiddamanand when a
795e49fc963SAndy Fiddaman.Sy ~
796e49fc963SAndy Fiddamanappears after a colon
797e49fc963SAndy Fiddaman.Pq Sy \&: .
798e49fc963SAndy FiddamanThe
799e49fc963SAndy Fiddaman.Sy \&:
800e49fc963SAndy Fiddamanalso terminates a
801e49fc963SAndy Fiddaman.Sy ~
802c10c16deSRichard Lowelogin name.
803e49fc963SAndy Fiddaman.Ss "Command Substitution"
804c10c16deSRichard LoweThe standard output from a command enclosed in parentheses preceded by a dollar
805e49fc963SAndy Fiddamansign -
806e49fc963SAndy Fiddaman.Sy \&$ Ns Po Ar list Pc -
807e49fc963SAndy Fiddamanor in a brace group preceded by a dollar
808e49fc963SAndy Fiddamansign -
809e49fc963SAndy Fiddaman.Sy \&${ Ar list Ns Sy ;} ,
810e49fc963SAndy Fiddaman- or in a pair of grave accents -
811e49fc963SAndy Fiddaman.Sy ``
812e49fc963SAndy Fiddaman- can be used as part or all of a word.
813e49fc963SAndy FiddamanTrailing NEWLINEs are removed.
814e49fc963SAndy FiddamanIn the second case, the
815e49fc963SAndy Fiddaman.Sy {
816e49fc963SAndy Fiddamanand
817e49fc963SAndy Fiddaman.Sy }
818e49fc963SAndy Fiddamanare treated as a reserved words so that
819e49fc963SAndy Fiddaman.Sy {
820e49fc963SAndy Fiddamanmust be followed by a blank and
821e49fc963SAndy Fiddaman.Sy }
822e49fc963SAndy Fiddamanmust appear at the beginning of
823e49fc963SAndy Fiddamanthe line or follow a
824e49fc963SAndy Fiddaman.Sy \&; .
825e49fc963SAndy FiddamanIn the third (obsolete) form, the string between the quotes is processed for
826e49fc963SAndy Fiddamanspecial quoting characters before the command is executed.
827e49fc963SAndy FiddamanSee
828e49fc963SAndy Fiddaman.Sx Quoting .
829e49fc963SAndy Fiddaman.Pp
830e49fc963SAndy FiddamanThe command substitution
831e49fc963SAndy Fiddaman.Sy $(cat file)
832e49fc963SAndy Fiddamancan be replaced by the equivalent
833e49fc963SAndy Fiddamanbut faster
834e49fc963SAndy Fiddaman.Sy $(<file) .
835e49fc963SAndy FiddamanThe command substitution
836e49fc963SAndy Fiddaman.Sy $( Ns Ar n Sy \&<\&#\&)
837e49fc963SAndy Fiddamanexpands to the current byte offset for file descriptor
838e49fc963SAndy Fiddaman.Ar n .
839e49fc963SAndy FiddamanExcept for the second form, the command list is run in a subshell so that no
840e49fc963SAndy Fiddamanside effects are possible.
841e49fc963SAndy FiddamanFor the second form, the final
842e49fc963SAndy Fiddaman.Sy }
843e49fc963SAndy Fiddamanwill be recognized as a reserved word after any token.
844e49fc963SAndy Fiddaman.Ss "Arithmetic Substitution"
845c10c16deSRichard LoweAn arithmetic expression enclosed in double parentheses preceded by a dollar
846e49fc963SAndy Fiddamansign -
847e49fc963SAndy Fiddaman.Sy $(( Ns Ar arithmetic_expression Ns Sy ))
848e49fc963SAndy Fiddaman- is replaced by the value of the arithmetic expression within the double
849e49fc963SAndy Fiddamanparentheses.
850e49fc963SAndy Fiddaman.Ss "Process Substitution"
851e49fc963SAndy FiddamanEach command argument of the form
852e49fc963SAndy Fiddaman.Sy <( Ns Ar list Ns Sy \&)
853e49fc963SAndy Fiddamanor
854e49fc963SAndy Fiddaman.Sy >( Ns Ar list Ns Sy \&)
855e49fc963SAndy Fiddamanruns process
856e49fc963SAndy Fiddaman.Ar list
857e49fc963SAndy Fiddamanasynchronously connected to some file in
858e49fc963SAndy Fiddaman.Pa /dev/fd .
859e49fc963SAndy FiddamanThe name of this file becomes the argument to the command.
860e49fc963SAndy FiddamanIf the form with
861e49fc963SAndy Fiddaman.Sy >
862e49fc963SAndy Fiddamanis selected then writing on this file provides input for
863e49fc963SAndy Fiddaman.Ar list .
864e49fc963SAndy FiddamanIf
865e49fc963SAndy Fiddaman.Sy <
866e49fc963SAndy Fiddamanis used, then the file passed as an argument contains the output of the
867e49fc963SAndy Fiddaman.Ar list
868e49fc963SAndy Fiddamanprocess.
869e49fc963SAndy Fiddaman.Pp
870c10c16deSRichard LoweFor example,
871e49fc963SAndy Fiddaman.Bd -literal -offset Ds
872e49fc963SAndy Fiddamanpaste <(cut -f1 file1) <(cut -f3 file2) | tee \e
873e49fc963SAndy Fiddaman    >(process1) >(process2)
874e49fc963SAndy Fiddaman.Ed
875e49fc963SAndy Fiddaman.Pp
876e49fc963SAndy Fiddaman.Sy cut Ns No s
877e49fc963SAndy Fiddamanfields 1 and 3 from the files
878e49fc963SAndy Fiddaman.Ar file1
879e49fc963SAndy Fiddamanand
880e49fc963SAndy Fiddaman.Ar file2
881e49fc963SAndy Fiddamanrespectively,
882e49fc963SAndy Fiddaman.Sy paste Ns No s
883e49fc963SAndy Fiddamanthe results together, and sends it to the processes
884e49fc963SAndy Fiddaman.Ar process1
885e49fc963SAndy Fiddamanand
886e49fc963SAndy Fiddaman.Ar process2 .
887e49fc963SAndy FiddamanIt also displays the results to the standard output.
888e49fc963SAndy FiddamanThe file, which is passed as an argument to the command, is a UNIX
889e49fc963SAndy Fiddaman.Xr pipe 2 .
890e49fc963SAndy FiddamanPrograms that expect to
891e49fc963SAndy Fiddaman.Xr lseek 2
892e49fc963SAndy Fiddamanon the file do not work.
893e49fc963SAndy Fiddaman.Pp
894e49fc963SAndy FiddamanProcess substitution of the form
895e49fc963SAndy Fiddaman.Sy <( Ns Ar list Ns Sy \&)
896e49fc963SAndy Fiddamancan also be used
897e49fc963SAndy Fiddamanwith the
898e49fc963SAndy Fiddaman.Sy <
899e49fc963SAndy Fiddamanredirection operator which causes the output of list to be standard input or
900e49fc963SAndy Fiddamanthe input for whatever file descriptor is specified.
901e49fc963SAndy Fiddaman.Ss "Parameter Expansion"
902c10c16deSRichard LoweA parameter is a variable, one or more digits, or any of the characters
903e49fc963SAndy Fiddaman.Sy \&* ,
904e49fc963SAndy Fiddaman.Sy \&@ ,
905e49fc963SAndy Fiddaman.Sy \&# ,
906e49fc963SAndy Fiddaman.Sy \&? ,
907e49fc963SAndy Fiddaman.Sy \&- ,
908e49fc963SAndy Fiddaman.Sy \&$ ,
909e49fc963SAndy Fiddamanand
910e49fc963SAndy Fiddaman.Sy \&! .
911e49fc963SAndy FiddamanA variable is denoted by a
912e49fc963SAndy Fiddaman.Ar vname .
913e49fc963SAndy FiddamanTo create a variable whose
914e49fc963SAndy Fiddaman.Ar vname
915e49fc963SAndy Fiddamancontains a
916e49fc963SAndy Fiddaman.Sy \&. ,
917e49fc963SAndy Fiddamana variable whose
918e49fc963SAndy Fiddaman.Ar vname
919e49fc963SAndy Fiddamanconsists of everything before the last
920e49fc963SAndy Fiddaman.Sy \&.
921e49fc963SAndy Fiddamanmust already exist.
922e49fc963SAndy FiddamanA variable has a value and zero or more attributes.
923e49fc963SAndy FiddamanVariables can be assigned values and attributes by using the
924e49fc963SAndy Fiddaman.Ic typeset
925e49fc963SAndy Fiddamanspecial built-in command.
926e49fc963SAndy FiddamanThe attributes supported by the shell are described later with the
927e49fc963SAndy Fiddaman.Ic typeset
928e49fc963SAndy Fiddamanspecial built-in command.
929e49fc963SAndy FiddamanExported variables pass values and attributes to the environment.
930e49fc963SAndy Fiddaman.Pp
931e49fc963SAndy FiddamanThe shell supports both indexed and associative arrays.
932e49fc963SAndy FiddamanAn element of an array variable is referenced by a subscript.
933e49fc963SAndy FiddamanA subscript for an indexed array is denoted by an arithmetic expression,
934e49fc963SAndy Fiddaman.Pq see Sx Arithmetic Evaluation ,
935e49fc963SAndy Fiddamanbetween a
936e49fc963SAndy Fiddaman.Sy \&[
937e49fc963SAndy Fiddamanand a
938e49fc963SAndy Fiddaman.Sy \&] .
939e49fc963SAndy FiddamanTo assign values to an indexed array, use
940e49fc963SAndy Fiddaman.Ar vname Ns Sy =( Ns Ar value No ... Ns Sy \&)
941e49fc963SAndy Fiddamanor
942e49fc963SAndy Fiddaman.Sy set Fl A Ar vname value No ... .
943b30d1939SAndy FiddamanThe value of all subscripts must be in the range of
944e49fc963SAndy Fiddaman.Sy 0
945e49fc963SAndy Fiddamanto
946e49fc963SAndy Fiddaman.Sy 4,194,303 .
947e49fc963SAndy FiddamanA negative subscript is treated as an offset from the maximum current index +1
948e49fc963SAndy Fiddamanso that -1 refers to the last element.
949e49fc963SAndy FiddamanIndexed arrays can be declared with the
950e49fc963SAndy Fiddaman.Fl a
951e49fc963SAndy Fiddamanoption to
952e49fc963SAndy Fiddaman.Ic typeset .
953e49fc963SAndy FiddamanIndexed arrays need not be declared.
954e49fc963SAndy FiddamanAny reference to a variable with a valid subscript is legal and an array will
955e49fc963SAndy Fiddamanbe created if necessary.
956e49fc963SAndy Fiddaman.Pp
957e49fc963SAndy FiddamanAn associative array is created with the
958e49fc963SAndy Fiddaman.Fl A
959e49fc963SAndy Fiddamanoption to
960e49fc963SAndy Fiddaman.Ic typeset .
961e49fc963SAndy FiddamanA subscript for an associative array is denoted by a string enclosed between
962e49fc963SAndy Fiddaman.Sy \&[
963e49fc963SAndy Fiddamanand
964e49fc963SAndy Fiddaman.Sy \&] .
965e49fc963SAndy Fiddaman.Pp
966c10c16deSRichard LoweReferencing any array without a subscript is equivalent to referencing the
967e49fc963SAndy Fiddamanarray with subscript
968e49fc963SAndy Fiddaman.Sy 0 .
969e49fc963SAndy Fiddaman.Pp
970c10c16deSRichard LoweThe value of a variable can be assigned by:
971e49fc963SAndy Fiddaman.Bd -ragged -offset Ds
972e49fc963SAndy Fiddaman.Ar vname Ns Sy = Ns Ar value
973e49fc963SAndy Fiddaman.Op Ar vname Ns Sy = Ns Ar value
974e49fc963SAndy Fiddaman.No \&...
975e49fc963SAndy Fiddaman.Ed
976e49fc963SAndy Fiddaman.Pp
977c10c16deSRichard Loweor
978e49fc963SAndy Fiddaman.Bd -ragged -offset Ds
979e49fc963SAndy Fiddaman.Ar vname Ns [ Ns Ar subscript Ns ]= Ns Ar value
980e49fc963SAndy Fiddaman.Op Ar vname Ns [ Ns Ar subscript Ns ]= Ns Ar value
981e49fc963SAndy Fiddaman.No ...
982e49fc963SAndy Fiddaman.Ed
983e49fc963SAndy Fiddaman.Pp
984e49fc963SAndy FiddamanNote that no space is allowed before or after the
985e49fc963SAndy Fiddaman.Sy = .
986e49fc963SAndy Fiddaman.Pp
987e49fc963SAndy FiddamanAttributes assigned by the
988e49fc963SAndy Fiddaman.Ic typeset
989e49fc963SAndy Fiddamanspecial built-in command apply to all elements of the array.
990b30d1939SAndy FiddamanAn array element can be a simple variable, a compound variable or an array
991b30d1939SAndy Fiddamanvariable.
992b30d1939SAndy FiddamanAn element of an indexed array can be either an indexed array or an associative
993b30d1939SAndy Fiddamanarray.
994b30d1939SAndy FiddamanAn element of an associative array can also be either.
995e49fc963SAndy FiddamanTo refer to an array element that is part of an array element, concatenate the
996e49fc963SAndy Fiddamansubscript in brackets.
997e49fc963SAndy FiddamanFor example, to refer to the
998e49fc963SAndy Fiddaman.Ar foobar
999e49fc963SAndy Fiddamanelement of an associative array that is defined as the third element of the
1000e49fc963SAndy Fiddamanindexed array, use
1001e49fc963SAndy Fiddaman.Sm off
1002e49fc963SAndy Fiddaman.Sy ${ Ar vname Sy \&[ Ar 3 Sy ][ Ar foobar Sy ]} .
1003e49fc963SAndy Fiddaman.Sm on
1004e49fc963SAndy Fiddaman.Pp
1005e49fc963SAndy FiddamanA
1006e49fc963SAndy Fiddaman.Ar nameref
1007e49fc963SAndy Fiddamanis a variable that is a reference to another variable.
1008e49fc963SAndy FiddamanA
1009e49fc963SAndy Fiddaman.Ar nameref
1010e49fc963SAndy Fiddamanis created with the
1011e49fc963SAndy Fiddaman.Fl n
1012e49fc963SAndy Fiddamanattribute of
1013e49fc963SAndy Fiddaman.Ic typeset .
1014e49fc963SAndy FiddamanThe value of the variable at the time of the
1015e49fc963SAndy Fiddaman.Ic typeset
1016e49fc963SAndy Fiddamancommand becomes the variable that is referenced whenever the
1017e49fc963SAndy Fiddaman.Ar nameref
1018e49fc963SAndy Fiddamanvariable is used.
1019e49fc963SAndy FiddamanThe name of a
1020e49fc963SAndy Fiddaman.Ar nameref
1021e49fc963SAndy Fiddamancannot contain a dot
1022e49fc963SAndy Fiddaman.Pq \&. .
1023e49fc963SAndy FiddamanWhen a variable or
1024e49fc963SAndy Fiddamanfunction name contains a dot
1025e49fc963SAndy Fiddaman.Pq \&.
1026e49fc963SAndy Fiddamanand the portion of the name up to the first \&. matches the name of a
1027e49fc963SAndy Fiddaman.Ar nameref ,
1028e49fc963SAndy Fiddamanthe variable referred to is obtained by replacing the
1029e49fc963SAndy Fiddaman.Ar nameref
1030e49fc963SAndy Fiddamanportion with the name of the variable referenced by the
1031e49fc963SAndy Fiddaman.Ar nameref .
1032e49fc963SAndy FiddamanIf a
1033e49fc963SAndy Fiddaman.Ar nameref
1034e49fc963SAndy Fiddamanis used as the index of a
1035e49fc963SAndy Fiddaman.Cm for
1036e49fc963SAndy Fiddamanloop, a name reference is established for each item in the list.
1037e49fc963SAndy FiddamanA
1038e49fc963SAndy Fiddaman.Ar nameref
1039e49fc963SAndy Fiddamanprovides a convenient way to refer to the variable inside a function whose name
1040e49fc963SAndy Fiddamanis passed as an argument to a function.
1041e49fc963SAndy FiddamanFor example, if the name of a variable is passed as the first argument to a
1042e49fc963SAndy Fiddamanfunction, the command
1043e49fc963SAndy Fiddaman.Bd -literal -offset Ds
1044e49fc963SAndy Fiddamantypeset -n var=$1
1045e49fc963SAndy Fiddaman.Ed
1046e49fc963SAndy Fiddaman.Pp
1047e49fc963SAndy Fiddamaninside the function causes references and assignments to
1048e49fc963SAndy Fiddaman.Ar var
1049e49fc963SAndy Fiddamanto be references and assignments to the variable whose name has been passed to
1050e49fc963SAndy Fiddamanthe function.
1051e49fc963SAndy FiddamanIf any of the floating point attributes,
1052e49fc963SAndy Fiddaman.Fl E ,
1053e49fc963SAndy Fiddaman.Fl F
1054e49fc963SAndy Fiddamanor
1055e49fc963SAndy Fiddaman.Fl X ,
1056e49fc963SAndy Fiddamanor the integer attribute,
1057e49fc963SAndy Fiddaman.Fl i ,
1058e49fc963SAndy Fiddamanis set for
1059e49fc963SAndy Fiddaman.Ar vname ,
1060e49fc963SAndy Fiddamanthen the
1061e49fc963SAndy Fiddaman.Ar value
1062e49fc963SAndy Fiddamanis subject to arithmetic evaluation as described in this manual page.
1063e49fc963SAndy FiddamanPositional parameters, parameters denoted by a number, can be assigned values
1064e49fc963SAndy Fiddamanwith the
1065e49fc963SAndy Fiddaman.Cm set
1066e49fc963SAndy Fiddamanspecial built-in command.
1067e49fc963SAndy FiddamanParameter
1068e49fc963SAndy Fiddaman.Sy $0
1069e49fc963SAndy Fiddamanis set from argument zero when the shell is invoked.
1070e49fc963SAndy Fiddaman.Pp
1071e49fc963SAndy FiddamanThe character
1072e49fc963SAndy Fiddaman.Sy $
1073e49fc963SAndy Fiddamanis used to introduce substitutable parameters.
1074e49fc963SAndy Fiddaman.Pp
1075e49fc963SAndy Fiddaman.Bl -tag -width Ds -compact
1076e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Ns Sy }
1077e49fc963SAndy FiddamanThe shell reads all the characters from
1078e49fc963SAndy Fiddaman.Sy ${
1079e49fc963SAndy Fiddamanto the matching
1080e49fc963SAndy Fiddaman.Sy }
1081e49fc963SAndy Fiddamanas part of the same word even if it contains braces or metacharacters.
1082e49fc963SAndy FiddamanThe value, if any, of the parameter is substituted.
1083e49fc963SAndy FiddamanThe braces are required when
1084e49fc963SAndy Fiddaman.Ar parameter
1085e49fc963SAndy Fiddamanis followed by a letter, digit, or underscore that is not to be interpreted as
1086e49fc963SAndy Fiddamanpart of its name or when the variable name contains a dot
1087e49fc963SAndy Fiddaman.Pq Sy \&. .
1088e49fc963SAndy FiddamanThe braces are also required when a variable is subscripted unless it is part
1089e49fc963SAndy Fiddamanof an Arithmetic Expression or a Conditional Expression.
1090e49fc963SAndy FiddamanIf
1091e49fc963SAndy Fiddaman.Ar parameter
1092e49fc963SAndy Fiddamanis one or more digits then it is a positional parameter.
1093e49fc963SAndy FiddamanA positional parameter of more than one digit must be enclosed in braces.
1094e49fc963SAndy FiddamanIf
1095e49fc963SAndy Fiddaman.Ar parameter
1096e49fc963SAndy Fiddamanis
1097e49fc963SAndy Fiddaman.Sy \&*
1098e49fc963SAndy Fiddamanor
1099e49fc963SAndy Fiddaman.Sy \&@ ,
1100e49fc963SAndy Fiddamanthen all the positional parameters, starting with
1101e49fc963SAndy Fiddaman.Sy $1 ,
1102e49fc963SAndy Fiddamanare substituted and separated by a field separator character.
1103e49fc963SAndy FiddamanIf an array
1104e49fc963SAndy Fiddaman.Ar vname
1105e49fc963SAndy Fiddamanwith last subscript
1106e49fc963SAndy Fiddaman.Sy \&*
1107e49fc963SAndy Fiddamanor
1108e49fc963SAndy Fiddaman.Sy \&@
1109e49fc963SAndy Fiddamanis used, or for index arrays of the form
1110e49fc963SAndy Fiddaman.Ar sub1 Ns Sy \&.. Ns Ar sub2
1111e49fc963SAndy Fiddamanis used, then the value for each of the elements between
1112e49fc963SAndy Fiddaman.Ar sub1
1113e49fc963SAndy Fiddamanand
1114e49fc963SAndy Fiddaman.Ar sub2
1115e49fc963SAndy Fiddamaninclusive
1116e49fc963SAndy Fiddaman.Pq or all elements for Sy \&* and Sy \&@
1117e49fc963SAndy Fiddamanis substituted, separated by the first character of the value of
1118e49fc963SAndy Fiddaman.Ev IFS .
1119e49fc963SAndy Fiddaman.Pp
1120e49fc963SAndy Fiddaman.It Sy ${# Ns Ar parameter Ns Sy }
1121e49fc963SAndy FiddamanIf
1122e49fc963SAndy Fiddaman.Ar parameter
1123e49fc963SAndy Fiddamanis
1124e49fc963SAndy Fiddaman.Sy \&*
1125e49fc963SAndy Fiddamanor
1126e49fc963SAndy Fiddaman.Sy \&@ ,
1127e49fc963SAndy Fiddamanthe number of positional parameters is substituted.
1128e49fc963SAndy FiddamanOtherwise, the length of the value of the
1129e49fc963SAndy Fiddaman.Ar parameter
1130e49fc963SAndy Fiddamanis substituted.
1131e49fc963SAndy Fiddaman.Pp
1132e49fc963SAndy Fiddaman.It Sy ${# Ns Ar vname Ns Sy [*]}
1133e49fc963SAndy Fiddaman.It Sy ${# Ns Ar vname Ns Sy [@]}
1134e49fc963SAndy FiddamanThe number of elements in the array
1135e49fc963SAndy Fiddaman.Ar vname
1136e49fc963SAndy Fiddamanis substituted.
1137e49fc963SAndy Fiddaman.Pp
1138e49fc963SAndy Fiddaman.It Sy ${@ Ns Ar vname Ns Sy }
1139b30d1939SAndy FiddamanExpands to the type name or attributes of the variable referred to by
1140e49fc963SAndy Fiddaman.Ar vname .
1141e49fc963SAndy FiddamanSee
1142e49fc963SAndy Fiddaman.Sx Type Variables .
1143e49fc963SAndy Fiddaman.Pp
1144e49fc963SAndy Fiddaman.It Sy \&$\&{\&! Ns Ar vname Ns Sy }
1145e49fc963SAndy FiddamanExpands to the name of the variable referred to by
1146e49fc963SAndy Fiddaman.Ar vname .
1147e49fc963SAndy FiddamanThis is
1148e49fc963SAndy Fiddaman.Ar vname
1149e49fc963SAndy Fiddamanexcept when
1150e49fc963SAndy Fiddaman.Ar vname
1151e49fc963SAndy Fiddamanis a name reference.
1152e49fc963SAndy Fiddaman.Pp
1153e49fc963SAndy Fiddaman.It Sy \&$\&{\&! Ns Ar vname Ns Oo Ar subscript Oc Ns Sy }
1154e49fc963SAndy FiddamanExpands to name of the subscript unless
1155e49fc963SAndy Fiddaman.Ar subscript
1156e49fc963SAndy Fiddamanis
1157e49fc963SAndy Fiddaman.Sy \&*
1158e49fc963SAndy Fiddamanor
1159e49fc963SAndy Fiddaman.Sy \&@ ,
1160e49fc963SAndy Fiddamanor of the form
1161e49fc963SAndy Fiddaman.Ar sub1 Ns Sy \&.. Ns Ar sub2 .
1162e49fc963SAndy FiddamanWhen
1163e49fc963SAndy Fiddaman.Ar subscript
1164e49fc963SAndy Fiddamanis
1165e49fc963SAndy Fiddaman.Sy \&* ,
1166e49fc963SAndy Fiddamanthe list of array subscripts for
1167e49fc963SAndy Fiddaman.Ar vname
1168e49fc963SAndy Fiddamanis generated.
1169e49fc963SAndy FiddamanFor a variable that is not an array, the value is
1170e49fc963SAndy Fiddaman.Sy 0
1171e49fc963SAndy Fiddamanif the variable is set, otherwise it is
1172e49fc963SAndy Fiddaman.Sy null .
1173e49fc963SAndy FiddamanWhen
1174e49fc963SAndy Fiddaman.Ar subscript
1175e49fc963SAndy Fiddamanis
1176e49fc963SAndy Fiddaman.Sy \&@ ,
1177e49fc963SAndy Fiddamanit is the same as
1178e49fc963SAndy Fiddaman.Sy ${ Ar vname Ns Oo * Oc Ns Sy } ,
1179e49fc963SAndy Fiddamanexcept that when used in double quotes, each array subscript yields a separate
1180e49fc963SAndy Fiddamanargument.
1181e49fc963SAndy FiddamanWhen subscript is of the form
1182e49fc963SAndy Fiddaman.Ar sub1 Ns Sy \&.. Ns Ar sub2
1183e49fc963SAndy Fiddamanit expands to the list of subscripts between
1184e49fc963SAndy Fiddaman.Ar sub1
1185e49fc963SAndy Fiddamanand
1186e49fc963SAndy Fiddaman.Ar sub2
1187e49fc963SAndy Fiddamaninclusive using the same quoting rules as
1188e49fc963SAndy Fiddaman.Sy @ .
1189e49fc963SAndy Fiddaman.Pp
1190e49fc963SAndy Fiddaman.It Sy \&$\&{\&! Ns Ar prefix Ns Sy *}
1191e49fc963SAndy FiddamanExpands to the names of the variables whose names begin with
1192e49fc963SAndy Fiddaman.Ar prefix .
1193e49fc963SAndy Fiddaman.Pp
1194e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Ns Sy \&:- Ns Ar word Ns Sy }
1195e49fc963SAndy FiddamanIf
1196e49fc963SAndy Fiddaman.Ar parameter
1197e49fc963SAndy Fiddamanis set and is non-null then substitute its value.
1198e49fc963SAndy FiddamanOtherwise substitute
1199e49fc963SAndy Fiddaman.Ar word .
1200e49fc963SAndy Fiddaman.Pp
1201e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Ns Sy \&:= Ns Ar word Ns Sy }
1202e49fc963SAndy FiddamanIf
1203e49fc963SAndy Fiddaman.Ar parameter
1204e49fc963SAndy Fiddamanis not set or is
1205e49fc963SAndy Fiddaman.Sy null ,
1206e49fc963SAndy Fiddamanset it to
1207e49fc963SAndy Fiddaman.Ar word .
1208e49fc963SAndy FiddamanThe value of the parameter is then substituted.
1209e49fc963SAndy FiddamanPositional parameters cannot be assigned to in this way.
1210e49fc963SAndy Fiddaman.Pp
1211e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Ns Sy \&:\&? Ns Ar word Ns Sy }
1212e49fc963SAndy FiddamanIf
1213e49fc963SAndy Fiddaman.Ar parameter
1214e49fc963SAndy Fiddamanis set and is non-null, substitute its value.
1215e49fc963SAndy FiddamanOtherwise, print
1216e49fc963SAndy Fiddaman.Ar word
1217e49fc963SAndy Fiddamanand exit from the shell, if the shell is not interactive.
1218e49fc963SAndy FiddamanIf
1219e49fc963SAndy Fiddaman.Ar word
1220e49fc963SAndy Fiddamanis omitted then a standard message is printed.
1221e49fc963SAndy Fiddaman.Pp
1222e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Ns Sy \&:+ Ns Ar word Ns Sy }
1223e49fc963SAndy FiddamanIf
1224e49fc963SAndy Fiddaman.Ar parameter
1225e49fc963SAndy Fiddamanis set and is non-null, substitute
1226e49fc963SAndy Fiddaman.Ar word .
1227e49fc963SAndy FiddamanOtherwise substitute nothing.
1228e49fc963SAndy Fiddaman.El
1229e49fc963SAndy Fiddaman.Pp
1230e49fc963SAndy FiddamanIn the above,
1231e49fc963SAndy Fiddaman.Ar word
1232e49fc963SAndy Fiddamanis not evaluated unless it is to be used as the substituted string.
1233e49fc963SAndy FiddamanIn the following example,
1234e49fc963SAndy Fiddaman.Ic pwd
1235e49fc963SAndy Fiddamanis executed only if
1236e49fc963SAndy Fiddaman.Sy d
1237e49fc963SAndy Fiddamanis not set or is
1238e49fc963SAndy Fiddaman.Dv NULL :
1239e49fc963SAndy Fiddaman.Bd -literal -offset Ds
1240c10c16deSRichard Loweprint ${d:-$(pwd)}
1241e49fc963SAndy Fiddaman.Ed
1242e49fc963SAndy Fiddaman.Pp
1243e49fc963SAndy FiddamanIf the colon
1244e49fc963SAndy Fiddaman.Pq Sy \&:
1245e49fc963SAndy Fiddamanis omitted from the expression, the shell only checks whether
1246e49fc963SAndy Fiddaman.Ar parameter
1247e49fc963SAndy Fiddamanis set or not.
1248e49fc963SAndy Fiddaman.Pp
1249e49fc963SAndy Fiddaman.Bl -tag -width Ds -compact
1250e49fc963SAndy Fiddaman.Sm off
1251e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy \&: Ar offset Sy \&: Ar length Sy }
1252e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy \&: Ar offset Sy }
1253e49fc963SAndy Fiddaman.Sm on
1254e49fc963SAndy FiddamanExpands to the portion of the value of
1255e49fc963SAndy Fiddaman.Ar parameter
1256e49fc963SAndy Fiddamanstarting at the
1257e49fc963SAndy Fiddamancharacter
1258e49fc963SAndy Fiddaman.Pq counting from 0
1259e49fc963SAndy Fiddamandetermined by expanding
1260e49fc963SAndy Fiddaman.Ar offset
1261e49fc963SAndy Fiddamanas an arithmetic expression and consisting of the number of characters
1262e49fc963SAndy Fiddamandetermined by the arithmetic expression defined by
1263e49fc963SAndy Fiddaman.Ar length .
1264e49fc963SAndy Fiddaman.Pp
1265e49fc963SAndy FiddamanIn the second form, the remainder of the value is used.
1266e49fc963SAndy FiddamanA negative offset counts backwards from the end of
1267e49fc963SAndy Fiddaman.Ar parameter .
1268e49fc963SAndy Fiddaman.Pp
1269c10c16deSRichard LoweOne or more BLANKs is required in front of a minus sign to prevent the shell
1270e49fc963SAndy Fiddamanfrom interpreting the operator as
1271e49fc963SAndy Fiddaman.Sy \&:- .
1272e49fc963SAndy FiddamanIf parameter is
1273e49fc963SAndy Fiddaman.Sy \&*
1274e49fc963SAndy Fiddamanor
1275e49fc963SAndy Fiddaman.Sy \&@ ,
1276e49fc963SAndy Fiddamanor is an array name indexed by
1277e49fc963SAndy Fiddaman.Sy \&*
1278e49fc963SAndy Fiddamanor
1279e49fc963SAndy Fiddaman.Sy \&@ ,
1280e49fc963SAndy Fiddamanthen
1281e49fc963SAndy Fiddaman.Ar offset
1282e49fc963SAndy Fiddamanand
1283e49fc963SAndy Fiddaman.Ar length
1284e49fc963SAndy Fiddamanrefer to the array index and number of elements respectively.
1285e49fc963SAndy FiddamanA negative
1286e49fc963SAndy Fiddaman.Ar offset
1287e49fc963SAndy Fiddamanis taken relative to one greater than the highest subscript for indexed arrays.
1288e49fc963SAndy FiddamanThe order for associative arrays is unspecified.
1289e49fc963SAndy Fiddaman.Pp
1290e49fc963SAndy Fiddaman.Sm off
1291e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy # Ar pattern Sy }
1292e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy ## Ar pattern Sy }
1293e49fc963SAndy Fiddaman.Sm on
1294e49fc963SAndy FiddamanIf the shell
1295e49fc963SAndy Fiddaman.Ar pattern
1296e49fc963SAndy Fiddamanmatches the beginning of the value of
1297e49fc963SAndy Fiddaman.Ar parameter ,
1298e49fc963SAndy Fiddamanthen the value of this expansion is the value of the
1299e49fc963SAndy Fiddaman.Ar parameter
1300e49fc963SAndy Fiddamanwith the matched portion deleted.
1301e49fc963SAndy FiddamanOtherwise the value of this
1302e49fc963SAndy Fiddaman.Ar parameter
1303e49fc963SAndy Fiddamanis substituted.
1304e49fc963SAndy FiddamanIn the first form the smallest matching
1305e49fc963SAndy Fiddaman.Ar pattern
1306e49fc963SAndy Fiddamanis deleted and in the second form the largest matching
1307e49fc963SAndy Fiddaman.Ar pattern
1308e49fc963SAndy Fiddamanis deleted.
1309e49fc963SAndy FiddamanWhen
1310e49fc963SAndy Fiddaman.Ar parameter
1311e49fc963SAndy Fiddamanis
1312e49fc963SAndy Fiddaman.Sy \&@ ,
1313e49fc963SAndy Fiddaman.Sy \&* ,
1314e49fc963SAndy Fiddamanor an array variable with subscript
1315e49fc963SAndy Fiddaman.Sy \&@
1316e49fc963SAndy Fiddamanor
1317e49fc963SAndy Fiddaman.Sy \&* ,
1318e49fc963SAndy Fiddamanthe substring operation is applied to each element in turn.
1319e49fc963SAndy Fiddaman.Pp
1320e49fc963SAndy Fiddaman.Sm off
1321e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy % Ar pattern Sy }
1322e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy %% Ar pattern Sy }
1323e49fc963SAndy Fiddaman.Sm on
1324e49fc963SAndy FiddamanIf the shell
1325e49fc963SAndy Fiddaman.Ar pattern
1326e49fc963SAndy Fiddamanmatches the end of the value of
1327e49fc963SAndy Fiddaman.Ar parameter ,
1328c10c16deSRichard Lowethen the value of this expansion is the value of the parameter with the matched
1329e49fc963SAndy Fiddamanpart deleted.
1330e49fc963SAndy FiddamanOtherwise substitute the value of
1331e49fc963SAndy Fiddaman.Ar parameter .
1332e49fc963SAndy FiddamanIn the first form the smallest matching pattern is deleted, and in the second
1333e49fc963SAndy Fiddamanform the largest matching pattern is deleted.
1334e49fc963SAndy FiddamanWhen parameter is
1335e49fc963SAndy Fiddaman.Sy \&@ ,
1336e49fc963SAndy Fiddaman.Sy \&* ,
1337e49fc963SAndy Fiddamanor an array variable with subscript
1338e49fc963SAndy Fiddaman.Sy \&@
1339e49fc963SAndy Fiddamanor
1340e49fc963SAndy Fiddaman.Sy \&* ,
1341e49fc963SAndy Fiddamanthe substring operation is applied to each element in turn.
1342e49fc963SAndy Fiddaman.Pp
1343e49fc963SAndy Fiddaman.Sm off
1344e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy / Ar pattern Sy / Ar string Sy }
1345e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy // Ar pattern Sy / Ar string Sy }
1346e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy /# Ar pattern Sy / Ar string Sy }
1347e49fc963SAndy Fiddaman.It Sy ${ Ns Ar parameter Sy /% Ar pattern Sy / Ar string Sy }
1348e49fc963SAndy Fiddaman.Sm on
1349e49fc963SAndy FiddamanExpands
1350e49fc963SAndy Fiddaman.Ar parameter
1351e49fc963SAndy Fiddamanand replaces the longest match of
1352e49fc963SAndy Fiddaman.Ar pattern
1353e49fc963SAndy Fiddamanwith the specified
1354e49fc963SAndy Fiddaman.Ar string .
1355e49fc963SAndy FiddamanEach occurrence of
1356e49fc963SAndy Fiddaman.Sy \e Ns Ar n
1357e49fc963SAndy Fiddamanin
1358e49fc963SAndy Fiddaman.Ar string
1359e49fc963SAndy Fiddamanis replaced by the portion of
1360e49fc963SAndy Fiddaman.Ar parameter
1361e49fc963SAndy Fiddamanthat matches the
1362e49fc963SAndy Fiddaman.Ar n Ns No th
1363c10c16deSRichard Lowesub-pattern.
1364e49fc963SAndy Fiddaman.Pp
1365e49fc963SAndy FiddamanWhen
1366e49fc963SAndy Fiddaman.Ar string
1367e49fc963SAndy Fiddamanis null, the
1368e49fc963SAndy Fiddaman.Ar pattern
1369e49fc963SAndy Fiddamanis deleted and the
1370e49fc963SAndy Fiddaman.Sy /
1371e49fc963SAndy Fiddamanin front of string can be omitted.
1372e49fc963SAndy FiddamanWhen
1373e49fc963SAndy Fiddaman.Ar parameter
1374e49fc963SAndy Fiddamanis
1375e49fc963SAndy Fiddaman.Sy \&@ ,
1376e49fc963SAndy Fiddaman.Sy \&* ,
1377e49fc963SAndy Fiddamanor an
1378e49fc963SAndy Fiddamanarray variable with subscript
1379e49fc963SAndy Fiddaman.Sy \&@
1380e49fc963SAndy Fiddamanor
1381e49fc963SAndy Fiddaman.Sy \&* ,
1382e49fc963SAndy Fiddamanthe substitution operation is applied to each element in turn.
1383e49fc963SAndy FiddamanIn this case, the
1384e49fc963SAndy Fiddaman.Ar string
1385e49fc963SAndy Fiddamanportion of
1386e49fc963SAndy Fiddaman.Ar word
1387e49fc963SAndy Fiddamanis re-evaluated for each element.
1388e49fc963SAndy Fiddaman.Pp
1389e49fc963SAndy FiddamanIn the first form, only the first occurrence of
1390e49fc963SAndy Fiddaman.Ar pattern
1391e49fc963SAndy Fiddamanis replaced.
1392e49fc963SAndy Fiddaman.Pp
1393e49fc963SAndy FiddamanIn the second form, each match for
1394e49fc963SAndy Fiddaman.Ar pattern
1395e49fc963SAndy Fiddamanis replaced by the specified
1396e49fc963SAndy Fiddaman.Ar string .
1397e49fc963SAndy Fiddaman.Pp
1398c10c16deSRichard LoweThe third form restricts the pattern match to the beginning of the
1399e49fc963SAndy Fiddaman.Ar string .
1400e49fc963SAndy Fiddaman.Pp
1401e49fc963SAndy FiddamanThe fourth form restricts the pattern match to the end of the
1402e49fc963SAndy Fiddaman.Ar string .
1403e49fc963SAndy Fiddaman.El
1404e49fc963SAndy Fiddaman.Pp
1405c10c16deSRichard LoweThe following parameters are automatically set by the shell:
1406e49fc963SAndy Fiddaman.Bl -tag -width Ds
1407e49fc963SAndy Fiddaman.It Sy #
1408c10c16deSRichard LoweThe number of positional parameters in decimal.
1409e49fc963SAndy Fiddaman.It Sy -
1410e49fc963SAndy FiddamanOptions supplied to the shell on invocation or by the
1411e49fc963SAndy Fiddaman.Ic set
1412e49fc963SAndy Fiddamancommand.
1413e49fc963SAndy Fiddaman.It Sy \&?
1414c10c16deSRichard LoweThe decimal value returned by the last executed command.
1415e49fc963SAndy Fiddaman.It Sy $
1416c10c16deSRichard LoweThe process number of this shell.
1417e49fc963SAndy Fiddaman.It Sy _
1418e49fc963SAndy FiddamanInitially, the value of
1419e49fc963SAndy Fiddaman.Sy _
1420e49fc963SAndy Fiddamanis the absolute pathname of the shell or script being executed as passed in the
1421e49fc963SAndy Fiddamanenvironment.
1422e49fc963SAndy FiddamanIt is subsequently assigned the last argument of the previous command.
1423e49fc963SAndy Fiddaman.Pp
1424e49fc963SAndy FiddamanThis parameter is not set for commands which are asynchronous.
1425e49fc963SAndy FiddamanThis parameter is also used to hold the name of the matching
1426e49fc963SAndy Fiddaman.Ev MAIL
1427e49fc963SAndy Fiddamanfile when checking for mail.
1428e49fc963SAndy Fiddaman.It Sy \&!
1429b30d1939SAndy FiddamanThe process id or the pool name and job number of the last background command
1430b30d1939SAndy Fiddamaninvoked or the most recent job put in the background with the
1431e49fc963SAndy Fiddaman.Ic bg
1432e49fc963SAndy Fiddamanbuilt-in command.
1433e49fc963SAndy FiddamanBackground jobs started in a named pool with be in the form
1434e49fc963SAndy Fiddaman.Ar pool Ns \&. Ns Ar number
1435e49fc963SAndy Fiddamanwhere
1436e49fc963SAndy Fiddaman.Ar pool
1437e49fc963SAndy Fiddamanis the pool name and
1438e49fc963SAndy Fiddaman.Ar number
1439e49fc963SAndy Fiddamanis the job number within that pool.
1440e49fc963SAndy Fiddaman.It Sy \&.sh.command
1441e49fc963SAndy FiddamanWhen processing a
1442e49fc963SAndy Fiddaman.Dv DEBUG
1443e49fc963SAndy Fiddamantrap, this variable contains the current command line that is about to run.
1444e49fc963SAndy Fiddaman.It Sy \&.sh.edchar
1445c10c16deSRichard LoweThis variable contains the value of the keyboard character (or sequence of
1446e49fc963SAndy Fiddamancharacters if the first character is an ESC,
1447e49fc963SAndy Fiddaman.Pq  ASCII 033
1448e49fc963SAndy Fiddamanthat has been entered when processing a
1449e49fc963SAndy Fiddaman.Dv KEYBD
1450c10c16deSRichard Lowetrap.
1451e49fc963SAndy FiddamanIf the value is changed as part of the trap action, then the new value replaces
1452e49fc963SAndy Fiddamanthe key (or key sequence) that caused the trap.
1453e49fc963SAndy FiddamanSee the
1454e49fc963SAndy Fiddaman.Sx Key Bindings
1455e49fc963SAndy Fiddamansection of this manual page.
1456e49fc963SAndy Fiddaman.It Sy \&.sh.edcol
1457e49fc963SAndy FiddamanThe character position of the cursor at the time of the most recent
1458e49fc963SAndy Fiddaman.Dv KEYBD
1459e49fc963SAndy Fiddamantrap.
1460e49fc963SAndy Fiddaman.It Sy \&.sh.edmode
1461e49fc963SAndy FiddamanThe value is set to ESC when processing a
1462e49fc963SAndy Fiddaman.Dv KEYBD
1463e49fc963SAndy Fiddamantrap while in
1464e49fc963SAndy Fiddaman.Sy vi
1465e49fc963SAndy Fiddamaninsert mode.
1466e49fc963SAndy FiddamanOtherwise,
1467e49fc963SAndy Fiddaman.Sy \&.sh.edmode
1468e49fc963SAndy Fiddamanis null when processing a
1469e49fc963SAndy Fiddaman.Dv KEYBD
1470e49fc963SAndy Fiddamantrap.
1471e49fc963SAndy FiddamanSee the
1472e49fc963SAndy Fiddaman.Sx vi Editing Mode
1473e49fc963SAndy Fiddamansection of this manual page.
1474e49fc963SAndy Fiddaman.It Sy \&.sh.edtext
1475e49fc963SAndy FiddamanThe characters in the input buffer at the time of the most recent
1476e49fc963SAndy Fiddaman.Dv KEYBD
1477e49fc963SAndy Fiddamantrap.
1478e49fc963SAndy FiddamanThe value is null when not processing a
1479e49fc963SAndy Fiddaman.Dv KEYBD
1480e49fc963SAndy Fiddamantrap.
1481e49fc963SAndy Fiddaman.It Sy \&.sh.file
1482c10c16deSRichard LoweThe pathname of the file than contains the current command.
1483e49fc963SAndy Fiddaman.It Sy \&.sh.fun
1484c10c16deSRichard LoweThe name of the current function that is being executed.
1485e49fc963SAndy Fiddaman.It Sy \&.sh.match
1486c10c16deSRichard LoweAn indexed array which stores the most recent match and sub-pattern matches
1487c10c16deSRichard Loweafter conditional pattern matches that match and after variables expansions
1488e49fc963SAndy Fiddamanusing the operators
1489e49fc963SAndy Fiddaman.Sy \&# ,
1490e49fc963SAndy Fiddaman.Sy \&% , or
1491e49fc963SAndy Fiddaman.Sy \&/ .
1492e49fc963SAndy FiddamanThe
1493e49fc963SAndy Fiddaman.Sy 0 Ns No th
1494e49fc963SAndy Fiddamanelement stores the complete match and the
1495e49fc963SAndy Fiddaman.Ar i Ns No th
1496e49fc963SAndy Fiddamanelement stores the
1497e49fc963SAndy Fiddaman.Ar i Ns No th
1498e49fc963SAndy Fiddamansub-match.
1499e49fc963SAndy FiddamanThe
1500e49fc963SAndy Fiddaman.Sy \&.sh.match
1501e49fc963SAndy Fiddamanvariable is unset when the variable that has expanded is assigned a new value.
1502e49fc963SAndy Fiddaman.It Sy \&.sh.math
1503e49fc963SAndy FiddamanUsed for defining arithmetic functions
1504e49fc963SAndy Fiddaman.Pq see Sx Arithmetic evaluation
1505e49fc963SAndy Fiddamanand stores the list of user-defined arithmetic functions.
1506e49fc963SAndy Fiddaman.It Sy \&.sh.name
1507c10c16deSRichard LoweSet to the name of the variable at the time that a discipline function is
1508c10c16deSRichard Loweinvoked.
1509e49fc963SAndy Fiddaman.It Sy \&.sh.subscript
1510c10c16deSRichard LoweSet to the name subscript of the variable at the time that a discipline
1511c10c16deSRichard Lowefunction is invoked.
1512e49fc963SAndy Fiddaman.It Sy \&.sh.subshell
1513c10c16deSRichard LoweThe current depth for sub-shells and command substitution.
1514e49fc963SAndy Fiddaman.It Sy \&.sh.value
1515c10c16deSRichard LoweSet to the value of the variable at the time that the set or append discipline
1516e49fc963SAndy Fiddamanfunction is invoked.
1517e49fc963SAndy FiddamanWhen a user-defined arithmetic function is invoked, the value of
1518e49fc963SAndy Fiddaman.Sy .sh.value
1519e49fc963SAndy Fiddamanis saved and
1520e49fc963SAndy Fiddaman.Sy .sh.value
1521e49fc963SAndy Fiddamanis set to long double precision floating point.
1522e49fc963SAndy Fiddaman.Sy .sh.value
1523e49fc963SAndy Fiddamanis restored when the function returns.
1524e49fc963SAndy Fiddaman.It Sy \&.sh.version
1525c10c16deSRichard LoweSet to a value that identifies the version of this shell.
1526e49fc963SAndy Fiddaman.It Sy LINENO
1527c10c16deSRichard LoweThe current line number within the script or function being executed.
1528e49fc963SAndy Fiddaman.It Sy OLDPWD
1529e49fc963SAndy FiddamanThe previous working directory set by the
1530e49fc963SAndy Fiddaman.Ic cd
1531c10c16deSRichard Lowecommand.
1532e49fc963SAndy Fiddaman.It Sy OPTARG
1533e49fc963SAndy FiddamanThe value of the last option argument processed by the
1534e49fc963SAndy Fiddaman.Ic getopts
1535e49fc963SAndy Fiddamanbuilt-in command.
1536e49fc963SAndy Fiddaman.It Sy OPTIND
1537e49fc963SAndy FiddamanThe index of the last option argument processed by the
1538e49fc963SAndy Fiddaman.Ic getopts
1539e49fc963SAndy Fiddamanbuilt-in command.
1540e49fc963SAndy Fiddaman.It Sy PPID
1541c10c16deSRichard LoweThe process number of the parent of the shell.
1542e49fc963SAndy Fiddaman.It Sy PWD
1543e49fc963SAndy FiddamanThe present working directory set by the
1544e49fc963SAndy Fiddaman.Ic cd
1545e49fc963SAndy Fiddamancommand.
1546e49fc963SAndy Fiddaman.It Sy RANDOM
1547c10c16deSRichard LoweEach time this variable is referenced, a random integer, uniformly distributed
1548e49fc963SAndy Fiddamanbetween
1549e49fc963SAndy Fiddaman.Sy 0
1550e49fc963SAndy Fiddamanand
1551e49fc963SAndy Fiddaman.Sy 32767 ,
1552e49fc963SAndy Fiddamanis generated.
1553e49fc963SAndy FiddamanThe sequence of random numbers can be initialized by assigning a numeric value
1554e49fc963SAndy Fiddamanto
1555e49fc963SAndy Fiddaman.Ev RANDOM .
1556e49fc963SAndy Fiddaman.It Sy REPLY
1557e49fc963SAndy FiddamanThis variable is set by the
1558e49fc963SAndy Fiddaman.Ic select
1559e49fc963SAndy Fiddamanstatement and by the
1560e49fc963SAndy Fiddaman.Ic read
1561c10c16deSRichard Lowebuilt-in command when no arguments are supplied.
1562e49fc963SAndy Fiddaman.It Sy SECONDS
1563c10c16deSRichard LoweEach time this variable is referenced, the number of seconds since shell
1564e49fc963SAndy Fiddamaninvocation is returned.
1565e49fc963SAndy FiddamanIf this variable is assigned a value, then the value returned upon reference is
1566e49fc963SAndy Fiddamanthe value that was assigned plus the number of seconds since the assignment.
1567e49fc963SAndy Fiddaman.It Sy SHLVL
1568b30d1939SAndy FiddamanAn integer variable the is incremented each time the shell is invoked and is
1569e49fc963SAndy Fiddamanexported.
1570e49fc963SAndy FiddamanIf
1571e49fc963SAndy Fiddaman.Ev SHLVL
1572e49fc963SAndy Fiddamanis not in the environment when the shell is invoked, it is set to 1.
1573e49fc963SAndy Fiddaman.El
1574e49fc963SAndy Fiddaman.Pp
1575c10c16deSRichard LoweThe following variables are used by the shell:
1576e49fc963SAndy Fiddaman.Bl -tag -width Ds
1577e49fc963SAndy Fiddaman.It Sy CDPATH
1578e49fc963SAndy FiddamanDefines the search path for the
1579e49fc963SAndy Fiddaman.Ic cd
1580e49fc963SAndy Fiddamancommand.
1581e49fc963SAndy Fiddaman.It Sy COLUMNS
1582c10c16deSRichard LoweDefines the width of the edit window for the shell edit modes and for printing
1583c10c16deSRichard Loweselect lists.
1584e49fc963SAndy Fiddaman.It Sy EDITOR
1585e49fc963SAndy FiddamanIf the
1586e49fc963SAndy Fiddaman.Ev VISUAL
1587e49fc963SAndy Fiddamanvariable is not set, the value of this variable is checked for the patterns as
1588e49fc963SAndy Fiddamandescribed with
1589e49fc963SAndy Fiddaman.Ev VISUAL
1590e49fc963SAndy Fiddamanand the corresponding editing option is turned on.
1591e49fc963SAndy Fiddaman.Pp
1592e49fc963SAndy FiddamanSee the
1593e49fc963SAndy Fiddaman.Ic set
1594e49fc963SAndy Fiddamancommand in the
1595e49fc963SAndy Fiddaman.Sx Special Commands
1596e49fc963SAndy Fiddamansection of this manual page.
1597e49fc963SAndy Fiddaman.It Sy ENV
1598c10c16deSRichard LowePerforms parameter expansion, command substitution, and arithmetic substitution
1599c10c16deSRichard Loweon the value to generate the pathname of the script that is executed when the
1600e49fc963SAndy Fiddamanshell is invoked.
1601e49fc963SAndy FiddamanThis file is typically used for alias and function definitions.
1602e49fc963SAndy FiddamanThe default value is
1603e49fc963SAndy Fiddaman.Sy $HOME/.kshrc .
1604e49fc963SAndy Fiddaman.Pp
1605e49fc963SAndy FiddamanSee the
1606e49fc963SAndy Fiddaman.Sx Invocation
1607e49fc963SAndy Fiddamansection of this manual page.
1608e49fc963SAndy Fiddaman.Pp
1609e49fc963SAndy Fiddaman.Ev ENV
1610e49fc963SAndy Fiddamanis not set by the shell.
1611e49fc963SAndy Fiddaman.It Sy FCEDIT
1612e49fc963SAndy FiddamanObsolete name for the default editor name for the
1613e49fc963SAndy Fiddaman.Ic hist
1614e49fc963SAndy Fiddamancommand.
1615e49fc963SAndy Fiddaman.Ev FCEDIT
1616e49fc963SAndy Fiddamanis not used when
1617e49fc963SAndy Fiddaman.Ev HISTEDIT
1618e49fc963SAndy Fiddamanis set.
1619e49fc963SAndy Fiddaman.Pp
1620e49fc963SAndy FiddamanThe shell specifies a default value to
1621e49fc963SAndy Fiddaman.Ev FCEDIT .
1622e49fc963SAndy Fiddaman.It Sy FIGNORE
1623c10c16deSRichard LoweA pattern that defines the set of file names that is ignored when performing
1624c10c16deSRichard Lowefile name matching.
1625e49fc963SAndy Fiddaman.It Sy FPATH
1626e49fc963SAndy FiddamanThe search path for function definitions.
1627e49fc963SAndy FiddamanThe directories in this path are searched for a file with the same name as the
1628e49fc963SAndy Fiddamanfunction or command when a function with the
1629e49fc963SAndy Fiddaman.Fl u
1630e49fc963SAndy Fiddamanattribute is referenced and when a command is not found.
1631e49fc963SAndy FiddamanIf an executable file with the name of that command is found, then it is read
1632e49fc963SAndy Fiddamanand executed in the current environment.
1633e49fc963SAndy FiddamanUnlike
1634e49fc963SAndy Fiddaman.Ev PATH ,
1635e49fc963SAndy Fiddamanthe current directory must be represented explicitly by dot
1636e49fc963SAndy Fiddaman.Pq Sy \&.
1637e49fc963SAndy Fiddamanrather than by adjacent colon
1638e49fc963SAndy Fiddaman.Pq Sy \&:
1639e49fc963SAndy Fiddamancharacters or a beginning or ending colon
1640e49fc963SAndy Fiddaman.Pq Sy \&: .
1641e49fc963SAndy Fiddaman.It Sy HISTCMD
1642c10c16deSRichard LoweThe number of the current command in the history file.
1643e49fc963SAndy Fiddaman.It Sy HISTEDIT
1644e49fc963SAndy FiddamanThe name for the default editor name for the
1645e49fc963SAndy Fiddaman.Ic hist
1646e49fc963SAndy Fiddamancommand.
1647e49fc963SAndy Fiddaman.It Sy HISTFILE
1648c10c16deSRichard LoweIf this variable is set when the shell is invoked, the value is the pathname of
1649e49fc963SAndy Fiddamanthe file that is used to store the command history.
1650e49fc963SAndy FiddamanSee the
1651e49fc963SAndy Fiddaman.Sx Command Re-entry
1652e49fc963SAndy Fiddamansection of this manual page.
1653e49fc963SAndy Fiddaman.It Sy HISTSIZE
1654c10c16deSRichard LoweIf this variable is set when the shell is invoked, then the number of
1655c10c16deSRichard Lowepreviously entered commands that are accessible by this shell is greater than
1656e49fc963SAndy Fiddamanor equal to this number.
1657e49fc963SAndy FiddamanThe default is
1658e49fc963SAndy Fiddaman.Sy 512 .
1659e49fc963SAndy Fiddaman.It Sy HOME
1660e49fc963SAndy FiddamanThe default argument (home directory) for the
1661e49fc963SAndy Fiddaman.Ic cd
1662e49fc963SAndy Fiddamancommand.
1663e49fc963SAndy Fiddaman.Pp
1664e49fc963SAndy Fiddaman.Ev HOME
1665e49fc963SAndy Fiddamanis not set by the shell.
1666e49fc963SAndy Fiddaman.Ev HOME
1667e49fc963SAndy Fiddamanis set by
1668e49fc963SAndy Fiddaman.Xr login 1 .
1669e49fc963SAndy Fiddaman.It Sy IFS
1670c10c16deSRichard LoweInternal field separators, normally SPACE, TAB, and NEWLINE that are used to
1671c10c16deSRichard Loweseparate the results of command substitution or parameter expansion and to
1672e49fc963SAndy Fiddamanseparate fields with the built-in command read.
1673e49fc963SAndy FiddamanThe first character of the
1674e49fc963SAndy Fiddaman.Ev IFS
1675e49fc963SAndy Fiddamanvariable is used to separate arguments for the
1676e49fc963SAndy Fiddaman.Dq Sy \&$*
1677e49fc963SAndy Fiddamansubstitution.
1678e49fc963SAndy FiddamanSee the
1679e49fc963SAndy Fiddaman.Sx Quoting
1680e49fc963SAndy Fiddamansection of this manual page.
1681e49fc963SAndy Fiddaman.Pp
1682e49fc963SAndy FiddamanEach single occurrence of an
1683e49fc963SAndy Fiddaman.Ev IFS
1684e49fc963SAndy Fiddamancharacter in the string to be split, that is not in the
1685e49fc963SAndy Fiddaman.Sy issspace
1686e49fc963SAndy Fiddamancharacter class, and any adjacent characters in
1687e49fc963SAndy Fiddaman.Ev IFS
1688e49fc963SAndy Fiddamanthat are in the
1689e49fc963SAndy Fiddaman.Sy issspace
1690e49fc963SAndy Fiddamancharacter class, delimit a field.
1691e49fc963SAndy FiddamanOne or more characters in
1692e49fc963SAndy Fiddaman.Ev IFS
1693e49fc963SAndy Fiddamanthat belong to the
1694e49fc963SAndy Fiddaman.Sy issspace
1695e49fc963SAndy Fiddamancharacter class, delimit a field.
1696e49fc963SAndy FiddamanIn addition, if the same
1697e49fc963SAndy Fiddaman.Sy issspace
1698e49fc963SAndy Fiddamancharacter appears consecutively inside
1699e49fc963SAndy Fiddaman.Ev IFS ,
1700e49fc963SAndy Fiddamanthis character is treated as if it were not in the
1701e49fc963SAndy Fiddaman.Sy issspace
1702e49fc963SAndy Fiddamanclass, so that if
1703e49fc963SAndy Fiddaman.Ev IFS
1704e49fc963SAndy Fiddamanconsists of two tab characters, then two adjacent tab characters delimit a null
1705e49fc963SAndy Fiddamanfield.
1706e49fc963SAndy Fiddaman.Pp
1707e49fc963SAndy FiddamanThe shell specifies a default value to
1708e49fc963SAndy Fiddaman.Ev IFS .
1709e49fc963SAndy Fiddaman.It Sy JOBMAX
1710b30d1939SAndy FiddamanThis variable defines the maximum number running background jobs that can run
1711e49fc963SAndy Fiddamanat a time.
1712e49fc963SAndy FiddamanWhen this limit is reached, the shell will wait for a job to complete before
1713e49fc963SAndy Fiddamanstarting a new job.
1714e49fc963SAndy Fiddaman.It Sy LANG
1715c10c16deSRichard LoweThis variable determines the locale category for any category not specifically
1716e49fc963SAndy Fiddamanselected with a variable starting with
1717e49fc963SAndy Fiddaman.Ev LC_
1718e49fc963SAndy Fiddamanor
1719e49fc963SAndy Fiddaman.Ev LANG .
1720e49fc963SAndy Fiddaman.It Sy LC_ALL
1721e49fc963SAndy FiddamanThis variable overrides the value of the
1722e49fc963SAndy Fiddaman.Ev LANG
1723e49fc963SAndy Fiddamanvariable and any other
1724e49fc963SAndy Fiddaman.Ev LC_
1725e49fc963SAndy Fiddamanvariable.
1726e49fc963SAndy Fiddaman.It Sy LC_COLLATE
1727c10c16deSRichard LoweThis variable determines the locale category for character collation
1728c10c16deSRichard Loweinformation.
1729e49fc963SAndy Fiddaman.It Sy LC_CTYPE
1730c10c16deSRichard LoweThis variable determines the locale category for character handling functions.
1731e49fc963SAndy FiddamanIt determines the character classes for pattern matching.
1732e49fc963SAndy FiddamanSee the
1733e49fc963SAndy Fiddaman.Sx File Name Generation
1734e49fc963SAndy Fiddamansection of this manual page.
1735e49fc963SAndy Fiddaman.It Sy LC_NUMERIC
1736c10c16deSRichard LoweThis variable determines the locale category for the decimal point character.
1737e49fc963SAndy Fiddaman.It Sy LINES
1738c10c16deSRichard LoweIf this variable is set, the value is used to determine the column length for
1739e49fc963SAndy Fiddamanprinting select lists.
1740e49fc963SAndy FiddamanSelect lists prints vertically until about two-thirds of
1741e49fc963SAndy Fiddaman.Ev LINES
1742e49fc963SAndy Fiddamanlines are filled.
1743e49fc963SAndy Fiddaman.It Sy MAIL
1744e49fc963SAndy FiddamanIf this variable is set to the name of a mail file
1745e49fc963SAndy Fiddaman.Em and
1746e49fc963SAndy Fiddamanthe
1747e49fc963SAndy Fiddaman.Ev MAILPATH
1748c10c16deSRichard Lowevariable is not set, then the shell informs the user of arrival of mail in the
1749c10c16deSRichard Lowespecified file.
1750e49fc963SAndy Fiddaman.Pp
1751e49fc963SAndy Fiddaman.Ev MAIL
1752e49fc963SAndy Fiddamanis not set by the shell.
1753e49fc963SAndy FiddamanOn some systems,
1754e49fc963SAndy Fiddaman.Ev MAIL
1755e49fc963SAndy Fiddamanis set by
1756e49fc963SAndy Fiddaman.Xr login 1 .
1757e49fc963SAndy Fiddaman.It Sy MAILCHECK
1758c10c16deSRichard LoweSpecifies how often in seconds the shell checks for changes in the modification
1759e49fc963SAndy Fiddamantime of any of the files specified by the
1760e49fc963SAndy Fiddaman.Ev MAILPATH
1761e49fc963SAndy Fiddamanor
1762e49fc963SAndy Fiddaman.Ev MAIL
1763e49fc963SAndy Fiddamanvariables.
1764e49fc963SAndy FiddamanThe default value is
1765e49fc963SAndy Fiddaman.Sy 600
1766e49fc963SAndy Fiddamanseconds.
1767e49fc963SAndy FiddamanWhen the time has elapsed the shell checks before issuing the next prompt.
1768e49fc963SAndy Fiddaman.Pp
1769e49fc963SAndy FiddamanThe shell specifies a default value to
1770e49fc963SAndy Fiddaman.Ev MAILCHECK .
1771e49fc963SAndy Fiddaman.It Sy MAILPATH
1772e49fc963SAndy FiddamanA colon
1773e49fc963SAndy Fiddaman.Pq Sy \&:
1774e49fc963SAndy Fiddamanseparated list of file names.
1775e49fc963SAndy FiddamanIf this variable is set, then the shell informs the user of any modifications
1776e49fc963SAndy Fiddamanto the specified files that have occurred within the last
1777e49fc963SAndy Fiddaman.Ev MAILCHECK
1778e49fc963SAndy Fiddamanseconds.
1779e49fc963SAndy FiddamanEach file name can be followed by a
1780e49fc963SAndy Fiddaman.Sy \&?
1781e49fc963SAndy Fiddamanand a message that is printed.
1782e49fc963SAndy FiddamanThe message undergoes parameter expansion, command substitution, and arithmetic
1783e49fc963SAndy Fiddamansubstitution with the variable
1784e49fc963SAndy Fiddaman.Sy $_
1785e49fc963SAndy Fiddamandefined as the name of the file that has changed.
1786e49fc963SAndy FiddamanThe default message is
1787e49fc963SAndy Fiddaman.Ql you have mail in $_ .
1788e49fc963SAndy Fiddaman.It Sy PATH
1789e49fc963SAndy FiddamanThe search path for commands.
1790e49fc963SAndy FiddamanExcept in
1791e49fc963SAndy Fiddaman.Pa .profile ,
1792e49fc963SAndy Fiddamanusers cannot change
1793e49fc963SAndy Fiddaman.Ev PATH
1794e49fc963SAndy Fiddamanif executing under
1795e49fc963SAndy Fiddaman.Nm rksh93 .
1796e49fc963SAndy FiddamanSee the
1797e49fc963SAndy Fiddaman.Sx Execution section
1798e49fc963SAndy Fiddamanof this manual page.
1799e49fc963SAndy Fiddaman.Pp
1800e49fc963SAndy FiddamanThe shell specifies a default value to
1801e49fc963SAndy Fiddaman.Ev PATH .
1802e49fc963SAndy Fiddaman.It Sy PS1
1803c10c16deSRichard LoweThe value of this variable is expanded for parameter expansion, command
1804c10c16deSRichard Lowesubstitution, and arithmetic substitution to define the primary prompt string
1805e49fc963SAndy Fiddamanwhich by default is
1806e49fc963SAndy Fiddaman.Sy $ .
1807e49fc963SAndy FiddamanThe character
1808e49fc963SAndy Fiddaman.Sy \&!
1809e49fc963SAndy Fiddamanin the primary prompt string is replaced by the command number.
1810e49fc963SAndy FiddamanTwo successive occurrences of
1811e49fc963SAndy Fiddaman.Sy \&!
1812e49fc963SAndy Fiddamanproduces a single
1813e49fc963SAndy Fiddaman.Sy \&!
1814e49fc963SAndy Fiddamanwhen the prompt string is printed.
1815e49fc963SAndy FiddamanSee the
1816e49fc963SAndy Fiddaman.Sx Command Re-entry
1817e49fc963SAndy Fiddamansection of this manual page.
1818e49fc963SAndy Fiddaman.Pp
1819e49fc963SAndy FiddamanThe shell specifies a default value to
1820e49fc963SAndy Fiddaman.Ev PS1 .
1821e49fc963SAndy Fiddaman.It Sy PS2
1822e49fc963SAndy FiddamanSecondary prompt string, by default,
1823e49fc963SAndy Fiddaman.Sy \&> .
1824e49fc963SAndy Fiddaman.Pp
1825e49fc963SAndy FiddamanThe shell specifies a default value to
1826e49fc963SAndy Fiddaman.Ev PS2 .
1827e49fc963SAndy Fiddaman.It Sy PS3
1828e49fc963SAndy FiddamanSelection prompt string used within a select loop, by default
1829e49fc963SAndy Fiddaman.Sy \&\&#\&? .
1830e49fc963SAndy Fiddaman.Pp
1831e49fc963SAndy FiddamanThe shell specifies a default value to
1832e49fc963SAndy Fiddaman.Ev PS3 .
1833e49fc963SAndy Fiddaman.It Sy PS4
1834c10c16deSRichard LoweThe value of this variable is expanded for parameter evaluation, command
1835c10c16deSRichard Lowesubstitution, and arithmetic substitution and precedes each line of an
1836e49fc963SAndy Fiddamanexecution trace.
1837e49fc963SAndy FiddamanBy default,
1838e49fc963SAndy Fiddaman.Ev PS4
1839e49fc963SAndy Fiddamanis
1840e49fc963SAndy Fiddaman.Sy \&+ .
1841e49fc963SAndy FiddamanWhen
1842e49fc963SAndy Fiddaman.Ev PS4
1843e49fc963SAndy Fiddamanis unset, the execution trace prompt is also
1844e49fc963SAndy Fiddaman.Sy \&+ .
1845e49fc963SAndy Fiddaman.Pp
1846e49fc963SAndy FiddamanThe shell specifies a default value to
1847e49fc963SAndy Fiddaman.Ev PS4 .
1848e49fc963SAndy Fiddaman.It Sy SHELL
1849e49fc963SAndy FiddamanThe pathname of the shell is kept in the environment.
1850e49fc963SAndy FiddamanAt invocation, if the basename of this variable is
1851e49fc963SAndy Fiddaman.Sy rsh ,
1852e49fc963SAndy Fiddaman.Sy rksh ,
1853e49fc963SAndy Fiddaman.Sy rksh93 ,
1854e49fc963SAndy Fiddamanor
1855e49fc963SAndy Fiddaman.Sy krsh ,
1856e49fc963SAndy Fiddamanthe shell becomes restricted.
1857e49fc963SAndy Fiddaman.Pp
1858e49fc963SAndy Fiddaman.Ev SHELL
1859e49fc963SAndy Fiddamanis not set by the shell.
1860e49fc963SAndy FiddamanOn some systems,
1861e49fc963SAndy Fiddaman.Ev SHELL
1862e49fc963SAndy Fiddamanis set by
1863e49fc963SAndy Fiddaman.Xr login 1 .
1864e49fc963SAndy Fiddaman.It Sy TIMEFORMAT
1865c10c16deSRichard LoweThe value of this parameter is used as a format string specifying how the
1866e49fc963SAndy Fiddamantiming information for pipelines prefixed with the
1867e49fc963SAndy Fiddaman.Ic time
1868e49fc963SAndy Fiddamanreserved word should be displayed.
1869e49fc963SAndy FiddamanThe
1870e49fc963SAndy Fiddaman.Sy \&%
1871e49fc963SAndy Fiddamancharacter introduces a format sequence that is expanded to a time value or
1872e49fc963SAndy Fiddamanother information.
1873e49fc963SAndy Fiddaman.Pp
1874c10c16deSRichard LoweThe format sequences and their meanings are as follows.
1875e49fc963SAndy Fiddaman.Bl -tag -width Ar
1876e49fc963SAndy Fiddaman.It Sy %%
1877e49fc963SAndy FiddamanA literal
1878e49fc963SAndy Fiddaman.Sy % .
1879e49fc963SAndy Fiddaman.Sm off
1880e49fc963SAndy Fiddaman.It Sy % Oo Ar p Oc Oo Cm l Oc Cm R
1881c10c16deSRichard LoweThe elapsed time in seconds.
1882e49fc963SAndy Fiddaman.It Sy % Oo Ar p Oc Oo Cm l Oc Cm U
1883c10c16deSRichard LoweThe number of CPU seconds spent in user mode.
1884e49fc963SAndy Fiddaman.It Sy % Oo Ar p Oc Oo Cm l Oc Cm S
1885c10c16deSRichard LoweThe number of CPU seconds spent in system mode.
1886e49fc963SAndy Fiddaman.It Sy % Ns Cm P
1887e49fc963SAndy FiddamanThe CPU percentage, computed as
1888e49fc963SAndy Fiddaman.Sy (U + S) / R .
1889e49fc963SAndy Fiddaman.Sm on
1890e49fc963SAndy Fiddaman.El
1891e49fc963SAndy Fiddaman.Pp
1892e49fc963SAndy FiddamanThe braces denote optional portions.
1893e49fc963SAndy FiddamanThe optional
1894e49fc963SAndy Fiddaman.Ar p
1895e49fc963SAndy Fiddamanis a digit specifying
1896e49fc963SAndy Fiddamanthe
1897e49fc963SAndy Fiddaman.Ar precision ,
1898e49fc963SAndy Fiddamanthe number of fractional digits after a decimal point.
1899e49fc963SAndy FiddamanA value of
1900e49fc963SAndy Fiddaman.Sy 0
1901e49fc963SAndy Fiddamancauses no decimal point or fraction to be output.
1902e49fc963SAndy FiddamanAt most three places after the decimal point can be displayed.
1903e49fc963SAndy FiddamanValues of
1904e49fc963SAndy Fiddaman.Ar p
1905e49fc963SAndy Fiddamangreater than
1906e49fc963SAndy Fiddaman.Sy 3
1907e49fc963SAndy Fiddamanare treated as
1908e49fc963SAndy Fiddaman.Sy 3 .
1909e49fc963SAndy FiddamanIf
1910e49fc963SAndy Fiddaman.Ar p
1911e49fc963SAndy Fiddamanis not specified, the value
1912e49fc963SAndy Fiddaman.Sy 3
1913e49fc963SAndy Fiddamanis used.
1914e49fc963SAndy Fiddaman.Pp
1915e49fc963SAndy FiddamanThe optional
1916e49fc963SAndy Fiddaman.Cm l
1917e49fc963SAndy Fiddamanspecifies a longer format, including hours if greater than zero, minutes, and
1918e49fc963SAndy Fiddamanseconds of the form
1919e49fc963SAndy Fiddaman.Em HHhMMmSS.FFs .
1920e49fc963SAndy FiddamanThe value of
1921e49fc963SAndy Fiddaman.Ar p
1922c10c16deSRichard Lowedetermines whether or not the fraction is included.
1923e49fc963SAndy Fiddaman.Pp
1924c10c16deSRichard LoweAll other characters are output without change and a trailing NEWLINE is added.
1925e49fc963SAndy FiddamanIf unset, the default value:
1926e49fc963SAndy Fiddaman.Pp
1927e49fc963SAndy Fiddaman.Dl $'\enreal\et%2lR\enuser\et%2lU\ensys%2lS'
1928e49fc963SAndy Fiddaman.Pp
1929e49fc963SAndy Fiddamanis used.
1930e49fc963SAndy FiddamanIf the value is null, no timing information is displayed.
1931e49fc963SAndy Fiddaman.It Sy TMOUT
1932e49fc963SAndy FiddamanIf set to a value greater than zero,
1933e49fc963SAndy Fiddaman.Ev TMOUT
1934e49fc963SAndy Fiddamanis the default time-out value for the
1935e49fc963SAndy Fiddaman.Ic read
1936e49fc963SAndy Fiddamanbuilt-in command.
1937e49fc963SAndy FiddamanThe
1938e49fc963SAndy Fiddaman.Ic select
1939e49fc963SAndy Fiddamancompound command terminates after
1940e49fc963SAndy Fiddaman.Ev TMOUT
1941e49fc963SAndy Fiddamanseconds when input is from a terminal.
1942e49fc963SAndy FiddamanOtherwise, the shell terminates if a line is not entered within the prescribed
1943e49fc963SAndy Fiddamannumber of seconds while reading from a terminal.
1944e49fc963SAndy FiddamanThe shell can be compiled with a maximum bound for this value which cannot be
1945e49fc963SAndy Fiddamanexceeded.
1946e49fc963SAndy Fiddaman.Pp
1947e49fc963SAndy FiddamanThe shell specifies a default value to
1948e49fc963SAndy Fiddaman.Ev TMOUT .
1949e49fc963SAndy Fiddaman.It Sy VISUAL
1950e49fc963SAndy FiddamanIf the value of this variable matches the pattern
1951e49fc963SAndy Fiddaman.Sy *[Vv][Ii]* ,
1952e49fc963SAndy Fiddamanthen the
1953e49fc963SAndy Fiddaman.Sy vi
1954e49fc963SAndy Fiddamanoption is turned on.
1955e49fc963SAndy FiddamanSee
1956e49fc963SAndy Fiddaman.Sx Special Commands .
1957e49fc963SAndy FiddamanIf the value matches the pattern
1958e49fc963SAndy Fiddaman.Sy *gmacs* ,
1959e49fc963SAndy Fiddamanthe
1960e49fc963SAndy Fiddaman.Sy gmacs
1961e49fc963SAndy Fiddamanoption is turned on.
1962e49fc963SAndy FiddamanIf the value matches the pattern
1963e49fc963SAndy Fiddaman.Sy *macs* ,
1964e49fc963SAndy Fiddamanthen the
1965e49fc963SAndy Fiddaman.Sy emacs
1966e49fc963SAndy Fiddamanoption is turned on.
1967e49fc963SAndy FiddamanThe value of
1968e49fc963SAndy Fiddaman.Ev VISUAL
1969e49fc963SAndy Fiddamanoverrides the value of
1970e49fc963SAndy Fiddaman.Ev EDITOR .
1971e49fc963SAndy Fiddaman.El
1972e49fc963SAndy Fiddaman.Ss "Field Splitting"
1973c10c16deSRichard LoweAfter parameter expansion and command substitution, the results of
1974e49fc963SAndy Fiddamansubstitutions are scanned for the field separator characters
1975e49fc963SAndy Fiddaman.Pq those found in Ev IFS
1976e49fc963SAndy Fiddamanand split into distinct fields where such characters are found.
1977e49fc963SAndy FiddamanExplicit null fields
1978e49fc963SAndy Fiddaman.Pq Sy "" or Sy \&''
1979e49fc963SAndy Fiddamanare retained.
1980e49fc963SAndy FiddamanImplicit null fields, those resulting from parameters that have no values or
1981e49fc963SAndy Fiddamancommand substitutions with no output, are removed.
1982e49fc963SAndy Fiddaman.Pp
1983e49fc963SAndy FiddamanIf the
1984e49fc963SAndy Fiddaman.Sy braceexpand
1985e49fc963SAndy Fiddaman.Pq Fl B
1986e49fc963SAndy Fiddamanoption is set, each of the fields resulting from
1987e49fc963SAndy Fiddaman.Ev IFS
1988e49fc963SAndy Fiddamanare checked to see if they contain one or more of the brace patterns.
1989e49fc963SAndy FiddamanValid brace patterns are:
1990e49fc963SAndy Fiddaman.Pp
1991e49fc963SAndy Fiddaman.Bl -item -offset Ds -compact
1992e49fc963SAndy Fiddaman.Sm off
1993e49fc963SAndy Fiddaman.It
1994e49fc963SAndy Fiddaman.Brq Sy \&*,* Ns Oo Sy ,* Oc Ns No ...
1995e49fc963SAndy Fiddaman.It
1996e49fc963SAndy Fiddaman.Brq Ar l1 Sy \&.. Ar l2
1997e49fc963SAndy Fiddaman.It
1998e49fc963SAndy Fiddaman.Brq Ar n1 Sy \&.. Ar n2
1999e49fc963SAndy Fiddaman.It
2000e49fc963SAndy Fiddaman.Brq Ar n1 Sy \&.. Ar n2 Sy % Ar fmt
2001e49fc963SAndy Fiddaman.It
2002e49fc963SAndy Fiddaman.Brq Ar n1 Sy \&.. Ar n2 Sy \&.. Ar n3
2003e49fc963SAndy Fiddaman.It
2004e49fc963SAndy Fiddaman.Brq Ar n1 Sy \&.. Ar n2 Sy \&.. Ar n3 Sy % Ar fmt
2005e49fc963SAndy Fiddaman.Sm on
2006e49fc963SAndy Fiddaman.El
2007e49fc963SAndy Fiddaman.Pp
2008e49fc963SAndy Fiddamanwhere
2009e49fc963SAndy Fiddaman.Sy *
2010e49fc963SAndy Fiddamanrepresents any character,
2011e49fc963SAndy Fiddaman.Ar l1 ,
2012e49fc963SAndy Fiddaman.Ar l2
2013e49fc963SAndy Fiddamanare letters and
2014e49fc963SAndy Fiddaman.Ar n1 ,
2015e49fc963SAndy Fiddaman.Ar n2 ,
2016e49fc963SAndy Fiddaman.Ar n3
2017e49fc963SAndy Fiddamanare signed numbers and
2018e49fc963SAndy Fiddaman.Ar fmt
2019e49fc963SAndy Fiddamanis a format specified as used by
2020e49fc963SAndy Fiddaman.Ic printf .
2021e49fc963SAndy FiddamanIn each case, fields are created by prepending the characters before the
2022e49fc963SAndy Fiddaman.Sy {
2023e49fc963SAndy Fiddamanand appending the characters after
2024e49fc963SAndy Fiddamanthe
2025e49fc963SAndy Fiddaman.Sy }
2026e49fc963SAndy Fiddamanto each of the strings generated by the characters between the
2027e49fc963SAndy Fiddaman.Sy {
2028e49fc963SAndy Fiddamanand
2029e49fc963SAndy Fiddaman.Sy } .
2030e49fc963SAndy FiddamanThe resulting fields are checked to see if they have any brace patterns.
2031e49fc963SAndy Fiddaman.Pp
2032e49fc963SAndy FiddamanIn the first form, a field is created for each string between
2033e49fc963SAndy Fiddaman.Sy {
2034e49fc963SAndy Fiddamanand the first comma
2035e49fc963SAndy Fiddaman.Pq Sq \&, ,
2036e49fc963SAndy Fiddamanbetween a pair of commas
2037e49fc963SAndy Fiddaman.Pq Sq \&,
2038e49fc963SAndy Fiddamanand between
2039e49fc963SAndy Fiddamanthe last comma
2040e49fc963SAndy Fiddaman.Pq Sq \&,
2041e49fc963SAndy Fiddamanand the terminating
2042e49fc963SAndy Fiddaman.Sy } .
2043e49fc963SAndy FiddamanThe string
2044e49fc963SAndy Fiddamanrepresented by
2045e49fc963SAndy Fiddaman.Sy *
2046e49fc963SAndy Fiddamancan contain embedded matching { and } without quoting.
2047e49fc963SAndy FiddamanOtherwise, each
2048e49fc963SAndy Fiddaman.Sy {
2049e49fc963SAndy Fiddamanand
2050e49fc963SAndy Fiddaman.Sy }
2051e49fc963SAndy Fiddamanwithin
2052e49fc963SAndy Fiddaman.Sy *
2053e49fc963SAndy Fiddamanmust be quoted.
2054e49fc963SAndy Fiddaman.Pp
2055e49fc963SAndy FiddamanIn the second form,
2056e49fc963SAndy Fiddaman.Ar l1
2057e49fc963SAndy Fiddamanand
2058e49fc963SAndy Fiddaman.Ar l2
2059e49fc963SAndy Fiddamanmust both be either upper case or both be lower case characters in the C
2060e49fc963SAndy Fiddamanlocale.
2061e49fc963SAndy FiddamanIn this case a field is created for each character from
2062e49fc963SAndy Fiddaman.Ar l1
2063e49fc963SAndy Fiddamanto
2064e49fc963SAndy Fiddaman.Ar l2
2065e49fc963SAndy Fiddamaninclusive.
2066e49fc963SAndy Fiddaman.Pp
2067c10c16deSRichard LoweIn the remaining forms, a field is created for each number starting at
2068e49fc963SAndy Fiddaman.Ar n1 .
2069e49fc963SAndy FiddamanThis continues until it reaches
2070e49fc963SAndy Fiddaman.Ar n2
2071e49fc963SAndy Fiddamanand increments
2072e49fc963SAndy Fiddaman.Ar n1
2073e49fc963SAndy Fiddamanby
2074e49fc963SAndy Fiddaman.Ar n3 .
2075e49fc963SAndy FiddamanThe cases where
2076e49fc963SAndy Fiddaman.Ar n3
2077e49fc963SAndy Fiddamanis not specified behave as if
2078e49fc963SAndy Fiddaman.Ar n3
2079e49fc963SAndy Fiddamanwere 1 if
2080e49fc963SAndy Fiddaman.Ar n1
2081e49fc963SAndy Fiddaman<=
2082e49fc963SAndy Fiddaman.Ar n2 ,
2083e49fc963SAndy Fiddamanand -1 otherwise.
2084e49fc963SAndy Fiddaman.Pp
2085e49fc963SAndy FiddamanIn forms which specify
2086e49fc963SAndy Fiddaman.Sy % Ns Ar fmt ,
2087e49fc963SAndy Fiddamanany format flags, widths and precisions can be specified and
2088e49fc963SAndy Fiddaman.Ar fmt
2089e49fc963SAndy Fiddamancan end in any of the specifiers
2090e49fc963SAndy Fiddaman.Sy cdiouxX .
2091e49fc963SAndy FiddamanFor example,
2092e49fc963SAndy Fiddaman.Sy {a,z}{1..5..3%02d}{b..c}x
2093e49fc963SAndy Fiddamanexpands to the 8 fields,
2094e49fc963SAndy Fiddaman.Sy a01bx ,
2095e49fc963SAndy Fiddaman.Sy a01cx ,
2096e49fc963SAndy Fiddaman.Sy a04bx ,
2097e49fc963SAndy Fiddaman.Sy a04cx ,
2098e49fc963SAndy Fiddaman.Sy z01bx ,
2099e49fc963SAndy Fiddaman.Sy z01cx ,
2100e49fc963SAndy Fiddaman.Sy z04bx ,
2101e49fc963SAndy Fiddamanand
2102e49fc963SAndy Fiddaman.Sy z04cx .
2103e49fc963SAndy Fiddaman.Ss "File Name Generation"
2104e49fc963SAndy FiddamanFollowing splitting, each field is scanned for the characters
2105e49fc963SAndy Fiddaman.Sy \&* ,
2106e49fc963SAndy Fiddaman.Sy \&? ,
2107e49fc963SAndy Fiddaman.Sy \&( ,
2108e49fc963SAndy Fiddamanand
2109e49fc963SAndy Fiddaman.Sy \&[ ,
2110e49fc963SAndy Fiddamanunless the
2111e49fc963SAndy Fiddaman.Fl f
2112e49fc963SAndy Fiddamanoption has been set.
2113e49fc963SAndy FiddamanIf one of these characters appears, then the word is regarded as a pattern.
2114e49fc963SAndy Fiddaman.Pp
2115c10c16deSRichard LoweEach file name component that contains any pattern character is replaced with a
2116c10c16deSRichard Lowelexicographically sorted set of names that matches the pattern from that
2117e49fc963SAndy Fiddamandirectory.
2118e49fc963SAndy FiddamanIf no file name is found that matches the pattern, then that component of the
2119e49fc963SAndy Fiddamanfile name is left unchanged unless the pattern is prefixed with
2120e49fc963SAndy Fiddaman.Sy ~(N)
2121e49fc963SAndy Fiddamanin which case it is removed.
2122e49fc963SAndy FiddamanIf
2123e49fc963SAndy Fiddaman.Ev FIGNORE
2124e49fc963SAndy Fiddamanis set, then each file name component that matches the pattern defined by the
2125e49fc963SAndy Fiddamanvalue of
2126e49fc963SAndy Fiddaman.Ev FIGNORE
2127e49fc963SAndy Fiddamanis ignored when generating the matching file names.
2128e49fc963SAndy FiddamanThe names
2129e49fc963SAndy Fiddaman.Sy \&.
2130e49fc963SAndy Fiddamanand
2131e49fc963SAndy Fiddaman.Sy \&..
2132e49fc963SAndy Fiddamanare also ignored.
2133e49fc963SAndy FiddamanIf
2134e49fc963SAndy Fiddaman.Ev FIGNORE
2135e49fc963SAndy Fiddamanis not set, the character
2136e49fc963SAndy Fiddaman.Sy \&.
2137e49fc963SAndy Fiddamanat the start of each file name component is ignored unless the first character
2138e49fc963SAndy Fiddamanof the pattern corresponding to this component is the character
2139e49fc963SAndy Fiddaman.Sy \&.
2140e49fc963SAndy Fiddamanitself.
2141e49fc963SAndy FiddamanFor other uses of pattern matching the
2142e49fc963SAndy Fiddaman.Sy /
2143e49fc963SAndy Fiddamanand
2144e49fc963SAndy Fiddaman.Sy \&.
2145e49fc963SAndy Fiddamanare not specially treated.
2146e49fc963SAndy Fiddaman.Bl -tag -width Ds
2147e49fc963SAndy Fiddaman.It Sy *
2148e49fc963SAndy FiddamanMatch any string, including the null string.
2149e49fc963SAndy FiddamanWhen used for file name expansion, if the
2150e49fc963SAndy Fiddaman.Sy globstar
2151e49fc963SAndy Fiddamanoption is on, two adjacent
2152e49fc963SAndy Fiddaman.Sy * Ns No s
2153e49fc963SAndy Fiddamanby themselves match all files and zero or more directories and subdirectories.
2154e49fc963SAndy FiddamanIf the two adjacent
2155e49fc963SAndy Fiddaman.Sy * Ns No s
2156e49fc963SAndy Fiddamanare followed by a
2157e49fc963SAndy Fiddaman.Sy / ,
2158e49fc963SAndy Fiddamanonly directories and subdirectories match.
2159e49fc963SAndy Fiddaman.It Sy \&?
2160c10c16deSRichard LoweMatches any single character.
2161e49fc963SAndy Fiddaman.It Sy [...]
2162e49fc963SAndy FiddamanMatch any one of the enclosed characters.
2163e49fc963SAndy FiddamanA pair of characters separated by
2164e49fc963SAndy Fiddaman.Sy -
2165e49fc963SAndy Fiddamanmatches any character lexically between the pair, inclusive.
2166e49fc963SAndy FiddamanIf the first character following the opening
2167e49fc963SAndy Fiddaman.Sy \&[
2168e49fc963SAndy Fiddamanis a
2169e49fc963SAndy Fiddaman.Sy \&!
2170e49fc963SAndy Fiddamanor
2171e49fc963SAndy Fiddaman.Sy ^ ,
2172e49fc963SAndy Fiddamanany character not enclosed is matched.
2173e49fc963SAndy FiddamanA
2174e49fc963SAndy Fiddaman.Sy -
2175e49fc963SAndy Fiddamancan be included in the character set by putting it as the first or last
2176e49fc963SAndy Fiddamancharacter.
2177e49fc963SAndy FiddamanWithin
2178e49fc963SAndy Fiddaman.Sy \&[
2179e49fc963SAndy Fiddamanand
2180e49fc963SAndy Fiddaman.Sy \&] ,
2181e49fc963SAndy Fiddamancharacter classes can be specified with the syntax
2182e49fc963SAndy Fiddaman.Sy [: Ns Ar class Ns Sy \&:\&]
2183e49fc963SAndy Fiddamanwhere
2184e49fc963SAndy Fiddaman.Ar class
2185e49fc963SAndy Fiddamanis one of the following classes defined in the
2186e49fc963SAndy Fiddaman.Sy ANSI-C
2187c10c16deSRichard Lowestandard:
2188e49fc963SAndy Fiddaman.Bl -column -offset indent xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx xxxxxx
2189e49fc963SAndy Fiddaman.It alnum Ta alpha Ta blank Ta cntrl Ta digit Ta graph
2190e49fc963SAndy Fiddaman.It lower Ta print Ta punct Ta space Ta upper Ta word
2191e49fc963SAndy Fiddaman.It xdigit Ta Ta Ta Ta Ta
2192e49fc963SAndy Fiddaman.El
2193e49fc963SAndy Fiddaman.Pp
2194e49fc963SAndy Fiddaman.Ar word
2195e49fc963SAndy Fiddamanis equivalent to
2196e49fc963SAndy Fiddaman.Ar alnum
2197e49fc963SAndy Fiddamanplus the character
2198e49fc963SAndy Fiddaman.Sy _ .
2199e49fc963SAndy FiddamanWithin
2200e49fc963SAndy Fiddaman.Sy \&[
2201e49fc963SAndy Fiddamanand
2202e49fc963SAndy Fiddaman.Sy \&] ,
2203e49fc963SAndy Fiddamanan equivalence class can be specified with the syntax
2204e49fc963SAndy Fiddaman.Sy [= Ns Ar c Ns Sy =]
2205e49fc963SAndy Fiddamanwhich matches all characters with the same primary collation weight (as defined
2206e49fc963SAndy Fiddamanby the current locale) as the character
2207e49fc963SAndy Fiddaman.Ar c .
2208e49fc963SAndy FiddamanWithin
2209e49fc963SAndy Fiddaman.Sy \&[
2210e49fc963SAndy Fiddamanand
2211e49fc963SAndy Fiddaman.Sy \&] ,
2212e49fc963SAndy Fiddaman.Sm off
2213e49fc963SAndy Fiddaman.Sy \&[ \&. Ar symbol Ns \&. Sy \&]
2214e49fc963SAndy Fiddaman.Sm on
2215e49fc963SAndy Fiddamanmatches the collating symbol
2216e49fc963SAndy Fiddaman.Ar symbol .
2217e49fc963SAndy Fiddaman.El
2218e49fc963SAndy Fiddaman.Pp
2219e49fc963SAndy FiddamanA
2220e49fc963SAndy Fiddaman.Sy pattern-list
2221e49fc963SAndy Fiddamanis a list of one or more patterns separated from each other with an
2222e49fc963SAndy Fiddaman.Sy \&&
2223e49fc963SAndy Fiddamanor
2224e49fc963SAndy Fiddaman.Sy \&| .
2225e49fc963SAndy FiddamanAn
2226e49fc963SAndy Fiddaman.Sy \&&
2227e49fc963SAndy Fiddamansignifies that all patterns must be matched whereas
2228e49fc963SAndy Fiddaman.Sy \&|
2229e49fc963SAndy Fiddamanrequires that only one pattern be matched.
2230e49fc963SAndy FiddamanComposite patterns can be formed with one or more of the following
2231e49fc963SAndy Fiddamansub-patterns:
2232e49fc963SAndy Fiddaman.Bl -tag -width xxxxxxxxxxxxxxxxxxxxx
2233e49fc963SAndy Fiddaman.Sm off
2234e49fc963SAndy Fiddaman.It Sy \&?( Ar pattern-list Sy \&)
2235c10c16deSRichard LoweOptionally matches any one of the specified patterns.
2236e49fc963SAndy Fiddaman.It Sy \&*( Ar pattern-list Sy \&)
2237c10c16deSRichard LoweMatches zero or more occurrences of the specified patterns.
2238e49fc963SAndy Fiddaman.It Sy \&+( Ar pattern-list Sy \&)
2239c10c16deSRichard LoweMatches one or more occurrences of the specified patterns.
2240e49fc963SAndy Fiddaman.It Sy \&{ Ar n Sy \&} Sy \&( Ar pattern-list Sy \&)
2241e49fc963SAndy Fiddaman.Sm on
2242e49fc963SAndy FiddamanMatches
2243e49fc963SAndy Fiddaman.Ar n
2244e49fc963SAndy Fiddamanoccurrences of the specified patterns.
2245e49fc963SAndy Fiddaman.Sm off
2246e49fc963SAndy Fiddaman.It Sy \&{ Ar m Sy \&, Ar n Sy \&} Sy \&( Ar pattern-list Sy \&)
2247e49fc963SAndy Fiddaman.Sm on
2248e49fc963SAndy FiddamanMatches from
2249e49fc963SAndy Fiddaman.Ar m
2250e49fc963SAndy Fiddamanto
2251e49fc963SAndy Fiddaman.Ar n
2252e49fc963SAndy Fiddamanoccurrences of the specified patterns.
2253e49fc963SAndy FiddamanIf
2254e49fc963SAndy Fiddaman.Ar m
2255e49fc963SAndy Fiddamanis omitted,
2256e49fc963SAndy Fiddaman.Sy 0
2257e49fc963SAndy Fiddamanis used.
2258e49fc963SAndy FiddamanIf
2259e49fc963SAndy Fiddaman.Ar n
2260e49fc963SAndy Fiddamanis omitted at least
2261e49fc963SAndy Fiddaman.Ar m
2262c10c16deSRichard Loweoccurrences are matched.
2263e49fc963SAndy Fiddaman.Sm off
2264e49fc963SAndy Fiddaman.It Sy \&@( Ar pattern-list Sy \&)
2265c10c16deSRichard LoweMatches exactly one of the specified patterns.
2266e49fc963SAndy Fiddaman.It Sy \&!( Ar pattern-list Sy \&)
2267c10c16deSRichard LoweMatches anything except one of the specified patterns.
2268e49fc963SAndy Fiddaman.Sm on
2269e49fc963SAndy Fiddaman.El
2270e49fc963SAndy Fiddaman.Pp
2271c10c16deSRichard LoweBy default, each pattern, or sub-pattern matches the longest string possible
2272e49fc963SAndy Fiddamanconsistent with generating the longest overall match.
2273e49fc963SAndy FiddamanIf more than one match is possible, the one starting closest to the beginning
2274e49fc963SAndy Fiddamanof the string is chosen.
2275e49fc963SAndy FiddamanHowever, for each of the compound patterns a
2276e49fc963SAndy Fiddaman.Sy -
2277e49fc963SAndy Fiddamancan be inserted in front
2278e49fc963SAndy Fiddamanof the
2279e49fc963SAndy Fiddaman.Sy \&(
2280e49fc963SAndy Fiddamanto cause the shortest match to the specified
2281e49fc963SAndy Fiddaman.Ar pattern-list
2282c10c16deSRichard Loweto be used.
2283e49fc963SAndy Fiddaman.Pp
2284e49fc963SAndy FiddamanWhen
2285e49fc963SAndy Fiddaman.Sy pattern-list
2286e49fc963SAndy Fiddamanis contained within parentheses, the backslash
2287e49fc963SAndy Fiddamancharacter
2288e49fc963SAndy Fiddaman.Pq Sy \e
2289e49fc963SAndy Fiddamanis treated specially even when inside a character class.
2290e49fc963SAndy FiddamanAll
2291e49fc963SAndy Fiddaman.Sy ANSI-C
2292e49fc963SAndy Fiddamancharacter escapes are recognized and match the specified character.
2293e49fc963SAndy FiddamanIn addition the following escape sequences are recognized:
2294e49fc963SAndy Fiddaman.Bl -tag -width Ds
2295e49fc963SAndy Fiddaman.It Sy \ed
2296c10c16deSRichard LoweMatches any character in the digit class.
2297e49fc963SAndy Fiddaman.It Sy \eD
2298c10c16deSRichard LoweMatches any character not in the digit class.
2299e49fc963SAndy Fiddaman.It Sy \es
2300c10c16deSRichard LoweMatches any character in the space class.
2301e49fc963SAndy Fiddaman.It Sy \eS
2302c10c16deSRichard LoweMatches any character not in the space class.
2303e49fc963SAndy Fiddaman.It Sy \ew
2304c10c16deSRichard LoweMatches any character in the word class.
2305e49fc963SAndy Fiddaman.It Sy \eW
2306c10c16deSRichard LoweMatches any character not in the word class.
2307e49fc963SAndy Fiddaman.El
2308e49fc963SAndy Fiddaman.Pp
2309e49fc963SAndy FiddamanA pattern of the form
2310e49fc963SAndy Fiddaman.Sy %( Ns Ar pattern-pairs Ns Sy \&)
2311e49fc963SAndy Fiddamanis a sub-pattern that can be used to match nested character expressions.
2312e49fc963SAndy FiddamanEach
2313e49fc963SAndy Fiddaman.Ar pattern-pair
2314e49fc963SAndy Fiddamanis a two character sequence which cannot contain
2315e49fc963SAndy Fiddaman.Sy \&&
2316e49fc963SAndy Fiddamanor
2317e49fc963SAndy Fiddaman.Sy \&| .
2318e49fc963SAndy FiddamanThe first
2319e49fc963SAndy Fiddaman.Ar pattern-pair
2320e49fc963SAndy Fiddamanspecifies the starting and ending characters for the match.
2321e49fc963SAndy FiddamanEach subsequent
2322e49fc963SAndy Fiddaman.Ar pattern-pair
2323e49fc963SAndy Fiddamanrepresents the beginning and ending characters of a nested group that is
2324e49fc963SAndy Fiddamanskipped over when counting starting and ending character matches.
2325e49fc963SAndy FiddamanThe behavior is unspecified when the first character of a
2326e49fc963SAndy Fiddaman.Ar pattern-pair
2327e49fc963SAndy Fiddamanis alphanumeric except for the following:
2328e49fc963SAndy Fiddaman.Bl -tag -width Ds
2329e49fc963SAndy Fiddaman.It Sy D
2330c10c16deSRichard LoweCauses the ending character to terminate the search for this pattern without
2331c10c16deSRichard Lowefinding a match.
2332e49fc963SAndy Fiddaman.It Sy E
2333c10c16deSRichard LoweCauses the ending character to be interpreted as an escape character.
2334e49fc963SAndy Fiddaman.It Sy L
2335c10c16deSRichard LoweCauses the ending character to be interpreted as a quote character causing all
2336c10c16deSRichard Lowecharacters to be ignored when looking for a match.
2337e49fc963SAndy Fiddaman.It Sy Q
2338c10c16deSRichard LoweCauses the ending character to be interpreted as a quote character causing all
2339c10c16deSRichard Lowecharacters other than any escape character to be ignored when looking for a
2340c10c16deSRichard Lowematch.
2341e49fc963SAndy Fiddaman.El
2342e49fc963SAndy Fiddaman.Pp
2343e49fc963SAndy Fiddaman.Sy %({}Q"E\e) ,
2344e49fc963SAndy Fiddamanmatches characters starting at
2345e49fc963SAndy Fiddaman.Sy {
2346e49fc963SAndy Fiddamanuntil the matching
2347e49fc963SAndy Fiddaman.Sy }
2348e49fc963SAndy Fiddamanis found not counting any
2349e49fc963SAndy Fiddaman.Sy {
2350e49fc963SAndy Fiddamanor
2351e49fc963SAndy Fiddaman.Sy }
2352e49fc963SAndy Fiddamanthat is inside a double quoted string or preceded by the escape character
2353e49fc963SAndy Fiddaman.Pq Sy \e .
2354e49fc963SAndy FiddamanWithout the
2355e49fc963SAndy Fiddaman.Sy {}
2356e49fc963SAndy Fiddamanthis pattern matches any C language string.
2357e49fc963SAndy Fiddaman.Pp
2358e49fc963SAndy FiddamanEach sub-pattern in a composite pattern is numbered, starting at
2359e49fc963SAndy Fiddaman.Sy 1 ,
2360e49fc963SAndy Fiddamanby the location of the
2361e49fc963SAndy Fiddaman.Sy \&(
2362e49fc963SAndy Fiddamanwithin the pattern.
2363e49fc963SAndy FiddamanThe sequence
2364e49fc963SAndy Fiddaman.Sy \e Ns Ar n ,
2365e49fc963SAndy Fiddamanwhere
2366e49fc963SAndy Fiddaman.Ar n
2367e49fc963SAndy Fiddamanis a single digit and
2368e49fc963SAndy Fiddaman.Sy \e Ns Ar n ,
2369e49fc963SAndy Fiddamancomes after the
2370e49fc963SAndy Fiddaman.Ar n Ns No th
2371c10c16deSRichard Lowesub-pattern, matches the same string as the sub-pattern itself.
2372e49fc963SAndy Fiddaman.Pp
2373c10c16deSRichard LoweA pattern can contain sub-patterns of the form
2374e49fc963SAndy Fiddaman.Sm off
2375e49fc963SAndy Fiddaman.Sy ~( Ar options Sy \&: Ar pattern-list Sy \&) ,
2376e49fc963SAndy Fiddaman.Sm on
2377e49fc963SAndy Fiddamanwhere either
2378e49fc963SAndy Fiddaman.Ar options
2379e49fc963SAndy Fiddamanor
2380e49fc963SAndy Fiddaman.Sy \&: Ns Ar pattern-list
2381e49fc963SAndy Fiddamancan be omitted.
2382e49fc963SAndy FiddamanUnlike the other compound patterns, these sub-patterns are not counted in the
2383e49fc963SAndy Fiddamannumbered sub-patterns.
2384e49fc963SAndy Fiddaman.Sy \&: Ns Ar pattern-list
2385e49fc963SAndy Fiddamanmust be omitted for options
2386e49fc963SAndy Fiddaman.Sy F ,
2387e49fc963SAndy Fiddaman.Sy G ,
2388e49fc963SAndy Fiddaman.Sy N
2389e49fc963SAndy Fiddamanand
2390e49fc963SAndy Fiddaman.Sy V
2391e49fc963SAndy Fiddamanbelow.
2392e49fc963SAndy FiddamanIf
2393e49fc963SAndy Fiddaman.Ar options
2394e49fc963SAndy Fiddamanis present, it can consist of one or more of the following:
2395e49fc963SAndy Fiddaman.Bl -tag -width Ds
2396e49fc963SAndy Fiddaman.It Sy +
2397e49fc963SAndy FiddamanEnable the following options.
2398e49fc963SAndy FiddamanThis is the default.
2399e49fc963SAndy Fiddaman.It Sy -
2400c10c16deSRichard LoweDisable the following options.
2401e49fc963SAndy Fiddaman.It Sy E
2402c10c16deSRichard LoweThe remainder of the pattern uses extended regular expression syntax like the
2403e49fc963SAndy Fiddaman.Xr egrep 1
2404e49fc963SAndy Fiddamancommand.
2405e49fc963SAndy Fiddaman.It Sy F
2406e49fc963SAndy FiddamanThe remainder of the pattern uses
2407e49fc963SAndy Fiddaman.Xr fgrep 1
2408e49fc963SAndy Fiddamanexpression syntax.
2409e49fc963SAndy Fiddaman.It Sy g
2410c10c16deSRichard LoweFile the longest match (greedy).
2411c10c16deSRichard LoweThis is the default.
2412e49fc963SAndy Fiddaman.It Sy G
2413c10c16deSRichard LoweThe remainder of the pattern uses basic regular expression syntax like the
2414e49fc963SAndy Fiddaman.Xr grep 1
2415e49fc963SAndy Fiddamancommand.
2416e49fc963SAndy Fiddaman.It Sy i
2417c10c16deSRichard LoweTreat the match as case insensitive.
2418e49fc963SAndy Fiddaman.It Sy K
2419c10c16deSRichard LoweThe remainder of the pattern uses shell pattern syntax.
2420c10c16deSRichard LoweThis is the default.
2421e49fc963SAndy Fiddaman.It Sy l
2422c10c16deSRichard LoweLeft anchor the pattern.
2423e49fc963SAndy Fiddaman.Pp
2424e49fc963SAndy FiddamanThis is the default for
2425e49fc963SAndy Fiddaman.Sy K
2426e49fc963SAndy Fiddamanstyle patterns.
2427e49fc963SAndy Fiddaman.It Sy N
2428e49fc963SAndy FiddamanThis is ignored.
2429e49fc963SAndy FiddamanHowever, when it is the first letter and is used with file name generation, and
2430e49fc963SAndy Fiddamanno matches occur, the file pattern expands to the empty string.
2431e49fc963SAndy Fiddaman.It Sy r
2432c10c16deSRichard LoweRight anchor the pattern.
2433e49fc963SAndy Fiddaman.Pp
2434e49fc963SAndy FiddamanThis is the default for
2435e49fc963SAndy Fiddaman.Sy K
2436e49fc963SAndy Fiddamanstyle patterns.
2437e49fc963SAndy Fiddaman.It Sy X
2438b30d1939SAndy FiddamanThe remainder of the pattern uses augmented regular expression syntax.
2439e49fc963SAndy Fiddaman.It Sy P
2440e49fc963SAndy FiddamanThe remainder of the pattern uses
2441e49fc963SAndy Fiddaman.Xr perl 1
2442e49fc963SAndy Fiddamanregular expression syntax.
2443e49fc963SAndy FiddamanNot all perl regular expression syntax is currently implemented.
2444e49fc963SAndy Fiddaman.It Sy V
2445b30d1939SAndy FiddamanThe remainder of the pattern uses System V regular expression syntax.
2446e49fc963SAndy Fiddaman.El
2447e49fc963SAndy Fiddaman.Pp
2448e49fc963SAndy FiddamanIf both
2449e49fc963SAndy Fiddaman.Ar options
2450e49fc963SAndy Fiddamanand
2451e49fc963SAndy Fiddaman.Sy \&: Ns Ar pattern-list
2452e49fc963SAndy Fiddamanare specified, then the options apply only to
2453e49fc963SAndy Fiddaman.Ar pattern-list .
2454e49fc963SAndy FiddamanOtherwise, these options remain in effect until they are disabled by a
2455e49fc963SAndy Fiddamansubsequent
2456e49fc963SAndy Fiddaman.Sy ~(...)
2457e49fc963SAndy Fiddamanor at the end of
2458e49fc963SAndy Fiddamanthe sub-pattern containing
2459e49fc963SAndy Fiddaman.Sy ~(...) .
2460e49fc963SAndy Fiddaman.Ss "Quoting"
2461e49fc963SAndy FiddamanEach of the metacharacters listed in the
2462e49fc963SAndy Fiddaman.Sx Definitions
2463e49fc963SAndy Fiddamansection of this manual page has a special meaning to the shell and causes
2464e49fc963SAndy Fiddamantermination of a word unless quoted.
2465e49fc963SAndy FiddamanA character can be quoted, that is, made to stand for itself, by preceding it
2466e49fc963SAndy Fiddamanwith a backslash
2467e49fc963SAndy Fiddaman.Pq Sy \e .
2468e49fc963SAndy FiddamanThe pair
2469e49fc963SAndy Fiddaman.Sy \eNEWLINE
2470e49fc963SAndy Fiddamanis removed.
2471e49fc963SAndy FiddamanAll characters enclosed between a pair of single quote marks
2472e49fc963SAndy Fiddaman.Pq Sy ''
2473e49fc963SAndy Fiddamanthat is not preceded by a
2474e49fc963SAndy Fiddaman.Sy $
2475e49fc963SAndy Fiddamanare quoted.
2476e49fc963SAndy FiddamanA single quote cannot appear within the single quotes.
2477e49fc963SAndy FiddamanA single quoted string preceded by an unquoted
2478e49fc963SAndy Fiddaman.Sy $
2479e49fc963SAndy Fiddamanis processed as an
2480e49fc963SAndy Fiddaman.Sy ANSI-C
2481e49fc963SAndy Fiddamanstring except for the following:
2482e49fc963SAndy Fiddaman.Bl -tag -width Ar
2483e49fc963SAndy Fiddaman.It Sy \e0
2484c10c16deSRichard LoweCauses the remainder of the string to be ignored.
2485e49fc963SAndy Fiddaman.It Sy \ec Ns Ar x
2486e49fc963SAndy FiddamanExpands to the character
2487e49fc963SAndy Fiddaman.No CTRL- Ns Ar x .
2488e49fc963SAndy Fiddaman.It Sy \eC[\&. Ns Ar name Ns Sy \&.\&]
2489e49fc963SAndy FiddamanExpands to the collating element
2490e49fc963SAndy Fiddaman.Ar name .
2491e49fc963SAndy Fiddaman.It Sy \ee
2492e49fc963SAndy FiddamanEquivalent to the escape character
2493e49fc963SAndy Fiddaman.Pq ASCII 033 .
2494e49fc963SAndy Fiddaman.It Sy \eE
2495e49fc963SAndy FiddamanEquivalent to the escape character
2496e49fc963SAndy Fiddaman.Pq ASCII 033 .
2497e49fc963SAndy Fiddaman.El
2498e49fc963SAndy Fiddaman.Pp
2499e49fc963SAndy FiddamanInside double quote marks
2500e49fc963SAndy Fiddaman.Pq Sy \&"" ,
2501e49fc963SAndy Fiddamanparameter and command substitution occur and
2502e49fc963SAndy Fiddaman.Sy \e
2503e49fc963SAndy Fiddamanquotes the characters
2504e49fc963SAndy Fiddaman.Sy \e ,
2505e49fc963SAndy Fiddaman.Sy \&` ,
2506e49fc963SAndy Fiddaman.Sy \&" ,
2507e49fc963SAndy Fiddamanand
2508e49fc963SAndy Fiddaman.Sy \&$ .
2509e49fc963SAndy FiddamanA
2510e49fc963SAndy Fiddaman.Sy \&$
2511e49fc963SAndy Fiddamanin front of a double quoted string is ignored in the
2512e49fc963SAndy Fiddaman.Dv C
2513e49fc963SAndy Fiddamanor
2514e49fc963SAndy Fiddaman.Dv POSIX
2515e49fc963SAndy Fiddamanlocale, and might cause the string to be replaced by a locale specific string
2516e49fc963SAndy Fiddamanotherwise.
2517e49fc963SAndy FiddamanThe meaning of
2518e49fc963SAndy Fiddaman.Sy $*
2519e49fc963SAndy Fiddamanand
2520e49fc963SAndy Fiddaman.Sy $@
2521e49fc963SAndy Fiddamanis identical when not quoted or when used as a variable assignment value or as
2522e49fc963SAndy Fiddamana file name.
2523e49fc963SAndy FiddamanHowever, when used as a command argument,
2524e49fc963SAndy Fiddaman.Sy \&"$*"
2525e49fc963SAndy Fiddamanis equivalent to
2526e49fc963SAndy Fiddaman.Sm off
2527e49fc963SAndy Fiddaman.Sy \&"$1 Ar d Sy $2 Ar d No ..." ,
2528e49fc963SAndy Fiddaman.Sm on
2529e49fc963SAndy Fiddamanwhere
2530e49fc963SAndy Fiddaman.Ar d
2531e49fc963SAndy Fiddamanis the first character of the
2532e49fc963SAndy Fiddaman.Ev IFS
2533e49fc963SAndy Fiddamanvariable, whereas
2534e49fc963SAndy Fiddaman.Sy \&"$@"
2535e49fc963SAndy Fiddamanis equivalent to
2536e49fc963SAndy Fiddaman.Sy \&"$1" \&"$2" No ...
2537e49fc963SAndy FiddamanInside grave quote marks
2538e49fc963SAndy Fiddaman.Pq Sy `` ,
2539e49fc963SAndy Fiddaman.Sy \e
2540e49fc963SAndy Fiddamanquotes the characters
2541e49fc963SAndy Fiddaman.Sy \e ,
2542e49fc963SAndy Fiddaman.Sy ` ,
2543e49fc963SAndy Fiddamanand
2544e49fc963SAndy Fiddaman.Sy $ .
2545e49fc963SAndy FiddamanIf the grave quotes occur within double quotes, then
2546e49fc963SAndy Fiddaman.Sy \e
2547e49fc963SAndy Fiddamanalso quotes the character
2548e49fc963SAndy Fiddaman.Sy \&" .
2549e49fc963SAndy Fiddaman.Pp
2550c10c16deSRichard LoweThe special meaning of reserved words or aliases can be removed by quoting any
2551e49fc963SAndy Fiddamancharacter of the reserved word.
2552e49fc963SAndy FiddamanThe recognition of function names or built-in command names cannot be altered
2553e49fc963SAndy Fiddamanby quoting them.
2554e49fc963SAndy Fiddaman.Ss "Arithmetic Evaluation"
2555c10c16deSRichard LoweThe shell performs arithmetic evaluation for arithmetic substitution, to
2556c10c16deSRichard Loweevaluate an arithmetic command, to evaluate an indexed array subscript, and to
2557e49fc963SAndy Fiddamanevaluate arguments to the built-in commands
2558e49fc963SAndy Fiddaman.Ic shift
2559e49fc963SAndy Fiddamanand
2560e49fc963SAndy Fiddaman.Ic let .
2561c10c16deSRichard LoweArithmetic evaluation is also performed on argument operands of the built-in
2562e49fc963SAndy Fiddamancommand
2563e49fc963SAndy Fiddaman.Ic printf
2564e49fc963SAndy Fiddamanthat correspond to numeric format specifiers in the format operand.
2565e49fc963SAndy FiddamanSee
2566e49fc963SAndy Fiddaman.Xr printf 1 .
2567e49fc963SAndy FiddamanEvaluations are performed using double precision floating point arithmetic or
2568e49fc963SAndy Fiddamanlong double precision floating point for systems that provide this data type.
2569e49fc963SAndy FiddamanFloating point constants follow the
2570e49fc963SAndy Fiddaman.Sy ANSI-C
2571e49fc963SAndy Fiddamanprogramming language floating point conventions.
2572e49fc963SAndy FiddamanThe floating point constants
2573e49fc963SAndy Fiddaman.Dv Nan
2574e49fc963SAndy Fiddamanand
2575e49fc963SAndy Fiddaman.Dv Inf
2576e49fc963SAndy Fiddamancan be used to represent "not a number" and infinity respectively.
2577e49fc963SAndy FiddamanInteger constants follow the
2578e49fc963SAndy Fiddaman.Sy ANSI-C
2579e49fc963SAndy Fiddamanprogramming language integer constant conventions although only single byte
2580e49fc963SAndy Fiddamancharacter constants are recognized and character casts are not recognized.
2581e49fc963SAndy FiddamanConstants can be of the form
2582e49fc963SAndy Fiddaman.Oo Ar base Ns No \&# Oc Ns Ar n
2583e49fc963SAndy Fiddamanwhere
2584e49fc963SAndy Fiddaman.Ar base
2585e49fc963SAndy Fiddamanis a decimal number between two and sixty-four representing the arithmetic base
2586e49fc963SAndy Fiddamanand
2587e49fc963SAndy Fiddaman.Ar n
2588e49fc963SAndy Fiddamanis a number in that base.
2589e49fc963SAndy FiddamanThe digits greater than
2590e49fc963SAndy Fiddaman.Sy 9
2591e49fc963SAndy Fiddamanare represented by the lower case letters, the upper case letters,
2592e49fc963SAndy Fiddaman.Sy @ ,
2593e49fc963SAndy Fiddamanand
2594e49fc963SAndy Fiddaman.Sy _
2595e49fc963SAndy Fiddamanrespectively.
2596e49fc963SAndy FiddamanFor bases less than or equal to
2597e49fc963SAndy Fiddaman.Sy 36 ,
2598e49fc963SAndy Fiddamanupper and lower case characters can be used interchangeably.
2599e49fc963SAndy Fiddaman.Pp
2600c10c16deSRichard LoweAn arithmetic expression uses the same syntax, precedence, and associativity of
2601e49fc963SAndy Fiddamanexpression as the C language.
2602e49fc963SAndy FiddamanAll the C language operators that apply to floating point quantities can be
2603e49fc963SAndy Fiddamanused.
2604e49fc963SAndy FiddamanIn addition, the operator
2605e49fc963SAndy Fiddaman.Sy **
2606e49fc963SAndy Fiddamancan be used for exponentiation.
2607e49fc963SAndy FiddamanIt has higher precedence than multiplication and is left associative.
2608e49fc963SAndy FiddamanWhen the value of an arithmetic variable or subexpression can be represented as
2609e49fc963SAndy Fiddamana long integer, all C language integer arithmetic operations can be performed.
2610e49fc963SAndy FiddamanVariables can be referenced by name within an arithmetic expression without
2611e49fc963SAndy Fiddamanusing the parameter expansion syntax.
2612e49fc963SAndy FiddamanWhen a variable is referenced, its value is evaluated as an arithmetic
2613e49fc963SAndy Fiddamanexpression.
2614e49fc963SAndy Fiddaman.Pp
2615c10c16deSRichard LoweAny of the following math library functions that are in the C math library can
2616c10c16deSRichard Lowebe used within an arithmetic expression:
2617e49fc963SAndy Fiddaman.Pp
2618e49fc963SAndy Fiddaman.Bl -inset -offset Ds -compact
2619e49fc963SAndy Fiddaman.It rint round sin sinh sqrt tan tanh tgamma trunc abs
2620e49fc963SAndy Fiddaman.It acos acosh asin asinh atan atan2 atanh cbrt ceil copysign
2621e49fc963SAndy Fiddaman.It cos cosh erf erfc exp exp2 expm1 fabs fpclassify fdim
2622e49fc963SAndy Fiddaman.It finite floor fma fmax fmin fmod hypot ilogb int isfinite
2623e49fc963SAndy Fiddaman.It sinf isnan isnormal issubnormal issubordered iszero j0
2624e49fc963SAndy Fiddaman.It j1 jn lgamma log log10 log2 logb nearbyint nextafter
2625e49fc963SAndy Fiddaman.It nexttoward pow remainder rint round scanb signbit sin sinh
2626e49fc963SAndy Fiddaman.It sqrt tan tanh tgamma trunc y0 y1 yn
2627e49fc963SAndy Fiddaman.El
2628e49fc963SAndy Fiddaman.Pp
2629b30d1939SAndy FiddamanIn addition, arithmetic functions can be defined as shell functions with a
2630e49fc963SAndy Fiddamanvariant of the
2631e49fc963SAndy Fiddaman.Ic function Ar name
2632e49fc963SAndy Fiddamansyntax:
2633e49fc963SAndy Fiddaman.Bd -ragged -offset Ds
2634e49fc963SAndy Fiddaman.Sy function .sh.math\&. Ns Ar name Ar ident Sy { Ar list Sy ;}
2635e49fc963SAndy Fiddaman.Ed
2636e49fc963SAndy Fiddaman.Pp
2637e49fc963SAndy Fiddamanwhere
2638e49fc963SAndy Fiddaman.Ar name
2639e49fc963SAndy Fiddamanis the function name used in the arithmetic expression and each identified
2640e49fc963SAndy Fiddaman.Ar ident
2641e49fc963SAndy Fiddamanis a name reference to the long double precision floating point argument.
2642e49fc963SAndy FiddamanThe value of
2643e49fc963SAndy Fiddaman.Sy .sh.value
2644e49fc963SAndy Fiddamanwhen the function returns is the value of this function.
2645e49fc963SAndy FiddamanUser defined functions can take up to 3 arguments and override C math library
2646e49fc963SAndy Fiddamanfunctions.
2647e49fc963SAndy Fiddaman.Pp
2648e49fc963SAndy FiddamanAn internal representation of a
2649e49fc963SAndy Fiddaman.Ar variable
2650e49fc963SAndy Fiddamanas a double precision floating point can be specified with the
2651e49fc963SAndy Fiddaman.Fl E Ns Op Ar n ,
2652e49fc963SAndy Fiddaman.Fl F Ns Op Ar n ,
2653e49fc963SAndy Fiddamanor
2654e49fc963SAndy Fiddaman.Fl X Ns Op Ar n
2655e49fc963SAndy Fiddamanoptions of the
2656e49fc963SAndy Fiddaman.Ic typeset
2657e49fc963SAndy Fiddamanspecial built-in command.
2658e49fc963SAndy FiddamanThe
2659e49fc963SAndy Fiddaman.Fl E
2660e49fc963SAndy Fiddamanoption causes the expansion of the value to be represented using scientific
2661e49fc963SAndy Fiddamannotation when it is expanded.
2662e49fc963SAndy FiddamanThe optional option argument
2663e49fc963SAndy Fiddaman.Ar n
2664e49fc963SAndy Fiddamandefines the number of significant figures.
2665e49fc963SAndy FiddamanThe
2666e49fc963SAndy Fiddaman.Fl F
2667e49fc963SAndy Fiddamanoption causes the expansion to be represented as a floating decimal number when
2668e49fc963SAndy Fiddamanit is expanded.
2669e49fc963SAndy FiddamanThe optional option argument
2670e49fc963SAndy Fiddaman.Ar n
2671e49fc963SAndy Fiddamandefines the number of places after the decimal point in this case.
2672e49fc963SAndy FiddamanThe
2673e49fc963SAndy Fiddaman.Fl X
2674e49fc963SAndy Fiddamanoption causes the expansion to be represented using the
2675e49fc963SAndy Fiddaman.Sy %a
2676e49fc963SAndy Fiddamanformat defined by ISO C-99.
2677e49fc963SAndy FiddamanThe optional option argument n defines the number of places after the decimal
2678e49fc963SAndy Fiddaman(or radix) point in this case.
2679e49fc963SAndy Fiddaman.Pp
2680e49fc963SAndy FiddamanAn internal integer representation of a
2681e49fc963SAndy Fiddaman.Ar variable
2682e49fc963SAndy Fiddamancan be specified with
2683e49fc963SAndy Fiddamanthe
2684e49fc963SAndy Fiddaman.Fl i Ns Op Ar n
2685e49fc963SAndy Fiddamanoption of the
2686e49fc963SAndy Fiddaman.Ic typeset
2687e49fc963SAndy Fiddamanspecial built-in command.
2688e49fc963SAndy FiddamanThe optional option argument
2689e49fc963SAndy Fiddaman.Ar n
2690e49fc963SAndy Fiddamanspecifies an arithmetic base to be used when expanding the variable.
2691e49fc963SAndy FiddamanIf you do not specify an arithmetic base, base 10 is used.
2692e49fc963SAndy Fiddaman.Pp
2693c10c16deSRichard LoweArithmetic evaluation is performed on the value of each assignment to a
2694e49fc963SAndy Fiddamanvariable with the
2695e49fc963SAndy Fiddaman.Fl E ,
2696e49fc963SAndy Fiddaman.Fl F ,
2697e49fc963SAndy Fiddaman.Fl X
2698e49fc963SAndy Fiddamanor
2699e49fc963SAndy Fiddaman.Fl i
2700e49fc963SAndy Fiddamanoption.
2701e49fc963SAndy FiddamanAssigning a floating point number to a variable whose type is an integer causes
2702e49fc963SAndy Fiddamanthe fractional part to be truncated.
2703e49fc963SAndy Fiddaman.Ss "Prompting"
2704e49fc963SAndy FiddamanWhen used interactively, the shell prompts with the value of
2705e49fc963SAndy Fiddaman.Ev PS1
2706e49fc963SAndy Fiddamanafter expanding it for parameter expansion, command substitution, and
2707e49fc963SAndy Fiddamanarithmetic substitution, before reading a command.
2708e49fc963SAndy FiddamanIn addition, each single
2709e49fc963SAndy Fiddaman.Sy \&!
2710e49fc963SAndy Fiddamanin the prompt is replaced by the command number.
2711e49fc963SAndy FiddamanA
2712e49fc963SAndy Fiddaman.Sy \&!\&!
2713e49fc963SAndy Fiddamanis required to place a literal
2714e49fc963SAndy Fiddaman.Sy \&!
2715e49fc963SAndy Fiddamanin the prompt.
2716e49fc963SAndy FiddamanIf at any time a NEWLINE is typed and further input is needed to complete a
2717e49fc963SAndy Fiddamancommand, then the secondary prompt, that is, the value of
2718e49fc963SAndy Fiddaman.Ev PS2 ,
2719e49fc963SAndy Fiddamanis issued.
2720e49fc963SAndy Fiddaman.Ss "Conditional Expressions"
2721e49fc963SAndy FiddamanA
2722e49fc963SAndy Fiddaman.Sy conditional expression
2723e49fc963SAndy Fiddamanis used with the
2724e49fc963SAndy Fiddaman.Sy [[
2725e49fc963SAndy Fiddamancompound command to test attributes of files and to compare strings.
2726e49fc963SAndy FiddamanField splitting and file name generation are not performed on the words between
2727e49fc963SAndy Fiddaman.Sy [[
2728e49fc963SAndy Fiddamanand
2729e49fc963SAndy Fiddaman.Sy ]] .
2730e49fc963SAndy Fiddaman.Pp
2731c10c16deSRichard LoweEach expression can be constructed from one or more of the following unary or
2732c10c16deSRichard Lowebinary expressions:
2733e49fc963SAndy Fiddaman.Bl -tag -width Ar
2734e49fc963SAndy Fiddaman.It Fl a Ar file
2735e49fc963SAndy FiddamanTrue, if
2736e49fc963SAndy Fiddaman.Ar file
2737e49fc963SAndy Fiddamanexists.
2738e49fc963SAndy Fiddaman.Pp
2739e49fc963SAndy FiddamanThis option is the same as
2740e49fc963SAndy Fiddaman.Fl e .
2741e49fc963SAndy FiddamanThis option is obsolete.
2742e49fc963SAndy Fiddaman.It Fl b Ar file
2743e49fc963SAndy FiddamanTrue, if
2744e49fc963SAndy Fiddaman.Ar file
2745e49fc963SAndy Fiddamanexists and is a block special file.
2746e49fc963SAndy Fiddaman.It Fl c Ar file
2747e49fc963SAndy FiddamanTrue, if
2748e49fc963SAndy Fiddaman.Ar file
2749e49fc963SAndy Fiddamanexists and is a character special file.
2750e49fc963SAndy Fiddaman.It Fl d Ar file
2751e49fc963SAndy FiddamanTrue, if
2752e49fc963SAndy Fiddaman.Ar file
2753e49fc963SAndy Fiddamanexists and is a directory.
2754e49fc963SAndy Fiddaman.It Fl e Ar file
2755e49fc963SAndy FiddamanTrue, if
2756e49fc963SAndy Fiddaman.Ar file
2757e49fc963SAndy Fiddamanexists.
2758e49fc963SAndy Fiddaman.It Fl f Ar file
2759e49fc963SAndy FiddamanTrue, if
2760e49fc963SAndy Fiddaman.Ar file
2761e49fc963SAndy Fiddamanexists and is an ordinary file.
2762e49fc963SAndy Fiddaman.It Fl g Ar file
2763e49fc963SAndy FiddamanTrue, if
2764e49fc963SAndy Fiddaman.Ar file
2765e49fc963SAndy Fiddamanexists and it has its
2766e49fc963SAndy Fiddaman.Sy setgid
2767e49fc963SAndy Fiddamanbit set.
2768e49fc963SAndy Fiddaman.It Fl G Ar file
2769e49fc963SAndy FiddamanTrue, if
2770e49fc963SAndy Fiddaman.Ar file
2771e49fc963SAndy Fiddamanexists and its group matches the effective group id of this process.
2772e49fc963SAndy Fiddaman.It Fl h Ar file
2773e49fc963SAndy FiddamanTrue, if
2774e49fc963SAndy Fiddaman.Ar file
2775e49fc963SAndy Fiddamanexists and is a symbolic link.
2776e49fc963SAndy Fiddaman.It Fl k Ar file
2777e49fc963SAndy FiddamanTrue, if
2778e49fc963SAndy Fiddaman.Ar file
2779e49fc963SAndy Fiddamanexists and it has its sticky bit set.
2780e49fc963SAndy Fiddaman.It Fl L Ar file
2781e49fc963SAndy FiddamanTrue, if
2782e49fc963SAndy Fiddaman.Ar file
2783e49fc963SAndy Fiddamanexists and is a symbolic link.
2784e49fc963SAndy Fiddaman.It Fl n Ar string
2785e49fc963SAndy FiddamanTrue, if length of
2786e49fc963SAndy Fiddaman.Ar string
2787e49fc963SAndy Fiddamanis
2788e49fc963SAndy Fiddaman.Sy non-zero .
2789e49fc963SAndy Fiddaman.It Fl N Ar file
2790e49fc963SAndy FiddamanTrue, if
2791e49fc963SAndy Fiddaman.Ar file
2792e49fc963SAndy Fiddamanexists and the modification time is greater than the last
2793c10c16deSRichard Loweaccess time.
2794e49fc963SAndy Fiddaman.It Fl o Ar option
2795e49fc963SAndy FiddamanTrue, if option named
2796e49fc963SAndy Fiddaman.Ar option
2797e49fc963SAndy Fiddamanis on.
2798e49fc963SAndy Fiddaman.It Fl o Sy \&? Ns Ar option
2799e49fc963SAndy FiddamanTrue, if option named
2800e49fc963SAndy Fiddaman.Ar option
2801e49fc963SAndy Fiddamanis a valid option name.
2802e49fc963SAndy Fiddaman.It Fl O Ar file
2803e49fc963SAndy FiddamanTrue, if
2804e49fc963SAndy Fiddaman.Ar file
2805e49fc963SAndy Fiddamanexists and is owned by the effective user id of this process.
2806e49fc963SAndy Fiddaman.It Fl p Ar file
2807e49fc963SAndy FiddamanTrue, if
2808e49fc963SAndy Fiddaman.Ar file
2809e49fc963SAndy Fiddamanexists and is a
2810e49fc963SAndy Fiddaman.Sy FIFO
2811e49fc963SAndy Fiddamanspecial file or a pipe.
2812e49fc963SAndy Fiddaman.It Fl r Ar file
2813e49fc963SAndy FiddamanTrue, if
2814e49fc963SAndy Fiddaman.Ar file
2815e49fc963SAndy Fiddamanexists and is readable by current process.
2816e49fc963SAndy Fiddaman.It Fl R Ar name
2817e49fc963SAndy FiddamanTrue if variable
2818e49fc963SAndy Fiddaman.Ar name
2819e49fc963SAndy Fiddamanis a name reference.
2820e49fc963SAndy Fiddaman.It Fl s Ar file
2821e49fc963SAndy FiddamanTrue, if
2822e49fc963SAndy Fiddaman.Ar file
2823e49fc963SAndy Fiddamanexists and has size greater than zero.
2824e49fc963SAndy Fiddaman.It Fl S Ar file
2825e49fc963SAndy FiddamanTrue, if
2826e49fc963SAndy Fiddaman.Ar file
2827e49fc963SAndy Fiddamanexists and is a socket.
2828e49fc963SAndy Fiddaman.It Fl t Ar fildes
2829e49fc963SAndy FiddamanTrue, if file descriptor number
2830e49fc963SAndy Fiddaman.Ar fildes
2831e49fc963SAndy Fiddamanis open and associated with a terminal device.
2832e49fc963SAndy Fiddaman.It Fl u Ar file
2833e49fc963SAndy FiddamanTrue, if
2834e49fc963SAndy Fiddaman.Ar file
2835e49fc963SAndy Fiddamanexists and it has its
2836e49fc963SAndy Fiddaman.Sy setuid
2837e49fc963SAndy Fiddamanbit set.
2838e49fc963SAndy Fiddaman.It Fl v Ar name
2839e49fc963SAndy FiddamanTrue, if variable
2840e49fc963SAndy Fiddaman.Ar name
2841e49fc963SAndy Fiddamanis a valid variable name and is set.
2842e49fc963SAndy Fiddaman.It Fl w Ar file
2843e49fc963SAndy FiddamanTrue, if
2844e49fc963SAndy Fiddaman.Ar file
2845e49fc963SAndy Fiddamanexists and is writable by current process.
2846e49fc963SAndy Fiddaman.It Fl x Ar file
2847e49fc963SAndy FiddamanTrue, if
2848e49fc963SAndy Fiddaman.Ar file
2849e49fc963SAndy Fiddamanexists and is executable by current process.
2850e49fc963SAndy FiddamanIf
2851e49fc963SAndy Fiddaman.Ar file
2852c10c16deSRichard Loweexists and is a directory, then true if the current process has permission to
2853c10c16deSRichard Lowesearch in the directory.
2854e49fc963SAndy Fiddaman.It Fl z Ar string
2855e49fc963SAndy FiddamanTrue, if length of
2856e49fc963SAndy Fiddaman.Ar string
2857e49fc963SAndy Fiddamanis zero.
2858e49fc963SAndy Fiddaman.It Ar file1 Fl ef Ar file2
2859e49fc963SAndy FiddamanTrue, if
2860e49fc963SAndy Fiddaman.Ar file1
2861e49fc963SAndy Fiddamanand
2862e49fc963SAndy Fiddaman.Ar file2
2863e49fc963SAndy Fiddamanexist and refer to the same file.
2864e49fc963SAndy Fiddaman.It Ar file1 Fl nt Ar file2
2865e49fc963SAndy FiddamanTrue, if
2866e49fc963SAndy Fiddaman.Ar file1
2867e49fc963SAndy Fiddamanexists and
2868e49fc963SAndy Fiddaman.Ar file2
2869e49fc963SAndy Fiddamandoes not, or
2870e49fc963SAndy Fiddaman.Ar file1
2871e49fc963SAndy Fiddamanis newer
2872e49fc963SAndy Fiddamanthan
2873e49fc963SAndy Fiddaman.Ar file2 .
2874e49fc963SAndy Fiddaman.It Ar file1 Fl ot Ar file2
2875e49fc963SAndy FiddamanTrue, if
2876e49fc963SAndy Fiddaman.Ar file2
2877e49fc963SAndy Fiddamanexists and
2878e49fc963SAndy Fiddaman.Ar file1
2879e49fc963SAndy Fiddamandoes not, or
2880e49fc963SAndy Fiddaman.Ar file1
2881e49fc963SAndy Fiddamanis older
2882e49fc963SAndy Fiddamanthan
2883e49fc963SAndy Fiddaman.Ar file2 .
2884e49fc963SAndy Fiddaman.It Ar string
2885e49fc963SAndy FiddamanTrue, if
2886e49fc963SAndy Fiddaman.Ar string
2887e49fc963SAndy Fiddamanis not null.
2888e49fc963SAndy Fiddaman.It Ar string Sy == Ar pattern
2889e49fc963SAndy FiddamanTrue, if
2890e49fc963SAndy Fiddaman.Ar string
2891e49fc963SAndy Fiddamanmatches
2892e49fc963SAndy Fiddaman.Ar pattern .
2893e49fc963SAndy FiddamanAny part of
2894e49fc963SAndy Fiddaman.Ar pattern
2895e49fc963SAndy Fiddamancan be quoted to cause it to be matched as a string.
2896e49fc963SAndy FiddamanWith a successful match to
2897e49fc963SAndy Fiddaman.Ar pattern , the
2898e49fc963SAndy Fiddaman.Ev \&.sh.match
2899e49fc963SAndy Fiddamanarray variable contains the match and sub-pattern matches.
2900e49fc963SAndy Fiddaman.It Ar string Sy = Ar pattern
2901e49fc963SAndy FiddamanSame as
2902e49fc963SAndy Fiddaman.Sy == ,
2903e49fc963SAndy Fiddamanbut is obsolete.
2904e49fc963SAndy Fiddaman.It Ar string Sy != Ar pattern
2905e49fc963SAndy FiddamanTrue, if
2906e49fc963SAndy Fiddaman.Ar string
2907e49fc963SAndy Fiddamandoes not match
2908e49fc963SAndy Fiddaman.Ar pattern .
2909e49fc963SAndy FiddamanWhen the
2910e49fc963SAndy Fiddaman.Ar string
2911e49fc963SAndy Fiddamanmatches the
2912e49fc963SAndy Fiddaman.Ar pattern
2913e49fc963SAndy Fiddamanthe
2914e49fc963SAndy Fiddaman.Ev \&.sh.match
2915e49fc963SAndy Fiddamanarray variable contains the match and sub-pattern matches.
2916e49fc963SAndy Fiddaman.It Ar string Sy =~ Ar ere
2917e49fc963SAndy FiddamanTrue if
2918e49fc963SAndy Fiddaman.Ar string
2919e49fc963SAndy Fiddamanmatches the pattern
2920e49fc963SAndy Fiddaman.Sy ~(E) Ns Ar ere
2921e49fc963SAndy Fiddamanwhere
2922e49fc963SAndy Fiddaman.Ar ere
2923e49fc963SAndy Fiddamanis an extended regular expression.
2924e49fc963SAndy Fiddaman.It Ar string1 Sy \&< Ar string2
2925e49fc963SAndy FiddamanTrue, if
2926e49fc963SAndy Fiddaman.Ar string1
2927e49fc963SAndy Fiddamancomes before
2928e49fc963SAndy Fiddaman.Ar string2
2929e49fc963SAndy Fiddamanbased on
2930e49fc963SAndy Fiddaman.Sy ASCII
2931e49fc963SAndy Fiddamanvalue of their characters.
2932e49fc963SAndy Fiddaman.It Ar string1 Sy \&> Ar string2
2933e49fc963SAndy FiddamanTrue, if
2934e49fc963SAndy Fiddaman.Ar string1
2935e49fc963SAndy Fiddamancomes after
2936e49fc963SAndy Fiddaman.Ar string2
2937e49fc963SAndy Fiddamanbased on
2938e49fc963SAndy Fiddaman.Sy ASCII
2939e49fc963SAndy Fiddamanvalue of
2940c10c16deSRichard Lowetheir characters.
2941e49fc963SAndy Fiddaman.El
2942e49fc963SAndy Fiddaman.Pp
2943e49fc963SAndy FiddamanIn each of the above expressions, if
2944e49fc963SAndy Fiddaman.Ar file
2945e49fc963SAndy Fiddamanis of the form
2946e49fc963SAndy Fiddaman.Pa /dev/fd/ Ns Ar n ,
2947e49fc963SAndy Fiddamanwhere
2948e49fc963SAndy Fiddaman.Ar n
2949e49fc963SAndy Fiddamanis an integer, the test is applied to the open file whose descriptor number is
2950e49fc963SAndy Fiddaman.Ar n .
2951e49fc963SAndy Fiddaman.Pp
2952b30d1939SAndy FiddamanThe following obsolete arithmetic comparisons are also supported:
2953e49fc963SAndy Fiddaman.Bl -tag -width 18n
2954e49fc963SAndy Fiddaman.It Ar exp1 Fl eq Ar exp2
2955e49fc963SAndy FiddamanTrue, if
2956e49fc963SAndy Fiddaman.Ar exp1
2957e49fc963SAndy Fiddamanis equal to
2958e49fc963SAndy Fiddaman.Ar exp2 .
2959e49fc963SAndy Fiddaman.It Ar exp1 Fl ge Ar exp2
2960e49fc963SAndy FiddamanTrue, if
2961e49fc963SAndy Fiddaman.Ar exp1
2962e49fc963SAndy Fiddamanis greater than or equal to
2963e49fc963SAndy Fiddaman.Ar exp2 .
2964e49fc963SAndy Fiddaman.It Ar exp1 Fl gt Ar exp2
2965e49fc963SAndy FiddamanTrue, if
2966e49fc963SAndy Fiddaman.Ar exp1
2967e49fc963SAndy Fiddamanis greater than
2968e49fc963SAndy Fiddaman.Ar exp2 .
2969e49fc963SAndy Fiddaman.It Ar exp1 Fl le Ar exp2
2970e49fc963SAndy FiddamanTrue, if
2971e49fc963SAndy Fiddaman.Ar exp1
2972e49fc963SAndy Fiddamanis less than or equal to
2973e49fc963SAndy Fiddaman.Ar exp2 .
2974e49fc963SAndy Fiddaman.It Ar exp1 Fl lt Ar exp2
2975e49fc963SAndy FiddamanTrue, if
2976e49fc963SAndy Fiddaman.Ar exp1
2977e49fc963SAndy Fiddamanis less than
2978e49fc963SAndy Fiddaman.Ar exp2 .
2979e49fc963SAndy Fiddaman.It Ar exp1 Fl ne Ar exp2
2980e49fc963SAndy FiddamanTrue, if
2981e49fc963SAndy Fiddaman.Ar exp1
2982e49fc963SAndy Fiddamanis not equal to
2983e49fc963SAndy Fiddaman.Ar exp2 .
2984e49fc963SAndy Fiddaman.El
2985e49fc963SAndy Fiddaman.Pp
2986c10c16deSRichard LoweA compound expression can be constructed from these primitives by using any of
2987c10c16deSRichard Lowethe following, listed in decreasing order of precedence:
2988e49fc963SAndy Fiddaman.Bl -tag -width Ds
2989e49fc963SAndy Fiddaman.It Sy \&( Ns Ar expression Ns Sy \&)
2990e49fc963SAndy FiddamanTrue, if
2991e49fc963SAndy Fiddaman.Ar expression
2992e49fc963SAndy Fiddamanis true.
2993e49fc963SAndy FiddamanUsed to group expressions.
2994e49fc963SAndy Fiddaman.It Sy \&! Ar expression
2995e49fc963SAndy FiddamanTrue, if
2996e49fc963SAndy Fiddaman.Ar expression
2997e49fc963SAndy Fiddamanis false.
2998e49fc963SAndy Fiddaman.It Ar expression1 Sy \&&& Ar expression2
2999e49fc963SAndy FiddamanTrue, if
3000e49fc963SAndy Fiddaman.Ar expression1
3001e49fc963SAndy Fiddamanand
3002e49fc963SAndy Fiddaman.Ar expression2
3003e49fc963SAndy Fiddamanare both true.
3004e49fc963SAndy Fiddaman.It Ar expression1 Sy \&|\&| Ar expression2
3005e49fc963SAndy FiddamanTrue, if either
3006e49fc963SAndy Fiddaman.Ar expression1
3007e49fc963SAndy Fiddamanor
3008e49fc963SAndy Fiddaman.Ar expression2
3009e49fc963SAndy Fiddamanis true.
3010e49fc963SAndy Fiddaman.El
3011e49fc963SAndy Fiddaman.Ss "Input and Output"
3012c10c16deSRichard LoweBefore a command is executed, its input and output can be redirected using a
3013e49fc963SAndy Fiddamanspecial notation interpreted by the shell.
3014e49fc963SAndy FiddamanThe following can appear anywhere in
3015e49fc963SAndy Fiddamana simple command or can precede or follow a command and are
3016e49fc963SAndy Fiddaman.Em not
3017e49fc963SAndy Fiddamanpassed on to the invoked command.
3018e49fc963SAndy FiddamanCommand substitution, parameter expansion, and arithmetic substitution occur
3019e49fc963SAndy Fiddamanbefore
3020e49fc963SAndy Fiddaman.Ar word
3021e49fc963SAndy Fiddamanor
3022e49fc963SAndy Fiddaman.Ar digit
3023e49fc963SAndy Fiddamanis used except as noted in this section.
3024e49fc963SAndy FiddamanFile name generation occurs only if the shell is interactive and the pattern
3025e49fc963SAndy Fiddamanmatches a single file.
3026e49fc963SAndy FiddamanField splitting is not performed.
3027e49fc963SAndy Fiddaman.Pp
3028e49fc963SAndy FiddamanIn each of the following redirections, if
3029e49fc963SAndy Fiddaman.Ar file
3030e49fc963SAndy Fiddamanis of the form
3031e49fc963SAndy Fiddaman.Pa /dev/sctp/ Ar host Ns Sy / Ns Ar port ,
3032e49fc963SAndy Fiddaman.Pa /dev/tcp/ Ar host Ns Sy / Ns Ar port ,
3033e49fc963SAndy Fiddamanor
3034e49fc963SAndy Fiddaman.Pa /dev/udp/ Ar host Ns Sy / Ns Ar port ,
3035e49fc963SAndy Fiddamanwhere
3036e49fc963SAndy Fiddaman.Ar host
3037e49fc963SAndy Fiddamanis a hostname or host address, and
3038e49fc963SAndy Fiddaman.Ar port
3039e49fc963SAndy Fiddamanis a service specified by name or an integer port number, then the redirection
3040e49fc963SAndy Fiddamanattempts to make a
3041e49fc963SAndy Fiddaman.Sy tcp ,
3042e49fc963SAndy Fiddaman.Sy sctp
3043e49fc963SAndy Fiddamanor
3044e49fc963SAndy Fiddaman.Sy udp
3045e49fc963SAndy Fiddamanconnection to the corresponding socket.
3046e49fc963SAndy Fiddaman.Pp
3047c10c16deSRichard LoweNo intervening space is allowed between the characters of redirection
3048c10c16deSRichard Loweoperators.
3049e49fc963SAndy Fiddaman.Bl -tag -width Ar
3050e49fc963SAndy Fiddaman.It Sy \&< Ns Ar word
3051e49fc963SAndy FiddamanUse file
3052e49fc963SAndy Fiddaman.Ar word
3053e49fc963SAndy Fiddamanas standard input (file descriptor 0).
3054e49fc963SAndy Fiddaman.It Sy \&> Ns Ar word
3055e49fc963SAndy FiddamanUse file
3056e49fc963SAndy Fiddaman.Ar word
3057e49fc963SAndy Fiddamanas standard output (file descriptor 1).
3058e49fc963SAndy FiddamanIf the file does not exist then it is created.
3059e49fc963SAndy FiddamanIf the file exists, and the
3060e49fc963SAndy Fiddaman.Sy noclobber
3061e49fc963SAndy Fiddamanoption is on, this causes an error, otherwise, it is truncated to zero length.
3062e49fc963SAndy Fiddaman.It Sy \&>\&| Ns Ar word
3063e49fc963SAndy FiddamanSame as
3064e49fc963SAndy Fiddaman.Sy > ,
3065e49fc963SAndy Fiddamanexcept that it overrides the
3066e49fc963SAndy Fiddaman.Sy noclobber
3067e49fc963SAndy Fiddamanoption.
3068e49fc963SAndy Fiddaman.It Sy \&>\&; Ns Ar word
3069e49fc963SAndy FiddamanWrite output to a temporary file.
3070e49fc963SAndy FiddamanIf the command completes successfully rename it to word, otherwise, delete the
3071e49fc963SAndy Fiddamantemporary file.
3072e49fc963SAndy Fiddaman>;word cannot be used with the
3073e49fc963SAndy Fiddaman.Xr exec 2
3074e49fc963SAndy Fiddamanbuilt-in.
3075e49fc963SAndy Fiddaman.It Sy \&>> Ns Ar word
3076e49fc963SAndy FiddamanUse file
3077e49fc963SAndy Fiddaman.Ar word
3078e49fc963SAndy Fiddamanas standard output.
3079e49fc963SAndy FiddamanIf the file exists, then output is appended to it (by first seeking to the
3080e49fc963SAndy Fiddamanend-of-file), otherwise, the file is created.
3081e49fc963SAndy Fiddaman.It Sy \&<> Ns Ar word
3082e49fc963SAndy FiddamanOpen file
3083e49fc963SAndy Fiddaman.Ar word
3084e49fc963SAndy Fiddamanfor reading and writing as standard input.
3085e49fc963SAndy Fiddaman.It Sy \&<< Ns Oo Fl Oc Ns Ar word
3086e49fc963SAndy FiddamanThe shell input is read up to a line that is the same as
3087e49fc963SAndy Fiddaman.Ar word
3088e49fc963SAndy Fiddamanafter any quoting has been removed, or to an end-of-file.
3089e49fc963SAndy FiddamanNo parameter substitution, command substitution, arithmetic substitution or
3090e49fc963SAndy Fiddamanfile name generation is performed on
3091e49fc963SAndy Fiddaman.Ar word .
3092e49fc963SAndy FiddamanThe resulting document, called a
3093e49fc963SAndy Fiddaman.Sy here-document ,
3094e49fc963SAndy Fiddamanbecomes the standard input.
3095e49fc963SAndy FiddamanIf any character of
3096e49fc963SAndy Fiddaman.Ar word
3097e49fc963SAndy Fiddamanis quoted, then no interpretation is placed upon the characters of the
3098e49fc963SAndy Fiddamandocument.
3099e49fc963SAndy FiddamanOtherwise, parameter expansion, command substitution, and arithmetic
3100e49fc963SAndy Fiddamansubstitution occur,
3101e49fc963SAndy Fiddaman\eNEWLINE is ignored, and \e must be used to quote the characters
3102e49fc963SAndy Fiddaman.Sy \e ,
3103e49fc963SAndy Fiddaman.Sy $
3104e49fc963SAndy Fiddamanand
3105e49fc963SAndy Fiddaman.Sy \&` .
3106e49fc963SAndy FiddamanIf
3107e49fc963SAndy Fiddaman.Sy -
3108e49fc963SAndy Fiddamanis appended to
3109e49fc963SAndy Fiddaman.Sy << ,
3110e49fc963SAndy Fiddamanthen all
3111e49fc963SAndy Fiddamanleading tabs are stripped from
3112e49fc963SAndy Fiddaman.Ar word
3113e49fc963SAndy Fiddamanand from the document.
3114e49fc963SAndy FiddamanIf
3115e49fc963SAndy Fiddaman.Sy #
3116e49fc963SAndy Fiddamanis
3117e49fc963SAndy Fiddamanappended to
3118e49fc963SAndy Fiddaman.Sy << ,
3119e49fc963SAndy Fiddamanthen leading SPACEs and TABs are stripped off the first line of the document
3120e49fc963SAndy Fiddamanand up to an equivalent indentation is stripped from the remaining lines and
3121e49fc963SAndy Fiddamanfrom
3122e49fc963SAndy Fiddaman.Ar word .
3123e49fc963SAndy FiddamanA tab stop is assumed to occur at every 8 columns for the purposes of
3124e49fc963SAndy Fiddamandetermining the indentation.
3125e49fc963SAndy Fiddaman.It Sy \&<<< Ns Ar word
3126e49fc963SAndy FiddamanA short form of here document in which
3127e49fc963SAndy Fiddaman.Ar word
3128e49fc963SAndy Fiddamanbecomes the contents of the here-document after any parameter expansion,
3129e49fc963SAndy Fiddamancommand substitution, and arithmetic substitution occur.
3130e49fc963SAndy Fiddaman.It Sy \&<& Ns Ar digit
3131e49fc963SAndy FiddamanThe standard input is duplicated from file descriptor
3132e49fc963SAndy Fiddaman.Ar digit ,
3133e49fc963SAndy Fiddamanand similarly for the standard output using
3134e49fc963SAndy Fiddaman.Sy >&
3135e49fc963SAndy Fiddaman.Ar digit .
3136e49fc963SAndy FiddamanSee
3137e49fc963SAndy Fiddaman.Xr dup 2 .
3138e49fc963SAndy Fiddaman.It Sy \&<& Ns Ar digit Ns Sy -
3139e49fc963SAndy FiddamanThe file descriptor specified by
3140e49fc963SAndy Fiddaman.Ar digit
3141e49fc963SAndy Fiddamanis moved to standard input.
3142e49fc963SAndy FiddamanSimilarly for the standard output using
3143e49fc963SAndy Fiddaman.Sy >& Ns Ar digit Ns Sy - .
3144e49fc963SAndy Fiddaman.It Sy <&-
3145e49fc963SAndy FiddamanThe standard input is closed.
3146e49fc963SAndy FiddamanSimilarly for the standard output using
3147e49fc963SAndy Fiddaman.Sy >&- .
3148e49fc963SAndy Fiddaman.It Sy <&p
3149c10c16deSRichard LoweThe input from the co-process is moved to standard input.
3150e49fc963SAndy Fiddaman.It Sy >&p
3151c10c16deSRichard LoweThe output to the co-process is moved to standard output.
3152e49fc963SAndy Fiddaman.It Sy <#(( Ns Ar expr Ns Sy ))
3153e49fc963SAndy FiddamanEvaluate arithmetic expression
3154e49fc963SAndy Fiddaman.Ar expr
3155e49fc963SAndy Fiddamanand position file descriptor 0 to the resulting value bytes from the start of
3156e49fc963SAndy Fiddamanthe file.
3157e49fc963SAndy FiddamanThe variables
3158e49fc963SAndy Fiddaman.Ev CUR
3159e49fc963SAndy Fiddamanand
3160e49fc963SAndy Fiddaman.Ev EOF
3161e49fc963SAndy Fiddamanevaluate to the current offset and end-of-file offset respectively when
3162e49fc963SAndy Fiddamanevaluating
3163e49fc963SAndy Fiddaman.Ar expr .
3164e49fc963SAndy Fiddaman.It Sy >#(( Ns Ar expr Ns Sy ))
3165e49fc963SAndy FiddamanThe same as
3166e49fc963SAndy Fiddaman.Sy <#
3167e49fc963SAndy Fiddamanexcept applies to file descriptor 1.
3168e49fc963SAndy Fiddaman.It Sy <# Ns Ar pattern
3169c10c16deSRichard LoweSeek forward to the beginning of the next line containing pattern.
3170e49fc963SAndy Fiddaman.It Sy <## Ns Ar pattern
3171e49fc963SAndy FiddamanThe same as
3172e49fc963SAndy Fiddaman.Sy <# ,
3173e49fc963SAndy Fiddamanexcept that the portion of the file that is skipped is copied to standard
3174e49fc963SAndy Fiddamanoutput.
3175e49fc963SAndy Fiddaman.El
3176e49fc963SAndy Fiddaman.Pp
3177c10c16deSRichard LoweIf one of the redirection operators is preceded by a digit, with no intervening
3178c10c16deSRichard Lowespace, then the file descriptor number referred to is that specified by the
3179e49fc963SAndy Fiddamandigit (instead of the default 0 or 1).
3180e49fc963SAndy FiddamanIf one of the redirection operators
3181e49fc963SAndy Fiddamanother than
3182e49fc963SAndy Fiddaman.Sy >&-
3183e49fc963SAndy Fiddamanand the
3184e49fc963SAndy Fiddaman.Sy >#
3185e49fc963SAndy Fiddamanand
3186e49fc963SAndy Fiddaman.Sy <#
3187e49fc963SAndy Fiddamanforms, is preceded by
3188e49fc963SAndy Fiddaman.Sy \&{ Ns Ar varname Ns Sy \&}
3189e49fc963SAndy Fiddamanwith no intervening space, then a file descriptor
3190e49fc963SAndy Fiddamannumber
3191e49fc963SAndy Fiddaman.Sy > 10
3192e49fc963SAndy Fiddamanis selected by the shell and stored in the variable
3193e49fc963SAndy Fiddaman.Ar varname .
3194e49fc963SAndy FiddamanIf
3195e49fc963SAndy Fiddaman.Sy >&-
3196e49fc963SAndy Fiddamanor the any of the
3197e49fc963SAndy Fiddaman.Sy >#
3198e49fc963SAndy Fiddamanand
3199e49fc963SAndy Fiddaman.Sy <#
3200e49fc963SAndy Fiddamanforms is preceded by
3201e49fc963SAndy Fiddaman.Sy \&{ Ns Ar varname Ns Sy \&}
3202e49fc963SAndy Fiddamanthe value of
3203e49fc963SAndy Fiddaman.Ar varname
3204e49fc963SAndy Fiddamandefines the file descriptor to close or position.
3205e49fc963SAndy FiddamanFor example:
3206e49fc963SAndy Fiddaman.Pp
3207e49fc963SAndy Fiddaman.Dl ... 2>&1
3208e49fc963SAndy Fiddaman.Pp
3209c10c16deSRichard Lowemeans file descriptor 2 is to be opened for writing as a duplicate of file
3210c10c16deSRichard Lowedescriptor 1 and
3211e49fc963SAndy Fiddaman.Pp
3212e49fc963SAndy Fiddaman.Dl exec [n]<file
3213e49fc963SAndy Fiddaman.Pp
3214e49fc963SAndy Fiddamanmeans open
3215e49fc963SAndy Fiddaman.Ar file
3216e49fc963SAndy Fiddamanfor reading and store the file descriptor number in variable
3217e49fc963SAndy Fiddaman.Ar n .
3218e49fc963SAndy FiddamanThe order in which redirections are specified is significant.
3219e49fc963SAndy FiddamanThe shell evaluates each redirection in terms of the
3220e49fc963SAndy Fiddaman.Pq Ar file_descriptor , Ar file
3221e49fc963SAndy Fiddamanassociation at the time of evaluation.
3222e49fc963SAndy FiddamanFor example:
3223e49fc963SAndy Fiddaman.Pp
3224e49fc963SAndy Fiddaman.Dl ... 1>fname 2>&1
3225e49fc963SAndy Fiddaman.Pp
3226e49fc963SAndy Fiddamanfirst associates file descriptor 1 with file
3227e49fc963SAndy Fiddaman.Ar fname .
3228e49fc963SAndy FiddamanIt then associates file descriptor 2 with the file associated with file
3229e49fc963SAndy Fiddamandescriptor 1, that is,
3230e49fc963SAndy Fiddaman.Ar fname .
3231e49fc963SAndy FiddamanIf the order of redirections were reversed, file descriptor 2 would be
3232e49fc963SAndy Fiddamanassociated with the terminal (assuming file descriptor 1 had been) and then
3233e49fc963SAndy Fiddamanfile descriptor 1 would be associated with file
3234e49fc963SAndy Fiddaman.Ar fname .
3235e49fc963SAndy FiddamanIf a command is followed by
3236e49fc963SAndy Fiddaman.Sy \&&
3237e49fc963SAndy Fiddamanand job control is not active, the default standard input for the command is
3238e49fc963SAndy Fiddamanthe empty file
3239e49fc963SAndy Fiddaman.Pa /dev/null .
3240e49fc963SAndy FiddamanOtherwise, the environment for the execution of a command contains the file
3241e49fc963SAndy Fiddamandescriptors of the invoking shell as modified by input and output
3242e49fc963SAndy Fiddamanspecifications.
3243e49fc963SAndy Fiddaman.Ss "Environment"
3244e49fc963SAndy FiddamanThe
3245e49fc963SAndy Fiddaman.Sy environment
3246e49fc963SAndy Fiddamanis a list of name-value pairs that is passed to an executed program in the same
3247e49fc963SAndy Fiddamanway as a normal argument list.
3248e49fc963SAndy FiddamanSee
3249*bbf21555SRichard Lowe.Xr environ 7 .
3250e49fc963SAndy Fiddaman.Pp
3251e49fc963SAndy FiddamanThe names must be
3252e49fc963SAndy Fiddaman.Ar identifiers
3253e49fc963SAndy Fiddamanand the values are character strings.
3254e49fc963SAndy FiddamanThe shell interacts with the environment in several ways.
3255e49fc963SAndy FiddamanOn invocation, the shell scans the environment and creates a variable for each
3256e49fc963SAndy Fiddamanname found, giving it the corresponding value and attributes and marking it
3257e49fc963SAndy Fiddaman.Ic export .
3258e49fc963SAndy FiddamanExecuted commands inherit the environment.
3259e49fc963SAndy FiddamanIf the user modifies the values of these variables or creates new ones, using
3260e49fc963SAndy Fiddamanthe
3261e49fc963SAndy Fiddaman.Ic export
3262e49fc963SAndy Fiddamanor
3263e49fc963SAndy Fiddaman.Ic typeset Fl x
3264e49fc963SAndy Fiddamancommands, they become part of the environment.
3265e49fc963SAndy FiddamanThe environment seen by any executed command is thus composed of any name-value
3266e49fc963SAndy Fiddamanpairs originally inherited by the shell, whose values can be modified by the
3267e49fc963SAndy Fiddamancurrent shell, plus any additions which must be noted in
3268e49fc963SAndy Fiddaman.Ic export
3269e49fc963SAndy Fiddamanor
3270e49fc963SAndy Fiddaman.Ic typeset Fl x
3271e49fc963SAndy Fiddamancommands.
3272e49fc963SAndy FiddamanThe environment for any simple-command or function can be augmented by
3273e49fc963SAndy Fiddamanprefixing it with one or more variable assignments.
3274e49fc963SAndy FiddamanA variable assignment argument is a word of the form
3275e49fc963SAndy Fiddaman.Ar identifier Ns Sy = Ns Ar value .
3276e49fc963SAndy FiddamanThus:
3277e49fc963SAndy Fiddaman.Pp
3278e49fc963SAndy Fiddaman.Dl TERM=450 cmd args
3279e49fc963SAndy Fiddaman.Pp
3280c10c16deSRichard Loweand
3281e49fc963SAndy Fiddaman.Pp
3282e49fc963SAndy Fiddaman.Dl (export TERM; TERM=450; cmd args)
3283e49fc963SAndy Fiddaman.Pp
3284e49fc963SAndy Fiddamanare equivalent
3285e49fc963SAndy Fiddaman.Pq as far as the execution of Ar cmd No is concerned
3286e49fc963SAndy Fiddamanexcept for special built-in commands listed in the
3287e49fc963SAndy Fiddaman.Sx Built-Ins
3288e49fc963SAndy Fiddamansection, those that are preceded with a dagger.
3289e49fc963SAndy FiddamanIf the obsolete
3290e49fc963SAndy Fiddaman.Fl k
3291e49fc963SAndy Fiddamanoption is set, all variable assignment arguments are placed in the environment,
3292e49fc963SAndy Fiddamaneven if they occur after the command name.
3293e49fc963SAndy Fiddaman.Pp
3294e49fc963SAndy FiddamanThe following example first prints
3295e49fc963SAndy Fiddaman.Sy a=b c
3296e49fc963SAndy Fiddamanand then
3297e49fc963SAndy Fiddaman.Sy c :
3298e49fc963SAndy Fiddaman.Bd -literal -offset indent
3299c10c16deSRichard Loweecho a=b c
3300c10c16deSRichard Loweset -k
3301c10c16deSRichard Loweecho a=b c
3302e49fc963SAndy Fiddaman.Ed
3303e49fc963SAndy Fiddaman.Pp
3304c10c16deSRichard LoweThis feature is intended for use with scripts written for early versions of the
3305c10c16deSRichard Loweshell and its use in new scripts is strongly discouraged.
3306e49fc963SAndy Fiddaman.Ss "Functions"
3307c10c16deSRichard LoweFor historical reasons, there are two ways to define functions, the
3308e49fc963SAndy Fiddaman.Ar name Ns Sy ()
3309e49fc963SAndy Fiddamansyntax and the
3310e49fc963SAndy Fiddaman.Ic function Ar name
3311e49fc963SAndy Fiddamansyntax.
3312e49fc963SAndy FiddamanThese are
3313e49fc963SAndy Fiddamandescribed in the
3314e49fc963SAndy Fiddaman.Sx Commands
3315e49fc963SAndy Fiddamansection of this manual page.
3316e49fc963SAndy Fiddaman.Pp
3317e49fc963SAndy FiddamanShell functions are read in and stored internally.
3318e49fc963SAndy FiddamanAlias names are resolved when the function is read.
3319e49fc963SAndy FiddamanFunctions are executed like commands with the arguments passed as positional
3320e49fc963SAndy Fiddamanparameters.
3321e49fc963SAndy FiddamanSee the
3322e49fc963SAndy Fiddaman.Sx Execution
3323e49fc963SAndy Fiddamansection of this manual page for details.
3324e49fc963SAndy Fiddaman.Pp
3325e49fc963SAndy FiddamanFunctions defined by the
3326e49fc963SAndy Fiddaman.Ic function Ar name
3327e49fc963SAndy Fiddamansyntax and called by name execute in the same process as the caller and share
3328e49fc963SAndy Fiddamanall files and present working directory with the caller.
3329e49fc963SAndy FiddamanTraps caught by the caller are reset to their default action inside the
3330e49fc963SAndy Fiddamanfunction.
3331e49fc963SAndy FiddamanA trap condition that is not caught or ignored by the function causes the
3332e49fc963SAndy Fiddamanfunction to terminate and the condition to be passed on to the caller.
3333e49fc963SAndy FiddamanA trap on
3334e49fc963SAndy Fiddaman.Sy EXIT
3335e49fc963SAndy Fiddamanset inside a function is executed in the environment of the caller after the
3336e49fc963SAndy Fiddamanfunction completes.
3337c10c16deSRichard LoweOrdinarily, variables are shared between the calling program and the function.
3338e49fc963SAndy FiddamanHowever, the
3339e49fc963SAndy Fiddaman.Ic typeset
3340e49fc963SAndy Fiddamanspecial built-in command used within a function defines local variables whose
3341e49fc963SAndy Fiddamanscope includes the current function.
3342e49fc963SAndy FiddamanThey can be passed to functions that they call in the variable assignment list
3343e49fc963SAndy Fiddamanthat precedes the call or as arguments passed as name references.
3344e49fc963SAndy FiddamanErrors within functions return control to the caller.
3345e49fc963SAndy Fiddaman.Pp
3346e49fc963SAndy FiddamanFunctions defined with the
3347e49fc963SAndy Fiddaman.Ar name Ns Sy ()
3348e49fc963SAndy Fiddamansyntax and functions defined with the
3349e49fc963SAndy Fiddaman.Ic function Ar name
3350e49fc963SAndy Fiddamansyntax that are invoked with the
3351e49fc963SAndy Fiddaman.Ic \&.
3352e49fc963SAndy Fiddamanspecial built-in are executed in the caller's environment and share all
3353e49fc963SAndy Fiddamanvariables and traps with the caller.
3354e49fc963SAndy FiddamanErrors within these function executions cause the script that contains them to
3355e49fc963SAndy Fiddamanabort.
3356e49fc963SAndy Fiddaman.Pp
3357e49fc963SAndy FiddamanThe special built-in command
3358e49fc963SAndy Fiddaman.Ic return
3359e49fc963SAndy Fiddamanis used to return from function calls.
3360e49fc963SAndy Fiddaman.Pp
3361e49fc963SAndy FiddamanFunction names can be listed with the
3362e49fc963SAndy Fiddaman.Fl f
3363e49fc963SAndy Fiddamanor
3364e49fc963SAndy Fiddaman.Sy +f
3365e49fc963SAndy Fiddamanoption of the
3366e49fc963SAndy Fiddaman.Ic typeset
3367e49fc963SAndy Fiddamanspecial built-in command.
3368e49fc963SAndy FiddamanThe text of functions, when available, is also listed with
3369e49fc963SAndy Fiddaman.Fl f .
3370e49fc963SAndy FiddamanFunctions can be undefined with the
3371e49fc963SAndy Fiddaman.Fl f
3372e49fc963SAndy Fiddamanoption of the
3373e49fc963SAndy Fiddaman.Ic unset
3374e49fc963SAndy Fiddamanspecial built-in command.
3375e49fc963SAndy Fiddaman.Pp
3376c10c16deSRichard LoweOrdinarily, functions are unset when the shell executes a shell script.
3377c10c16deSRichard LoweFunctions that need to be defined across separate invocations of the shell
3378e49fc963SAndy Fiddamanshould be placed in a directory and the
3379e49fc963SAndy Fiddaman.Ev FPATH
3380e49fc963SAndy Fiddamanvariable should contain the
3381e49fc963SAndy Fiddamanname of this directory.
3382e49fc963SAndy FiddamanThey can also be specified in the
3383e49fc963SAndy Fiddaman.Ev ENV
3384e49fc963SAndy Fiddamanfile.
3385e49fc963SAndy Fiddaman.Ss "Discipline Functions"
3386c10c16deSRichard LoweEach variable can have zero or more discipline functions associated with it.
3387e49fc963SAndy FiddamanThe shell initially understands the discipline names
3388e49fc963SAndy Fiddaman.Ic get ,
3389e49fc963SAndy Fiddaman.Ic set ,
3390e49fc963SAndy Fiddaman.Ic append ,
3391e49fc963SAndy Fiddamanand
3392e49fc963SAndy Fiddaman.Ic unset
3393e49fc963SAndy Fiddamanbut on most systems others can be added at run time via the C programming
3394e49fc963SAndy Fiddamaninterface extension provided by the
3395e49fc963SAndy Fiddaman.Ic builtin
3396e49fc963SAndy Fiddamanbuilt-in utility.
3397e49fc963SAndy FiddamanIf the
3398e49fc963SAndy Fiddaman.Ic get
3399e49fc963SAndy Fiddamandiscipline is defined for a variable, it is invoked whenever the specified
3400e49fc963SAndy Fiddamanvariable is referenced.
3401e49fc963SAndy FiddamanIf the variable
3402e49fc963SAndy Fiddaman.Sy \&.sh.value
3403e49fc963SAndy Fiddamanis assigned a value inside the discipline function, the referenced variable is
3404e49fc963SAndy Fiddamanevaluated to this value instead.
3405e49fc963SAndy FiddamanIf the
3406e49fc963SAndy Fiddaman.Ic set
3407c10c16deSRichard Lowediscipline is defined for a variable, it is invoked whenever the specified
3408e49fc963SAndy Fiddamanvariable is assigned a value.
3409e49fc963SAndy FiddamanIf the
3410e49fc963SAndy Fiddaman.Ic append
3411e49fc963SAndy Fiddamandiscipline is defined for a variable, it is invoked whenever a value is
3412e49fc963SAndy Fiddamanappended to the specified variable.
3413e49fc963SAndy FiddamanThe variable
3414e49fc963SAndy Fiddaman.Sy \&.sh.value
3415e49fc963SAndy Fiddamanis specified the value of the variable before invoking the discipline, and the
3416e49fc963SAndy Fiddamanvariable is assigned the value of
3417e49fc963SAndy Fiddaman.Sy \&.sh.value
3418e49fc963SAndy Fiddamanafter the discipline completes.
3419e49fc963SAndy FiddamanIf
3420e49fc963SAndy Fiddaman.Sy .sh.value
3421e49fc963SAndy Fiddamanis
3422e49fc963SAndy Fiddaman.Ic unset
3423e49fc963SAndy Fiddamaninside the discipline, then that value is unchanged.
3424e49fc963SAndy FiddamanIf the
3425e49fc963SAndy Fiddaman.Ic unset
3426e49fc963SAndy Fiddamandiscipline is defined for a variable, it is invoked whenever the specified
3427e49fc963SAndy Fiddamanvariable is unset.
3428e49fc963SAndy FiddamanThe variable is not unset unless it is unset explicitly from within this
3429e49fc963SAndy Fiddamandiscipline function.
3430e49fc963SAndy Fiddaman.Pp
3431e49fc963SAndy FiddamanThe variable
3432e49fc963SAndy Fiddaman.Sy \&.sh.name
3433e49fc963SAndy Fiddamancontains the name of the variable for which the discipline function is called,
3434e49fc963SAndy Fiddaman.Sy \&.sh.subscript
3435e49fc963SAndy Fiddamanis the subscript of the variable, and
3436e49fc963SAndy Fiddaman.Sy \&.sh.value
3437e49fc963SAndy Fiddamancontains the value being assigned inside the
3438e49fc963SAndy Fiddaman.Ic set
3439e49fc963SAndy Fiddamandiscipline function.
3440e49fc963SAndy FiddamanFor the
3441e49fc963SAndy Fiddaman.Sy set
3442e49fc963SAndy Fiddamandiscipline, changing
3443e49fc963SAndy Fiddaman.Sy \&.sh.value
3444e49fc963SAndy Fiddamanchanges the value that gets assigned.
3445e49fc963SAndy FiddamanThe variable
3446e49fc963SAndy Fiddaman.Sy _
3447e49fc963SAndy Fiddamanis a reference to the variable including the subscript if any.
3448e49fc963SAndy FiddamanFor the
3449e49fc963SAndy Fiddaman.Ic set
3450e49fc963SAndy Fiddamandiscipline, changing
3451e49fc963SAndy Fiddaman.Sy \&.sh.value
3452e49fc963SAndy Fiddamanwill change the value that gets assigned.
3453e49fc963SAndy FiddamanFinally, the expansion
3454e49fc963SAndy Fiddaman.Sy ${ Ns Ar var.name Ns Sy } ,
3455b30d1939SAndy Fiddamanwhen name is the name of a discipline, and there is no variable of this name,
3456e49fc963SAndy Fiddamanis equivalent to the command substitution
3457e49fc963SAndy Fiddaman.Sy ${ Ns Ar var.name Ns Sy ;} .
3458e49fc963SAndy Fiddaman.Ss "Name Spaces"
3459e49fc963SAndy FiddamanCommands and functions that are executed as part of the
3460e49fc963SAndy Fiddaman.Ar list
3461e49fc963SAndy Fiddamanof a
3462e49fc963SAndy Fiddaman.Ic namespace
3463e49fc963SAndy Fiddamancommand that modify variables or create new ones, create a new variable whose
3464e49fc963SAndy Fiddamanname is the name of the name space as given by
3465e49fc963SAndy Fiddaman.Ar identifier
3466e49fc963SAndy Fiddamanpreceded by two dots
3467e49fc963SAndy Fiddaman.Pq Sy \&.. .
3468e49fc963SAndy FiddamanWhen a variable whose name is
3469e49fc963SAndy Fiddaman.Ar name
3470e49fc963SAndy Fiddamanis referenced, it is first searched for using
3471e49fc963SAndy Fiddaman.Sy \&. Ns Ar identifier Ns Sy \&. Ns Ar name Ns Sy \&.
3472e49fc963SAndy FiddamanSimilarly, a function defined by a command in the
3473e49fc963SAndy Fiddaman.Ic namespace Ar list
3474e49fc963SAndy Fiddamanis created using the name space name preceded by two dots
3475e49fc963SAndy Fiddaman.Pq Sy \&.. .
3476e49fc963SAndy Fiddaman.Pp
3477e49fc963SAndy FiddamanWhen  the
3478e49fc963SAndy Fiddaman.Ar list
3479e49fc963SAndy Fiddamanof a
3480e49fc963SAndy Fiddaman.Ic namespace
3481e49fc963SAndy Fiddamancommand contains a
3482e49fc963SAndy Fiddaman.Ic namespace
3483b30d1939SAndy Fiddamancommand, the names of variables and functions that are created consist
3484e49fc963SAndy Fiddamanof the variable or function name preceded by the list of
3485e49fc963SAndy Fiddaman.Ar identifier Ns No s ,
3486e49fc963SAndy Fiddamaneach preceded by two dots
3487e49fc963SAndy Fiddaman.Pq Sy \&.. .
3488e49fc963SAndy Fiddaman.Pp
3489e49fc963SAndy FiddamanOutside of a name space, a variable or function created inside a name space can
3490e49fc963SAndy Fiddamanbe referenced by preceding it with the name space name.
3491e49fc963SAndy Fiddaman.Pp
3492e49fc963SAndy FiddamanBy default, variables staring with
3493e49fc963SAndy Fiddaman.Sy \&.sh
3494e49fc963SAndy Fiddamanare in the
3495e49fc963SAndy Fiddaman.Sy sh
3496e49fc963SAndy Fiddamanname space.
3497e49fc963SAndy Fiddaman.Ss "Typed Variables"
3498e49fc963SAndy FiddamanTyped variables provide a way to create data structure and objects.
3499e49fc963SAndy FiddamanA type can be defined either by a shared library, by the
3500e49fc963SAndy Fiddaman.Ic enum
3501e49fc963SAndy Fiddamanbuilt-in command described below, or by using the
3502e49fc963SAndy Fiddaman.Fl T
3503e49fc963SAndy Fiddamanoption of the
3504e49fc963SAndy Fiddaman.Ic typeset
3505e49fc963SAndy Fiddamanbuilt-in command.
3506e49fc963SAndy FiddamanWith the
3507e49fc963SAndy Fiddaman.Fl T
3508e49fc963SAndy Fiddamanoption of
3509e49fc963SAndy Fiddaman.Ic typeset ,
3510e49fc963SAndy Fiddamanthe type name, specified as an option argument to
3511e49fc963SAndy Fiddaman.Fl T ,
3512e49fc963SAndy Fiddamanis set with a compound variable assignment that defines the type.
3513e49fc963SAndy FiddamanFunction definitions can appear inside the compound variable assignment and
3514e49fc963SAndy Fiddamanthese become discipline functions for this type and can be invoked or redefined
3515e49fc963SAndy Fiddamanby each instance of the type.
3516e49fc963SAndy FiddamanThe function name
3517e49fc963SAndy Fiddaman.Sy create
3518e49fc963SAndy Fiddamanis treated specially.
3519e49fc963SAndy FiddamanIt is invoked for each instance of the type that is created but is not
3520e49fc963SAndy Fiddamaninherited and cannot be redefined for each instance.
3521e49fc963SAndy Fiddaman.Pp
3522e49fc963SAndy FiddamanWhen a type is defined a special built-in command of that name is added.
3523e49fc963SAndy FiddamanThese built-ins are declaration commands and follow the same expansion rules as
3524e49fc963SAndy Fiddamanall the special built-in commands defined below that are preceded by a dot
3525e49fc963SAndy Fiddaman.Pq Sy \&. .
3526e49fc963SAndy FiddamanThese commands can subsequently be used inside further type definitions.
3527e49fc963SAndy FiddamanThe man page for these commands can be generated by using the
3528e49fc963SAndy Fiddaman.Fl -man
3529e49fc963SAndy Fiddamanoption or any of the other
3530e49fc963SAndy Fiddaman.Fl -
3531e49fc963SAndy Fiddamanoptions described with
3532e49fc963SAndy Fiddaman.Ic getopts .
3533e49fc963SAndy FiddamanThe
3534e49fc963SAndy Fiddaman.Fl r ,
3535e49fc963SAndy Fiddaman.Fl a ,
3536e49fc963SAndy Fiddaman.Fl A ,
3537e49fc963SAndy Fiddaman.Fl h
3538e49fc963SAndy Fiddamanand
3539e49fc963SAndy Fiddaman.Fl S
3540e49fc963SAndy Fiddamanoptions of
3541e49fc963SAndy Fiddaman.Ic typeset
3542b30d1939SAndy Fiddamanare permitted with each of these new built-ins.
3543e49fc963SAndy Fiddaman.Pp
3544e49fc963SAndy FiddamanAn instance of a type is created by invoking the type name followed by one or
3545e49fc963SAndy Fiddamanmore instance names.
3546b30d1939SAndy FiddamanEach instance of the type is initialized with a copy of the sub-variables
3547e49fc963SAndy Fiddamanexcept for sub-variables that are defined with the
3548e49fc963SAndy Fiddaman.Fl s
3549e49fc963SAndy Fiddamanoption.
3550e49fc963SAndy FiddamanVariables defined with
3551e49fc963SAndy Fiddaman.Fl S
3552e49fc963SAndy Fiddamanare shared by all instances of the type.
3553e49fc963SAndy FiddamanEach instance can change the value of any sub-variable and can also define new
3554e49fc963SAndy Fiddamandiscipline functions of the same names as those defined by the type definition
3555e49fc963SAndy Fiddamanas well as any standard discipline names.
3556e49fc963SAndy FiddamanNo additional sub-variables can be defined for any instance.
3557e49fc963SAndy Fiddaman.Pp
3558b30d1939SAndy FiddamanWhen defining a type, if the value of a sub-variable is not set and the
3559e49fc963SAndy Fiddaman.Fl r
3560e49fc963SAndy Fiddamanattribute is specified, it causes the sub-variable to be a required
3561e49fc963SAndy Fiddamansub-variable.
3562e49fc963SAndy FiddamanWhenever an instance of a type is created, all required sub-variables must be
3563e49fc963SAndy Fiddamanspecified.
3564e49fc963SAndy FiddamanThese sub-variables become readonly in each instance.
3565e49fc963SAndy Fiddaman.Pp
3566e49fc963SAndy FiddamanWhen
3567e49fc963SAndy Fiddaman.Ic unset
3568e49fc963SAndy Fiddamanis invoked on a sub-variable within a type, and the
3569e49fc963SAndy Fiddaman.Fl r
3570b30d1939SAndy Fiddamanattribute has not been specified for this field, the value is reset to the
3571e49fc963SAndy Fiddamandefault value associative with the type.
3572e49fc963SAndy FiddamanInvoking
3573e49fc963SAndy Fiddaman.Ic unset
3574e49fc963SAndy Fiddamanon a type instance not contained within another type deletes all sub-variables
3575e49fc963SAndy Fiddamanand the variable itself.
3576b30d1939SAndy FiddamanA type definition can be derived from another type definition by defining the
3577e49fc963SAndy Fiddamanfirst sub-variable name as
3578e49fc963SAndy Fiddaman.Sy _
3579e49fc963SAndy Fiddamanand defining its type as the base type.
3580e49fc963SAndy FiddamanAny remaining definitions will be additions and modifications that apply to the
3581e49fc963SAndy Fiddamannew type.
3582e49fc963SAndy FiddamanIf the new type name is the same is that of the base type, the type will be
3583e49fc963SAndy Fiddamanreplaced and the original type will no longer be accessible.
3584e49fc963SAndy Fiddaman.Pp
3585e49fc963SAndy FiddamanThe
3586e49fc963SAndy Fiddaman.Ic typeset
3587e49fc963SAndy Fiddamancommand with
3588e49fc963SAndy Fiddaman.Fl T
3589e49fc963SAndy Fiddamanand no option argument or operands will write all the type definitions to
3590e49fc963SAndy Fiddamanstandard output in a form that that can be read in to create all the types.
3591e49fc963SAndy Fiddaman.Ss "Jobs"
3592e49fc963SAndy FiddamanIf the monitor option of the
3593e49fc963SAndy Fiddaman.Ic set
3594e49fc963SAndy Fiddamancommand is turned on, an interactive shell associates a job with each pipeline.
3595e49fc963SAndy FiddamanIt keeps a table of current jobs, printed by the
3596e49fc963SAndy Fiddaman.Ic jobs
3597e49fc963SAndy Fiddamancommand, and assigns them small integer numbers.
3598e49fc963SAndy FiddamanWhen a job is started asynchronously with
3599e49fc963SAndy Fiddaman.Sy \&& ,
3600e49fc963SAndy Fiddamanthe shell prints a line which looks like:
3601e49fc963SAndy Fiddaman.Pp
3602e49fc963SAndy Fiddaman.Dl [1] 1234
3603e49fc963SAndy Fiddaman.Pp
3604c10c16deSRichard Loweindicating that the job which was started asynchronously was job number 1 and
3605e49fc963SAndy Fiddamanhad one (top-level) process, whose process id was
3606e49fc963SAndy Fiddaman.Sy 1234 .
3607e49fc963SAndy Fiddaman.Pp
3608e49fc963SAndy FiddamanIf you are running a job and wish to stop it, CTRL-z sends a
3609e49fc963SAndy Fiddaman.Sy STOP
3610e49fc963SAndy Fiddamansignal to the current job.
3611e49fc963SAndy FiddamanThe shell normally displays a message that the job has been stopped, and
3612e49fc963SAndy Fiddamandisplays another prompt.
3613e49fc963SAndy FiddamanYou can then manipulate the state of this job, putting it in the background
3614e49fc963SAndy Fiddamanwith the
3615e49fc963SAndy Fiddaman.Ic bg
3616e49fc963SAndy Fiddamancommand, or run some other commands and then eventually bring the job back into
3617e49fc963SAndy Fiddamanthe foreground with the foreground command
3618e49fc963SAndy Fiddaman.Ic fg .
3619e49fc963SAndy FiddamanA CTRL-z takes effect immediately and is like an interrupt in that pending
3620e49fc963SAndy Fiddamanoutput and unread input are discarded when it is typed.
3621e49fc963SAndy Fiddaman.Pp
3622c10c16deSRichard LoweA job being run in the background stops if it tries to read from the terminal.
3623c10c16deSRichard LoweBackground jobs are normally allowed to produce output, but this can be
3624e49fc963SAndy Fiddamandisabled by giving the command
3625e49fc963SAndy Fiddaman.Sy stty tostop .
3626e49fc963SAndy FiddamanIf you set this
3627e49fc963SAndy Fiddaman.Sy tty
3628c10c16deSRichard Loweoption, then background jobs stop when they try to produce output like they do
3629c10c16deSRichard Lowewhen they try to read input.
3630e49fc963SAndy Fiddaman.Pp
3631e49fc963SAndy FiddamanA job pool is a collection of jobs started with
3632e49fc963SAndy Fiddaman.Ar list Sy &
3633e49fc963SAndy Fiddamanassociated with a name.
3634e49fc963SAndy Fiddaman.Pp
3635e49fc963SAndy FiddamanThere are several ways to refer to jobs in the shell.
3636e49fc963SAndy FiddamanA job can be referred to
3637c10c16deSRichard Loweby the process id of any process of the job or by one of the following:
3638e49fc963SAndy Fiddaman.Bl -tag -width Ar
3639e49fc963SAndy Fiddaman.It Sy % Ns Ar number
3640c10c16deSRichard LoweThe job with the specified number.
3641e49fc963SAndy Fiddaman.It Ar pool
3642e49fc963SAndy FiddamanAll the jobs in the job pool named by
3643e49fc963SAndy Fiddaman.Ar pool .
3644e49fc963SAndy Fiddaman.It Ar pool Ns Sy \&. Ns Ar number
3645e49fc963SAndy FiddamanThe job number
3646e49fc963SAndy Fiddaman.Ar number
3647e49fc963SAndy Fiddamanin the pool named by
3648e49fc963SAndy Fiddaman.Ar pool .
3649e49fc963SAndy Fiddaman.It Sy % Ns Ar string
3650e49fc963SAndy FiddamanAny job whose command line begins with
3651e49fc963SAndy Fiddaman.Ar string .
3652e49fc963SAndy Fiddaman.It Sy %? Ns Ar string
3653e49fc963SAndy FiddamanAny job whose command line contains
3654e49fc963SAndy Fiddaman.Ar string .
3655e49fc963SAndy Fiddaman.It Sy %%
3656c10c16deSRichard LoweCurrent job.
3657e49fc963SAndy Fiddaman.It Sy %+
3658e49fc963SAndy FiddamanEquivalent to
3659e49fc963SAndy Fiddaman.Sy %% .
3660e49fc963SAndy Fiddaman.It Sy %-
3661c10c16deSRichard LowePrevious job.
3662e49fc963SAndy Fiddaman.El
3663e49fc963SAndy Fiddaman.Pp
3664e49fc963SAndy FiddamanIn addition, unless noted otherwise, wherever a job can be specified, the name
3665e49fc963SAndy Fiddamanof a background job pool can be used to represent all the jobs in that pool.
3666e49fc963SAndy Fiddaman.Pp
3667e49fc963SAndy FiddamanThe shell learns immediately whenever a process changes state.
3668e49fc963SAndy FiddamanIt normally informs you whenever a job becomes blocked so that no further
3669e49fc963SAndy Fiddamanprogress is possible, but only just before it prints a prompt.
3670e49fc963SAndy FiddamanThis is done so that it does not otherwise disturb your work.
3671e49fc963SAndy FiddamanThe notify option of the
3672e49fc963SAndy Fiddaman.Ic set
3673e49fc963SAndy Fiddamancommand causes the shell to print these job change messages as soon as they
3674e49fc963SAndy Fiddamanoccur.
3675e49fc963SAndy Fiddaman.Pp
3676e49fc963SAndy FiddamanWhen the
3677e49fc963SAndy Fiddaman.Sy monitor
3678e49fc963SAndy Fiddamanoption is on, each background job that completes triggers any trap set for
3679e49fc963SAndy Fiddaman.Dv CHLD .
3680e49fc963SAndy Fiddaman.Pp
3681c10c16deSRichard LoweWhen you try to leave the shell while jobs are running or stopped, you are
3682e49fc963SAndy Fiddamanwarned that
3683e49fc963SAndy Fiddaman.Pp
3684e49fc963SAndy Fiddaman.D1 You have stopped(running) jobs.
3685e49fc963SAndy Fiddaman.Pp
3686e49fc963SAndy FiddamanYou can use the
3687e49fc963SAndy Fiddaman.Ic jobs
3688e49fc963SAndy Fiddamancommand to see what they are.
3689e49fc963SAndy FiddamanIf you immediately try to exit again, the shell does not warn you a second
3690e49fc963SAndy Fiddamantime, and the stopped jobs are terminated.
3691e49fc963SAndy FiddamanWhen a login shell receives a
3692e49fc963SAndy Fiddaman.Sy HUP
3693e49fc963SAndy Fiddamansignal, it sends a
3694e49fc963SAndy Fiddaman.Sy HUP
3695e49fc963SAndy Fiddamansignal to each job that has not been disowned with the
3696e49fc963SAndy Fiddaman.Ic disown
3697e49fc963SAndy Fiddamanbuilt-in command.
3698e49fc963SAndy Fiddaman.Ss "Signals"
3699e49fc963SAndy FiddamanThe
3700e49fc963SAndy Fiddaman.Sy INT
3701e49fc963SAndy Fiddamanand
3702e49fc963SAndy Fiddaman.Sy QUIT
3703e49fc963SAndy Fiddamansignals for an invoked command are ignored if the command is followed by
3704e49fc963SAndy Fiddaman.Sy \&&
3705e49fc963SAndy Fiddamanand the
3706e49fc963SAndy Fiddaman.Sy monitor
3707e49fc963SAndy Fiddamanoption is not active.
3708e49fc963SAndy FiddamanOtherwise, signals have the values inherited by the shell from its parent.
3709e49fc963SAndy FiddamanSee the
3710e49fc963SAndy Fiddaman.Ic trap
3711e49fc963SAndy Fiddamanbuilt-in command.
3712e49fc963SAndy Fiddaman.Ss "Execution"
3713e49fc963SAndy FiddamanEach time a command is read, the substitutions are carried out.
3714e49fc963SAndy FiddamanIf the command name matches one of the ones in the
3715e49fc963SAndy Fiddaman.Sx Special Built-in Commands
3716e49fc963SAndy Fiddamansection of this manual page, it is executed within the current shell process.
3717e49fc963SAndy FiddamanNext, the command name is checked to see if it matches a user defined function.
3718e49fc963SAndy FiddamanIf it does, the positional parameters are saved and then reset to the arguments
3719e49fc963SAndy Fiddamanof the function call.
3720e49fc963SAndy FiddamanA function is also executed in the current shell process.
3721c10c16deSRichard LoweWhen the function completes or issues a return, the positional parameter list
3722e49fc963SAndy Fiddamanis restored.
3723e49fc963SAndy FiddamanFor functions defined with the
3724e49fc963SAndy Fiddaman.Ic function Ar name
3725e49fc963SAndy Fiddamansyntax, any trap set on
3726e49fc963SAndy Fiddaman.Dv EXIT
3727e49fc963SAndy Fiddamanwithin the function is executed.
3728e49fc963SAndy FiddamanThe exit value of a function is the value of the last command executed.
3729e49fc963SAndy FiddamanIf a command name is not a special built-in command or a user defined function,
3730e49fc963SAndy Fiddamanbut it is one of the built-in commands, it is executed in the current shell
3731e49fc963SAndy Fiddamanprocess.
3732e49fc963SAndy Fiddaman.Pp
3733e49fc963SAndy FiddamanThe shell variables
3734e49fc963SAndy Fiddaman.Ev PATH
3735e49fc963SAndy Fiddamanand
3736e49fc963SAndy Fiddaman.Ev FPATH
3737e49fc963SAndy Fiddamandefine the search path for the directory containing the command.
3738e49fc963SAndy FiddamanAlternative directory names are separated by a colon
3739e49fc963SAndy Fiddaman.Pq Sy \&: .
3740e49fc963SAndy FiddamanThe default path is
3741e49fc963SAndy Fiddaman.Pa /bin Ns Sy \&: Ns Pa /usr/bin Ns Sy \&: ,
3742e49fc963SAndy Fiddamanspecifying
3743e49fc963SAndy Fiddaman.Pa /bin ,
3744e49fc963SAndy Fiddaman.Pa /usr/bin ,
3745e49fc963SAndy Fiddamanand the current directory in that order.
3746e49fc963SAndy FiddamanThe current directory can be specified by two or more adjacent colons, or by a
3747e49fc963SAndy Fiddamancolon at the beginning or end of the path list.
3748e49fc963SAndy FiddamanIf the command name contains a slash
3749e49fc963SAndy Fiddaman.Pq Sy \&/ ,
3750e49fc963SAndy Fiddamanthe search path is not used.
3751e49fc963SAndy FiddamanOtherwise, each directory in the list of directories defined by
3752e49fc963SAndy Fiddaman.Ev PATH
3753e49fc963SAndy Fiddamanand
3754e49fc963SAndy Fiddaman.Ev FPATH
3755e49fc963SAndy Fiddamanis checked in order.
3756e49fc963SAndy FiddamanIf the directory being searched is contained in the value of the
3757e49fc963SAndy Fiddaman.Ev FPATH
3758b30d1939SAndy Fiddamanvariable and contains a file whose name matches the command being searched,
3759b30d1939SAndy Fiddamanthen this file is loaded into the current shell environment as if it were the
3760e49fc963SAndy Fiddamanargument to the
3761e49fc963SAndy Fiddaman.Ic \&.
3762e49fc963SAndy Fiddamancommand except that only preset aliases are expanded, and a function of the
3763e49fc963SAndy Fiddamanspecified name is executed as described in this manual page.
3764e49fc963SAndy Fiddaman.Pp
3765e49fc963SAndy FiddamanIf this directory is not in
3766e49fc963SAndy Fiddaman.Ev FPATH ,
3767e49fc963SAndy Fiddamanthe shell first determines whether there is a built-in version of a command
3768e49fc963SAndy Fiddamancorresponding to a given pathname and, if so, it is invoked in the current
3769e49fc963SAndy Fiddamanprocess.
3770e49fc963SAndy FiddamanIf no built-in is found, the shell checks for a file named
3771e49fc963SAndy Fiddaman.Pa \&.paths
3772e49fc963SAndy Fiddamanin this directory.
3773e49fc963SAndy FiddamanIf found and there is a line of the form:
3774e49fc963SAndy Fiddaman.Pp
3775e49fc963SAndy Fiddaman.D1 Ev FPATH Ns = Ns Ar path
3776e49fc963SAndy Fiddaman.Pp
3777e49fc963SAndy Fiddamanwhere
3778e49fc963SAndy Fiddaman.Ar path
3779e49fc963SAndy Fiddamanis an existing directory, then that directory is searched immediately after the
3780e49fc963SAndy Fiddamancurrent directory as if it were found in the
3781e49fc963SAndy Fiddaman.Ev FPATH
3782e49fc963SAndy Fiddamanvariable.
3783e49fc963SAndy FiddamanIf
3784e49fc963SAndy Fiddaman.Ar path
3785e49fc963SAndy Fiddamandoes not begin with
3786e49fc963SAndy Fiddaman.Sy / ,
3787e49fc963SAndy Fiddamanit is checked for relative to the directory being searched.
3788e49fc963SAndy Fiddaman.Pp
3789e49fc963SAndy FiddamanThe
3790e49fc963SAndy Fiddaman.Pa \&.paths
3791e49fc963SAndy Fiddamanfile is then checked for a line of the form:
3792e49fc963SAndy Fiddaman.Pp
3793e49fc963SAndy Fiddaman.D1 Ev PLUGIN_LIB Ns = Ns Ar libname Ns Oo Sy \&: Ns Ar libname Oc Ns No ...
3794e49fc963SAndy Fiddaman.Pp
3795e49fc963SAndy FiddamanEach library named by
3796e49fc963SAndy Fiddaman.Ar libname
3797e49fc963SAndy Fiddamanwill be searched for as if it were an option argument to
3798e49fc963SAndy Fiddaman.Ic builtin Fl f
3799e49fc963SAndy Fiddamanand, if it contains a built-in of the specified name, this is executed instead
3800e49fc963SAndy Fiddamanof a command by this name.
3801e49fc963SAndy Fiddaman.Pp
3802b30d1939SAndy FiddamanAny built-in loaded from a library found this way will be associated with the
3803e49fc963SAndy Fiddamandirectory containing the
3804e49fc963SAndy Fiddaman.Pa \&.paths
3805e49fc963SAndy Fiddamanfile so it will only execute if not found in an earlier directory.
3806e49fc963SAndy Fiddaman.Pp
3807b30d1939SAndy FiddamanFinally, the directory will be checked for a file of the given name.
3808e49fc963SAndy FiddamanIf the file has execute permission but is not an
3809e49fc963SAndy Fiddaman.Pa a.out
3810e49fc963SAndy Fiddamanfile, it is assumed to be a file containing shell commands.
3811e49fc963SAndy FiddamanA separate shell is spawned to read it.
3812e49fc963SAndy FiddamanAll non-exported variables are removed in this case.
3813e49fc963SAndy FiddamanIf the shell command file doesn't have read permission, and/or if the
3814e49fc963SAndy Fiddaman.Sy setuid
3815e49fc963SAndy Fiddamanand
3816e49fc963SAndy Fiddaman.Sy setgid
3817e49fc963SAndy Fiddamanbits are set on the file, then the shell executes an agent whose job it is to
3818e49fc963SAndy Fiddamanset up the permissions and execute the shell with the shell command file passed
3819e49fc963SAndy Fiddamandown as an open file.
3820e49fc963SAndy FiddamanIf the
3821e49fc963SAndy Fiddaman.Pa \&.paths
3822e49fc963SAndy Fiddamancontains a line of the form:
3823e49fc963SAndy Fiddaman.Pp
3824e49fc963SAndy Fiddaman.D1 Sy name= Ns Ar value
3825e49fc963SAndy Fiddaman.Pp
3826b30d1939SAndy Fiddamanin the
3827e49fc963SAndy Fiddamanfirst or second line, then the environment variable
3828e49fc963SAndy Fiddaman.Ar name
3829e49fc963SAndy Fiddamanis modified by prepending the directory specified by
3830e49fc963SAndy Fiddaman.Ar value
3831e49fc963SAndy Fiddamanto the directory list.
3832e49fc963SAndy FiddamanIf
3833e49fc963SAndy Fiddaman.Ar value
3834e49fc963SAndy Fiddamanis not an absolute directory, then it specifies a directory relative to the
3835e49fc963SAndy Fiddamandirectory in which the executable was found.
3836e49fc963SAndy FiddamanIf the environment variable
3837e49fc963SAndy Fiddaman.Ev name
3838e49fc963SAndy Fiddamandoes not already exist it will be added to the environment list for the
3839e49fc963SAndy Fiddamanspecified command.
3840b30d1939SAndy FiddamanA parenthesized command is executed in a sub-shell without removing
3841b30d1939SAndy Fiddamannon-exported variables.
3842e49fc963SAndy Fiddaman.Ss "Command Re-entry"
3843e49fc963SAndy FiddamanThe text of the last
3844e49fc963SAndy Fiddaman.Ev HISTSIZE
3845e49fc963SAndy Fiddaman.Pq default 512
3846e49fc963SAndy Fiddamancommands entered from a terminal device is saved in a history file.
3847e49fc963SAndy FiddamanThe file
3848e49fc963SAndy Fiddaman.Pa $HOME/.sh_history
3849e49fc963SAndy Fiddamanis used if the
3850e49fc963SAndy Fiddaman.Ev HISTFILE
3851e49fc963SAndy Fiddamanvariable is not set or if the file it names is not writable.
3852e49fc963SAndy FiddamanA shell can access the commands of all interactive shells which use the same
3853e49fc963SAndy Fiddamannamed
3854e49fc963SAndy Fiddaman.Ev HISTFILE .
3855e49fc963SAndy FiddamanThe built-in command
3856e49fc963SAndy Fiddaman.Ic hist
3857e49fc963SAndy Fiddamanis used to list or edit a portion of this file.
3858e49fc963SAndy FiddamanThe portion of the file to be edited or listed can be selected by number or by
3859e49fc963SAndy Fiddamangiving the first character or characters of the command.
3860e49fc963SAndy FiddamanA single command or range of commands can be specified.
3861e49fc963SAndy FiddamanIf you do not specify an editor program as an argument to
3862e49fc963SAndy Fiddaman.Ic hist
3863e49fc963SAndy Fiddamanthen the value of the variable
3864e49fc963SAndy Fiddaman.Ev HISTEDIT
3865e49fc963SAndy Fiddamanis used.
3866e49fc963SAndy FiddamanIf
3867e49fc963SAndy Fiddaman.Ev HISTEDIT
3868e49fc963SAndy Fiddamanis unset, the obsolete variable
3869e49fc963SAndy Fiddaman.Ev FCEDIT
3870e49fc963SAndy Fiddamanis used.
3871e49fc963SAndy FiddamanIf
3872e49fc963SAndy Fiddaman.Ev FCEDIT
3873e49fc963SAndy Fiddamanis not defined, then
3874e49fc963SAndy Fiddaman.Pa /bin/ed
3875e49fc963SAndy Fiddamanis used.
3876e49fc963SAndy FiddamanThe edited commands are printed and executed again upon leaving the editor
3877e49fc963SAndy Fiddamanunless you quit without writing.
3878e49fc963SAndy FiddamanThe
3879e49fc963SAndy Fiddaman.Fl s
3880e49fc963SAndy Fiddamanoption
3881e49fc963SAndy Fiddaman.Pq and in obsolete versions, the editor name Sy \&-
3882e49fc963SAndy Fiddamanis used to skip the editing phase and to re-execute the command.
3883e49fc963SAndy FiddamanIn this case a substitution parameter of the form
3884e49fc963SAndy Fiddaman.Ar old Ns Sy = Ns Ar new
3885e49fc963SAndy Fiddamancan be used to modify the command before execution.
3886e49fc963SAndy FiddamanFor example, with the preset alias
3887e49fc963SAndy Fiddaman.Ic r ,
3888e49fc963SAndy Fiddamanwhich is aliased to
3889e49fc963SAndy Fiddaman.Ic hist -s ,
3890e49fc963SAndy Fiddamantyping
3891e49fc963SAndy Fiddaman.Sq r bad=good c
3892e49fc963SAndy Fiddamanre-executes the most recent
3893e49fc963SAndy Fiddamancommand which starts with the letter
3894e49fc963SAndy Fiddaman.Sy c ,
3895e49fc963SAndy Fiddamanreplacing the first occurrence of the string
3896e49fc963SAndy Fiddaman.Sq bad
3897e49fc963SAndy Fiddamanwith the string
3898e49fc963SAndy Fiddaman.Sq good .
3899e49fc963SAndy Fiddaman.Ss "Inline Editing Options"
3900c10c16deSRichard LoweNormally, each command line entered from a terminal device is simply typed
3901e49fc963SAndy Fiddamanfollowed by a NEWLINE (RETURN or LINE FEED).
3902e49fc963SAndy FiddamanIf either the
3903e49fc963SAndy Fiddaman.Sy emacs ,
3904e49fc963SAndy Fiddaman.Sy gmacs ,
3905e49fc963SAndy Fiddamanor
3906e49fc963SAndy Fiddaman.Sy vi
3907e49fc963SAndy Fiddamanoption is active, the user can edit the command line.
3908e49fc963SAndy FiddamanTo be in either of these edit modes set the corresponding option.
3909e49fc963SAndy FiddamanAn editing option is automatically selected each time the
3910e49fc963SAndy Fiddaman.Ev VISUAL
3911e49fc963SAndy Fiddamanor
3912e49fc963SAndy Fiddaman.Ev EDITOR
3913c10c16deSRichard Lowevariable is assigned a value ending in either of these option names.
3914e49fc963SAndy Fiddaman.Pp
3915c10c16deSRichard LoweThe editing features require that the user's terminal accept RETURN as carriage
3916c10c16deSRichard Lowereturn without line feed and that a SPACE must overwrite the current character
3917c10c16deSRichard Loweon the screen.
3918e49fc963SAndy Fiddaman.Pp
3919e49fc963SAndy FiddamanUnless the
3920e49fc963SAndy Fiddaman.Sy multiline
3921e49fc963SAndy Fiddamanoption is on, the editing modes implement a concept where the user is looking
3922e49fc963SAndy Fiddamanthrough a window at the current line.
3923e49fc963SAndy FiddamanThe window width is the value of
3924e49fc963SAndy Fiddaman.Ev COLUMNS
3925e49fc963SAndy Fiddamanif it is defined, otherwise
3926e49fc963SAndy Fiddaman.Sy 80 .
3927e49fc963SAndy FiddamanIf the window width is too small to display the prompt and leave at least 8
3928e49fc963SAndy Fiddamancolumns to enter input, the prompt is truncated from the left.
3929e49fc963SAndy FiddamanIf the line is longer than the window width minus two, a mark is displayed at
3930e49fc963SAndy Fiddamanthe end of the window to notify the user.
3931e49fc963SAndy FiddamanAs the cursor moves and reaches the window boundaries the window is centered
3932e49fc963SAndy Fiddamanabout the cursor.
3933e49fc963SAndy FiddamanThe mark is a
3934e49fc963SAndy Fiddaman.Sy >
3935e49fc963SAndy Fiddaman.Pq Sy \&< Ns \&, Sy \&*
3936e49fc963SAndy Fiddamanif the line extends on the right, left, or both sides of the window.
3937e49fc963SAndy Fiddaman.Pp
3938e49fc963SAndy FiddamanThe search commands in each edit mode provide access to the history file.
3939e49fc963SAndy FiddamanOnly strings are matched, not patterns, although a leading
3940e49fc963SAndy Fiddaman.Sy ^
3941e49fc963SAndy Fiddamanin the string restricts the match to begin at the first character in the line.
3942e49fc963SAndy Fiddaman.Pp
3943c10c16deSRichard LoweEach of the edit modes has an operation to list the files or commands that
3944e49fc963SAndy Fiddamanmatch a partially entered word.
3945e49fc963SAndy FiddamanWhen applied to the first word on the line, or the first word after a
3946e49fc963SAndy Fiddaman.Sy \&; ,
3947e49fc963SAndy Fiddaman.Sy \&| ,
3948e49fc963SAndy Fiddaman.Sy \&& ,
3949e49fc963SAndy Fiddamanor
3950e49fc963SAndy Fiddaman.Sy \&( ,
3951e49fc963SAndy Fiddamanand the word does not begin with
3952e49fc963SAndy Fiddaman.Sy \&~
3953e49fc963SAndy Fiddamanor contain a
3954e49fc963SAndy Fiddaman.Sy \&/ ,
3955e49fc963SAndy Fiddamanthe list of aliases, functions, and executable commands defined by the
3956e49fc963SAndy Fiddaman.Ev PATH
3957e49fc963SAndy Fiddamanvariable that could match the partial word is displayed.
3958e49fc963SAndy FiddamanOtherwise, the list of files that match the specified word is displayed.
3959e49fc963SAndy FiddamanIf the partially entered word does not contain any file expansion characters, a
3960e49fc963SAndy Fiddaman.Sy *
3961e49fc963SAndy Fiddamanis appended before generating these lists.
3962e49fc963SAndy FiddamanAfter displaying the generated list, the input line is redrawn.
3963e49fc963SAndy FiddamanThese operations are called command name listing and file name listing,
3964e49fc963SAndy Fiddamanrespectively.
3965c10c16deSRichard LoweThere are additional operations, referred to as command name completion and
3966c10c16deSRichard Lowefile name completion, which compute the list of matching commands or files, but
3967c10c16deSRichard Loweinstead of printing the list, replace the current word with a complete or
3968e49fc963SAndy Fiddamanpartial match.
3969e49fc963SAndy FiddamanFor file name completion, if the match is unique, a
3970e49fc963SAndy Fiddaman.Sy /
3971e49fc963SAndy Fiddamanis appended if the file is a directory and a space is appended if the file is
3972e49fc963SAndy Fiddamannot a directory.
3973e49fc963SAndy FiddamanOtherwise, the longest common prefix for all the matching files replaces the
3974e49fc963SAndy Fiddamanword.
3975e49fc963SAndy FiddamanFor command name completion, only the portion of the file names after the last
3976e49fc963SAndy Fiddaman.Sy /
3977e49fc963SAndy Fiddamanare used to find the longest command prefix.
3978e49fc963SAndy FiddamanIf only a single name matches this prefix, then the word is replaced with the
3979e49fc963SAndy Fiddamancommand name followed by a space.
3980e49fc963SAndy FiddamanWhen using a
3981e49fc963SAndy Fiddaman.Dv TAB
3982e49fc963SAndy Fiddamanfor completion that does not yield a unique match, a subsequent
3983e49fc963SAndy Fiddaman.Dv TAB
3984e49fc963SAndy Fiddamanprovides a numbered list of matching alternatives.
3985e49fc963SAndy FiddamanA specific selection can be made by entering the selection number followed by a
3986e49fc963SAndy Fiddaman.Dv TAB .
3987e49fc963SAndy Fiddaman.Ss "Key Bindings"
3988e49fc963SAndy FiddamanThe
3989e49fc963SAndy Fiddaman.Sy KEYBD
3990e49fc963SAndy Fiddamantrap can be used to intercept keys as they are typed and change the characters
3991e49fc963SAndy Fiddamanthat are actually seen by the shell.
3992e49fc963SAndy FiddamanThis trap is executed after each character (or sequence of characters when the
3993e49fc963SAndy Fiddamanfirst character is ESC) is entered while reading from a terminal.
3994e49fc963SAndy Fiddaman.Pp
3995e49fc963SAndy FiddamanThe variable
3996e49fc963SAndy Fiddaman.Sy \&.sh.edchar
3997e49fc963SAndy Fiddamancontains the character or character sequence which generated the trap.
3998e49fc963SAndy FiddamanChanging the value of
3999e49fc963SAndy Fiddaman.Sy \&.sh.edchar
4000e49fc963SAndy Fiddamanin the trap action causes the shell to behave as if the new value were entered
4001e49fc963SAndy Fiddamanfrom the keyboard rather than the original value.
4002e49fc963SAndy FiddamanThe variable
4003e49fc963SAndy Fiddaman.Sy \&.sh.edcol
4004e49fc963SAndy Fiddamanis set to the input column number of the cursor at the time of the input.
4005e49fc963SAndy FiddamanThe variable
4006e49fc963SAndy Fiddaman.Sy \&.sh.edmode
4007e49fc963SAndy Fiddamanis set to
4008e49fc963SAndy Fiddaman.Sy ESC
4009e49fc963SAndy Fiddamanwhen in
4010e49fc963SAndy Fiddaman.Sy vi
4011e49fc963SAndy Fiddamaninsert mode and is null otherwise.
4012e49fc963SAndy FiddamanBy prepending
4013e49fc963SAndy Fiddaman.Sy ${.sh.editmode}
4014e49fc963SAndy Fiddamanto a value assigned to
4015e49fc963SAndy Fiddaman.Sy \&.sh.edchar
4016e49fc963SAndy Fiddamanit causes the shell to change to control mode if it is not already in this
4017e49fc963SAndy Fiddamanmode.
4018e49fc963SAndy Fiddaman.Pp
4019c10c16deSRichard LoweThis trap is not invoked for characters entered as arguments to editing
4020c10c16deSRichard Lowedirectives, or while reading input for a character search.
4021e49fc963SAndy Fiddaman.Ss "emacs Editing Mode"
4022e49fc963SAndy FiddamanThis mode is entered by enabling either the
4023e49fc963SAndy Fiddaman.Sy emacs
4024e49fc963SAndy Fiddamanor
4025e49fc963SAndy Fiddaman.Sy gmacs
4026e49fc963SAndy Fiddamanoption.
4027e49fc963SAndy FiddamanThe only difference between these two modes is the way they handle
4028e49fc963SAndy Fiddaman.Sy ^T .
4029e49fc963SAndy FiddamanTo edit, the user moves the cursor to the point needing correction and then
4030e49fc963SAndy Fiddamaninserts or deletes characters or words as needed.
4031e49fc963SAndy FiddamanAll the editing commands are control characters or escape sequences.
4032e49fc963SAndy Fiddaman.Pp
4033e49fc963SAndy FiddamanThe notation for control characters is caret
4034e49fc963SAndy Fiddaman.Pq Sy ^
4035e49fc963SAndy Fiddamanfollowed by the character.
4036e49fc963SAndy Fiddaman.Pp
4037e49fc963SAndy FiddamanFor example,
4038e49fc963SAndy Fiddaman.Sy ^F
4039e49fc963SAndy Fiddamanis the notation for CTRL/F.
4040e49fc963SAndy FiddamanThis is entered by depressing
4041e49fc963SAndy Fiddaman.Sy f
4042e49fc963SAndy Fiddamanwhile holding down the CTRL (control) key.
4043e49fc963SAndy FiddamanThe SHIFT key is not depressed.
4044e49fc963SAndy Fiddaman(The notation
4045e49fc963SAndy Fiddaman.Sy ^?
4046e49fc963SAndy Fiddamanindicates the DEL (delete) key).
4047e49fc963SAndy Fiddaman.Pp
4048e49fc963SAndy FiddamanThe notation for escape sequences is
4049e49fc963SAndy Fiddaman.Sy M-
4050e49fc963SAndy Fiddamanfollowed by a character.
4051e49fc963SAndy FiddamanFor example,
4052e49fc963SAndy Fiddaman.Sy M-f
4053e49fc963SAndy Fiddaman.Pq pronounced Sy Meta f
4054e49fc963SAndy Fiddamanis entered by depressing ESC
4055e49fc963SAndy Fiddaman.Pq Sy ASCII 033
4056e49fc963SAndy Fiddamanfollowed by
4057e49fc963SAndy Fiddaman.Ql f .
4058e49fc963SAndy Fiddaman.Sy M-F
4059e49fc963SAndy Fiddamanis the notation for ESC followed by
4060e49fc963SAndy Fiddaman.Ql F .
4061e49fc963SAndy Fiddaman.Pp
4062c10c16deSRichard LoweAll edit commands operate from any place on the line, not just at the
4063e49fc963SAndy Fiddamanbeginning.
4064e49fc963SAndy FiddamanThe RETURN or the LINE FEED key is not entered after edit commands except when
4065e49fc963SAndy Fiddamannoted.
4066e49fc963SAndy Fiddaman.Bl -tag -width Ar
4067e49fc963SAndy Fiddaman.It Sy ^F
4068c10c16deSRichard LoweMove the cursor forward (right) one character.
4069e49fc963SAndy Fiddaman.It Sy M-[C
4070c10c16deSRichard LoweMove the cursor forward (right) one character.
4071e49fc963SAndy Fiddaman.It Sy M-f
4072e49fc963SAndy FiddamanMove the cursor forward one word.
4073e49fc963SAndy FiddamanThe
4074e49fc963SAndy Fiddaman.Sy emacs
4075e49fc963SAndy Fiddamaneditor's idea of a word is a string of characters consisting of only letters,
4076e49fc963SAndy Fiddamandigits and underscores.
4077e49fc963SAndy Fiddaman.It Sy ^B
4078c10c16deSRichard LoweMove the cursor backward (left) one character.
4079e49fc963SAndy Fiddaman.It Sy M-[D
4080c10c16deSRichard LoweMove the cursor backward (left) one character.
4081e49fc963SAndy Fiddaman.It Sy M-b
4082c10c16deSRichard LoweMove the cursor backward one word.
4083e49fc963SAndy Fiddaman.It Sy ^A
4084c10c16deSRichard LoweMove the cursor to the beginning of the line.
4085e49fc963SAndy Fiddaman.It Sy M-[H
4086c10c16deSRichard LoweMove the cursor to the beginning of the line.
4087e49fc963SAndy Fiddaman.It Sy ^E
4088c10c16deSRichard LoweMove the cursor to the end of the line.
4089e49fc963SAndy Fiddaman.It Sy M-[Y
4090c10c16deSRichard LoweMove the cursor to the end of line.
4091e49fc963SAndy Fiddaman.It Sy ^] Ns Ar char
4092e49fc963SAndy FiddamanMove the cursor forward to the character
4093e49fc963SAndy Fiddaman.Ar char
4094e49fc963SAndy Fiddamanon the current line.
4095e49fc963SAndy Fiddaman.It Sy M-^\&] Ns Ar char
4096e49fc963SAndy FiddamanMove the cursor backwards to the character
4097e49fc963SAndy Fiddaman.Ar char
4098e49fc963SAndy Fiddamanon the current line.
4099e49fc963SAndy Fiddaman.It Sy ^X^X
4100c10c16deSRichard LoweInterchange the cursor and the mark.
4101e49fc963SAndy Fiddaman.It Ar erase
4102e49fc963SAndy FiddamanDelete the previous character.
4103e49fc963SAndy FiddamanThe user-defined erase character is defined by the
4104e49fc963SAndy Fiddaman.Xr stty 1
4105e49fc963SAndy Fiddamancommand, and is usually
4106e49fc963SAndy Fiddaman.Sy ^H
4107e49fc963SAndy Fiddamanor
4108e49fc963SAndy Fiddaman.Sy # .
4109e49fc963SAndy Fiddaman.It Ar lnext
4110e49fc963SAndy FiddamanRemoves the next character's editing features.
4111e49fc963SAndy FiddamanThe user-defined literal next character is defined by the
4112e49fc963SAndy Fiddaman.Xr stty 1
4113e49fc963SAndy Fiddamancommand, or is
4114e49fc963SAndy Fiddaman.Sy ^V
4115e49fc963SAndy Fiddamanif not defined.
4116e49fc963SAndy Fiddaman.It Sy ^D
4117c10c16deSRichard LoweDelete the current character.
4118e49fc963SAndy Fiddaman.It Sy M-d
4119c10c16deSRichard LoweDelete the current word.
4120e49fc963SAndy Fiddaman.It Sy M-^H
4121e49fc963SAndy FiddamanMetaBACKSPACE.
4122c10c16deSRichard LoweDelete the previous word.
4123e49fc963SAndy Fiddaman.It Sy M-h
4124e49fc963SAndy FiddamanDelete the previous word.
4125e49fc963SAndy Fiddaman.It Sy M-^\&?
4126e49fc963SAndy FiddamanMetaDEL.
4127e49fc963SAndy FiddamanDelete the previous word.
4128e49fc963SAndy FiddamanIf your interrupt character is
4129e49fc963SAndy Fiddaman.Sy ^?
4130c10c16deSRichard Lowe(DEL, the default), this command does not work.
4131e49fc963SAndy Fiddaman.It Sy ^T
4132c10c16deSRichard LoweTranspose the current character with the previous character, and advance the
4133e49fc963SAndy Fiddamancursor in
4134e49fc963SAndy Fiddaman.Sy emacs
4135c10c16deSRichard Lowemode.
4136e49fc963SAndy FiddamanTranspose two previous characters in
4137e49fc963SAndy Fiddaman.Sy gmacs
4138e49fc963SAndy Fiddamanmode.
4139e49fc963SAndy Fiddaman.It Sy ^C
4140c10c16deSRichard LoweCapitalize the current character.
4141e49fc963SAndy Fiddaman.It Sy M-c
4142c10c16deSRichard LoweCapitalize the current word.
4143e49fc963SAndy Fiddaman.It Sy M-l
4144c10c16deSRichard LoweChange the current word to lower case.
4145e49fc963SAndy Fiddaman.It Sy ^K
4146e49fc963SAndy FiddamanDelete from the cursor to the end of the line.
4147e49fc963SAndy FiddamanIf preceded by a numerical parameter whose value is less than the current
4148e49fc963SAndy Fiddamancursor position, delete from specified position up to the cursor.
4149e49fc963SAndy FiddamanIf preceded by a numerical parameter whose value is greater than the current
4150e49fc963SAndy Fiddamancursor position, then delete from cursor up to specified cursor position.
4151e49fc963SAndy Fiddaman.It Sy ^W
4152c10c16deSRichard LoweKill from the cursor to the mark.
4153e49fc963SAndy Fiddaman.It Sy M-p
4154c10c16deSRichard LowePush the region from the cursor to the mark on the stack.
4155e49fc963SAndy Fiddaman.It Ar kill
4156e49fc963SAndy FiddamanKill the entire current line.
4157e49fc963SAndy FiddamanThe user-defined kill character is defined by the
4158e49fc963SAndy Fiddaman.Xr stty 1
4159e49fc963SAndy Fiddamancommand, usually a
4160e49fc963SAndy Fiddaman.Sy ^G
4161e49fc963SAndy Fiddamanor
4162e49fc963SAndy Fiddaman.Sy @ .
4163e49fc963SAndy FiddamanIf two kill characters are entered in succession, all kill characters from then
4164e49fc963SAndy Fiddamanon cause a line feed.
4165c10c16deSRichard LoweThis is useful when using paper terminals.
4166e49fc963SAndy Fiddaman.It Sy ^Y
4167e49fc963SAndy FiddamanRestore the last item removed from line.
4168e49fc963SAndy FiddamanYank the item back to the line.
4169e49fc963SAndy Fiddaman.It Sy ^L
4170c10c16deSRichard LoweLine feed and print the current line.
4171e49fc963SAndy Fiddaman.It Sy M-^L
4172c10c16deSRichard LoweClear the screen.
4173e49fc963SAndy Fiddaman.It Sy ^@
4174e49fc963SAndy FiddamanNull character.
4175e49fc963SAndy FiddamanSet mark.
4176e49fc963SAndy Fiddaman.It Sy M- Ns Ar space
4177e49fc963SAndy FiddamanMetaSPACE.
4178e49fc963SAndy FiddamanSet the mark.
4179e49fc963SAndy Fiddaman.It Sy ^J
4180e49fc963SAndy FiddamanNew line.
4181e49fc963SAndy FiddamanExecute the current line.
4182e49fc963SAndy Fiddaman.It Sy ^M
4183e49fc963SAndy FiddamanReturn.
4184e49fc963SAndy FiddamanExecute the current line.
4185e49fc963SAndy Fiddaman.It Sy EOF
4186e49fc963SAndy FiddamanEnd-of-file character, normally
4187e49fc963SAndy Fiddaman.Sy ^D ,
4188e49fc963SAndy Fiddamanis processed as an
4189e49fc963SAndy Fiddaman.Sy end-of-file
4190c10c16deSRichard Loweonly if the current line is null.
4191e49fc963SAndy Fiddaman.It Sy ^P
4192e49fc963SAndy FiddamanFetch the previous command.
4193e49fc963SAndy FiddamanEach time
4194e49fc963SAndy Fiddaman.Sy ^P
4195e49fc963SAndy Fiddamanis entered the previous command back in time is accessed.
4196e49fc963SAndy FiddamanMoves back one line when it is not on the first line of a multi-line command.
4197e49fc963SAndy Fiddaman.It Sy M-[A
4198e49fc963SAndy Fiddaman.ad
4199e49fc963SAndy FiddamanEquivalent to
4200e49fc963SAndy Fiddaman.Sy ^P .
4201e49fc963SAndy Fiddaman.It Sy M-<
4202c10c16deSRichard LoweFetch the least recent (oldest) history line.
4203e49fc963SAndy Fiddaman.It Sy M->
4204c10c16deSRichard LoweFetch the most recent (youngest) history line.
4205e49fc963SAndy Fiddaman.It Sy ^N
4206e49fc963SAndy FiddamanFetch the next command line.
4207e49fc963SAndy FiddamanEach time
4208e49fc963SAndy Fiddaman.Sy ^N
4209e49fc963SAndy Fiddamanis entered the next command line forward in time is accessed.
4210e49fc963SAndy Fiddaman.It Sy M-[B
4211e49fc963SAndy FiddamanEquivalent to
4212e49fc963SAndy Fiddaman.Sy ^N .
4213e49fc963SAndy Fiddaman.It Sy ^R Ns Ar string
4214e49fc963SAndy FiddamanReverse search history for a previous command line containing
4215e49fc963SAndy Fiddaman.Ar string .
4216e49fc963SAndy FiddamanIf a parameter of zero is specified, the search is forward.
4217e49fc963SAndy Fiddaman.Ar string
4218e49fc963SAndy Fiddamanis terminated by a RETURN or NEWLINE.
4219e49fc963SAndy FiddamanIf string is preceded by a
4220e49fc963SAndy Fiddaman.Sy ^ ,
4221e49fc963SAndy Fiddamanthe matched line must begin with
4222e49fc963SAndy Fiddaman.Ar string .
4223e49fc963SAndy FiddamanIf
4224e49fc963SAndy Fiddaman.Ar string
4225e49fc963SAndy Fiddamanis omitted, then the next command line containing the most recent
4226e49fc963SAndy Fiddaman.Ar string
4227e49fc963SAndy Fiddamanis accessed.
4228e49fc963SAndy FiddamanIn this case a parameter of zero reverses the direction of the search.
4229e49fc963SAndy Fiddaman.It Sy ^O
4230e49fc963SAndy FiddamanOperate.
4231e49fc963SAndy FiddamanExecute the current line and fetch the next line relative to current line from
4232e49fc963SAndy Fiddamanthe history file.
4233e49fc963SAndy Fiddaman.It Sy M- Ns Ar digits
4234e49fc963SAndy FiddamanEscape.
4235e49fc963SAndy FiddamanDefine numeric parameter.
4236e49fc963SAndy FiddamanThe digits are taken as a parameter to the next command.
4237e49fc963SAndy FiddamanThe commands that accept a parameter are:
4238e49fc963SAndy Fiddaman.Sy ^F ,
4239e49fc963SAndy Fiddaman.Sy ^B ,
4240e49fc963SAndy Fiddaman.Sy ERASE ,
4241e49fc963SAndy Fiddaman.Sy ^C ,
4242e49fc963SAndy Fiddaman.Sy ^D ,
4243e49fc963SAndy Fiddaman.Sy ^K ,
4244e49fc963SAndy Fiddaman.Sy ^R ,
4245e49fc963SAndy Fiddaman.Sy ^P ,
4246e49fc963SAndy Fiddaman.Sy ^N ,
4247e49fc963SAndy Fiddaman.Sy ^] ,
4248e49fc963SAndy Fiddaman.Sy M-\&. ,
4249e49fc963SAndy Fiddaman.Sy M- ,
4250e49fc963SAndy Fiddaman.Sy M-^\&] ,
4251e49fc963SAndy Fiddaman.Sy M-_ ,
4252e49fc963SAndy Fiddaman.Sy M-= ,
4253e49fc963SAndy Fiddaman.Sy M-b ,
4254e49fc963SAndy Fiddaman.Sy M-c ,
4255e49fc963SAndy Fiddaman.Sy M-d ,
4256e49fc963SAndy Fiddaman.Sy M-f ,
4257e49fc963SAndy Fiddaman.Sy M-h ,
4258e49fc963SAndy Fiddaman.Sy M-l ,
4259e49fc963SAndy Fiddamanand
4260e49fc963SAndy Fiddaman.Sy M-^H .
4261e49fc963SAndy Fiddaman.It Sy M- Ns Ar letter
4262e49fc963SAndy FiddamanSoft-key.
4263e49fc963SAndy FiddamanSearch the alias list for an alias by the name
4264e49fc963SAndy Fiddaman.Ar letter .
4265e49fc963SAndy FiddamanIf an alias of
4266e49fc963SAndy Fiddaman.Ar letter
4267e49fc963SAndy Fiddamanis defined, insert its value on the input queue.
4268e49fc963SAndy Fiddaman.Ar letter
4269e49fc963SAndy Fiddamanmust not be one of the metafunctions in this section.
4270e49fc963SAndy Fiddaman.It Sy M-[ Ns Ar letter
4271e49fc963SAndy FiddamanSoft key.
4272e49fc963SAndy FiddamanSearch the alias list for an alias by the name
4273e49fc963SAndy Fiddaman.Ar letter .
4274e49fc963SAndy FiddamanIf an alias of this name is defined, insert its value on the input queue.
4275e49fc963SAndy FiddamanThis can be used to program function keys on many terminals.
4276e49fc963SAndy Fiddaman.It Sy M-\&.
4277e49fc963SAndy FiddamanThe last word of the previous command is inserted on the line.
4278e49fc963SAndy FiddamanIf preceded by a numeric parameter, the value of this parameter determines
4279e49fc963SAndy Fiddamanwhich word to insert rather than the last word.
4280e49fc963SAndy Fiddaman.It Sy M-_
4281e49fc963SAndy FiddamanSame as
4282e49fc963SAndy Fiddaman.Sy M-\&. .
4283e49fc963SAndy Fiddaman.It Sy M-*
4284e49fc963SAndy FiddamanAttempt filename generation on the current word.
4285e49fc963SAndy FiddamanAs asterisk is appended if the word does not match any file or contain any
4286e49fc963SAndy Fiddamanspecial pattern characters.
4287e49fc963SAndy Fiddaman.It Sy M-ESC
4288c10c16deSRichard LoweCommand or file name completion as described in this manual page.
4289e49fc963SAndy Fiddaman.It Sy ^I Pq TAB
4290e49fc963SAndy FiddamanAttempts command or file name completion as described in this manual page.
4291e49fc963SAndy FiddamanIf a partial completion occurs, repeating this behaves as if
4292e49fc963SAndy Fiddaman.Sy M-=
4293e49fc963SAndy Fiddamanwere entered.
4294c10c16deSRichard LoweIf no match is found or entered after SPACE, a TAB is inserted.
4295e49fc963SAndy Fiddaman.It Sy M-=
4296c10c16deSRichard LoweIf not preceded by a numeric parameter, generates the list of matching commands
4297e49fc963SAndy Fiddamanor file names as described in this manual page.
4298e49fc963SAndy FiddamanOtherwise, the word under the cursor is replaced by the item corresponding to
4299e49fc963SAndy Fiddamanthe value of the numeric parameter from the most recently generated command or
4300e49fc963SAndy Fiddamanfile list.
4301e49fc963SAndy FiddamanIf the cursor is not on a word, the word is inserted instead.
4302e49fc963SAndy Fiddaman.It Sy ^U
4303e49fc963SAndy FiddamanMultiply parameter of next command by
4304e49fc963SAndy Fiddaman.Sy 4 .
4305e49fc963SAndy Fiddaman.It Sy \e
4306e49fc963SAndy FiddamanEscape the next character.
4307e49fc963SAndy FiddamanEditing characters, the user's erase, kill and interrupt
4308e49fc963SAndy Fiddaman.Pq normally Sy ^?
4309e49fc963SAndy Fiddamancharacters can be entered in a command line or in a search string if preceded
4310e49fc963SAndy Fiddamanby a
4311e49fc963SAndy Fiddaman.Sy \e .
4312e49fc963SAndy FiddamanThe
4313e49fc963SAndy Fiddaman.Sy \e
4314e49fc963SAndy Fiddamanremoves the next character's editing features, if any.
4315e49fc963SAndy Fiddaman.It Sy M-^V
4316c10c16deSRichard LoweDisplay the version of the shell.
4317e49fc963SAndy Fiddaman.It Sy M-#
4318e49fc963SAndy FiddamanIf the line does not begin with a
4319e49fc963SAndy Fiddaman.Sy # ,
4320e49fc963SAndy Fiddamana
4321e49fc963SAndy Fiddaman.Sy #
4322e49fc963SAndy Fiddamanis inserted at the beginning of the line and after each NEWLINE, and the line
4323e49fc963SAndy Fiddamanis entered.
4324e49fc963SAndy FiddamanThis causes a comment to be inserted in the history file.
4325e49fc963SAndy FiddamanIf the line begins with a
4326e49fc963SAndy Fiddaman.Sy # ,
4327e49fc963SAndy Fiddamanthe
4328e49fc963SAndy Fiddaman.Sy #
4329e49fc963SAndy Fiddamanis deleted and one
4330e49fc963SAndy Fiddaman.Sy #
4331e49fc963SAndy Fiddamanafter each NEWLINE is also deleted.
4332e49fc963SAndy Fiddaman.El
4333e49fc963SAndy Fiddaman.Ss vi Editing Mode
4334e49fc963SAndy FiddamanThere are two typing modes.
4335e49fc963SAndy FiddamanInitially, when you enter a command you are in the input mode.
4336e49fc963SAndy FiddamanTo edit, the user enters control mode by typing ESC (033) and moves the cursor
4337e49fc963SAndy Fiddamanto the point needing correction and then inserts or deletes characters or words
4338e49fc963SAndy Fiddamanas needed.
4339e49fc963SAndy FiddamanMost control commands accept an optional repeat
4340e49fc963SAndy Fiddaman.Ar count
4341e49fc963SAndy Fiddamanprior to the command.
4342e49fc963SAndy Fiddaman.Pp
4343c10c16deSRichard LoweWhen in vi mode on most systems, canonical processing is initially enabled and
4344c10c16deSRichard Lowethe command is echoed again if the speed is 1200 baud or greater and it
4345c10c16deSRichard Lowecontains any control characters or less than one second has elapsed since the
4346e49fc963SAndy Fiddamanprompt was printed.
4347e49fc963SAndy FiddamanThe ESC character terminates canonical processing for the remainder of the
4348e49fc963SAndy Fiddamancommand and the user can then modify the command line.
4349e49fc963SAndy FiddamanThis scheme has the advantages of canonical processing with the type-ahead
4350e49fc963SAndy Fiddamanechoing of raw mode.
4351e49fc963SAndy Fiddaman.Pp
4352e49fc963SAndy FiddamanIf the option
4353e49fc963SAndy Fiddaman.Sy viraw
4354e49fc963SAndy Fiddamanis also set, the terminal is always have canonical processing disabled.
4355e49fc963SAndy FiddamanThis mode is implicit for systems that do not support two alternate end of line
4356e49fc963SAndy Fiddamandelimiters, and might be helpful for certain terminals.
4357e49fc963SAndy Fiddaman.Ss "Input Edit Commands"
4358c10c16deSRichard LoweBy default the editor is in input mode.
4359e49fc963SAndy Fiddaman.Pp
4360c10c16deSRichard LoweThe following input edit commands are supported:
4361e49fc963SAndy Fiddaman.Bl -tag -width Ds
4362e49fc963SAndy Fiddaman.It Sy ERASE
4363e49fc963SAndy FiddamanUser defined erase character as defined by the
4364e49fc963SAndy Fiddaman.Xr stty 1
4365e49fc963SAndy Fiddamancommand, usually
4366e49fc963SAndy Fiddaman.Sy ^H
4367e49fc963SAndy Fiddamanor
4368e49fc963SAndy Fiddaman.Sy # .
4369e49fc963SAndy FiddamanDelete previous character.
4370e49fc963SAndy Fiddaman.It Sy ^W
4371e49fc963SAndy FiddamanDelete the previous blank separated word.
4372e49fc963SAndy FiddamanOn some systems the
4373e49fc963SAndy Fiddaman.Sy viraw
4374c10c16deSRichard Loweoption might be required for this to work.
4375e49fc963SAndy Fiddaman.It Sy EOF
4376c10c16deSRichard LoweAs the first character of the line causes the shell to terminate unless the
4377e49fc963SAndy Fiddaman.Sy ignoreeof
4378e49fc963SAndy Fiddamanoption is set.
4379e49fc963SAndy FiddamanOtherwise this character is ignored.
4380e49fc963SAndy Fiddaman.It Ar lnext
4381e49fc963SAndy FiddamanUser defined literal next character as defined by
4382e49fc963SAndy Fiddaman.Xr stty 1
4383e49fc963SAndy Fiddamanor
4384e49fc963SAndy Fiddaman.Sy ^V
4385e49fc963SAndy Fiddamanif not defined.
4386e49fc963SAndy FiddamanRemoves the next character's editing features, if any.
4387e49fc963SAndy FiddamanOn some systems the
4388e49fc963SAndy Fiddaman.Sy viraw
4389e49fc963SAndy Fiddamanoption might be required for this to work.
4390e49fc963SAndy Fiddaman.It Sy \e
4391c10c16deSRichard LoweEscape the next ERASE or KILL character.
4392e49fc963SAndy Fiddaman.It Sy ^I Pq TAB
4393c10c16deSRichard LoweAttempts command or file name completion as described in this manual page and
4394e49fc963SAndy Fiddamanreturns to input mode.
4395e49fc963SAndy FiddamanIf a partial completion occurs, repeating this behaves as if
4396e49fc963SAndy Fiddaman.Sy \&=
4397e49fc963SAndy Fiddamanwere entered from control mode.
4398e49fc963SAndy FiddamanIf no match is found or entered after SPACE, a TAB is inserted.
4399e49fc963SAndy Fiddaman.El
4400e49fc963SAndy Fiddaman.Ss "Motion Edit Commands"
4401c10c16deSRichard LoweThe motion edit commands move the cursor.
4402e49fc963SAndy Fiddaman.Pp
4403c10c16deSRichard LoweThe following motion edit commands are supported:
4404e49fc963SAndy Fiddaman.Bl -tag -width Ar
4405e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy l
4406c10c16deSRichard LoweMove the cursor forward (right) one character.
4407e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy [C
4408c10c16deSRichard LoweMove the cursor forward (right) one character.
4409e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy w
4410c10c16deSRichard LoweMove the cursor forward one alphanumeric word.
4411e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy W
4412c10c16deSRichard LoweMove the cursor to the beginning of the next word that follows a blank.
4413e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy e
4414c10c16deSRichard LoweMove the cursor to the end of the word.
4415e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy E
4416c10c16deSRichard LoweMove the cursor to the end of the current blank delimited word.
4417e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy h
4418c10c16deSRichard LoweMove the cursor backward (left) one character.
4419e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy [D
4420c10c16deSRichard LoweMove the cursor backward (left) one character.
4421e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy b
4422c10c16deSRichard LoweMove the cursor backward one word.
4423e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy B
4424c10c16deSRichard LoweMove the cursor to the preceding blank separated word.
4425e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&|
4426e49fc963SAndy FiddamanMove the cursor to column
4427e49fc963SAndy Fiddaman.Ar count .
4428e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy f Ns Ar c
4429e49fc963SAndy FiddamanFind the next character
4430e49fc963SAndy Fiddaman.Ar c
4431e49fc963SAndy Fiddamanin the current line.
4432e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy F Ns Ar c
4433e49fc963SAndy FiddamanFind the previous character
4434e49fc963SAndy Fiddaman.Ar c
4435e49fc963SAndy Fiddamanin the current line.
4436e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy f Ns Ar c
4437e49fc963SAndy FiddamanEquivalent to
4438e49fc963SAndy Fiddaman.Sy f
4439e49fc963SAndy Fiddamanfollowed by
4440e49fc963SAndy Fiddaman.Sy h .
4441e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy T Ns Ar c
4442e49fc963SAndy FiddamanEquivalent to
4443e49fc963SAndy Fiddaman.Sy F
4444e49fc963SAndy Fiddamanfollowed by
4445e49fc963SAndy Fiddaman.Sy l .
4446e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&;
4447e49fc963SAndy FiddamanRepeat
4448e49fc963SAndy Fiddaman.Ar count
4449e49fc963SAndy Fiddamantimes the last single character find command:
4450e49fc963SAndy Fiddaman.Sy f ,
4451e49fc963SAndy Fiddaman.Sy F ,
4452e49fc963SAndy Fiddaman.Sy t ,
4453e49fc963SAndy Fiddamanor
4454e49fc963SAndy Fiddaman.Sy T .
4455e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&,
4456e49fc963SAndy FiddamanReverse the last single character find command
4457e49fc963SAndy Fiddaman.Ar count
4458e49fc963SAndy Fiddamantimes.
4459e49fc963SAndy Fiddaman.It Sy 0 Pq No zero
4460c10c16deSRichard LoweMove the cursor to the start of line.
4461e49fc963SAndy Fiddaman.It Sy \&^
4462c10c16deSRichard LoweMove the cursor to the first non-blank character in the line.
4463e49fc963SAndy Fiddaman.It Sy [H
4464e49fc963SAndy FiddamanMove the cursor to the first non-blank character in the line.
4465e49fc963SAndy Fiddaman.It Sy \&$
4466c10c16deSRichard LoweMove the cursor to the end of the line.
4467e49fc963SAndy Fiddaman.It Sy [Y
4468c10c16deSRichard LoweMove the cursor to the end of the line.
4469e49fc963SAndy Fiddaman.It Sy \&%
4470e49fc963SAndy FiddamanMoves to the balancing
4471e49fc963SAndy Fiddaman.Sy \&( ,
4472e49fc963SAndy Fiddaman.Sy \&) ,
4473e49fc963SAndy Fiddaman.Sy \&{ ,
4474e49fc963SAndy Fiddaman.Sy \&} ,
4475e49fc963SAndy Fiddaman.Sy \&[ ,
4476e49fc963SAndy Fiddamanor
4477e49fc963SAndy Fiddaman.Sy \&] .
4478e49fc963SAndy FiddamanIf cursor is not on one of the characters described in this section, the
4479e49fc963SAndy Fiddamanremainder of the line is searched for the first occurrence of one of the
4480e49fc963SAndy Fiddamancharacters first.
4481e49fc963SAndy Fiddaman.El
4482e49fc963SAndy Fiddaman.Ss "Search Edit Commands"
4483c10c16deSRichard LoweThe search edit commands access your command history.
4484e49fc963SAndy Fiddaman.Pp
4485c10c16deSRichard LoweThe following search edit commands are supported:
4486e49fc963SAndy Fiddaman.Bl -tag -width Ar
4487e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy k
4488e49fc963SAndy FiddamanFetch the previous command.
4489e49fc963SAndy FiddamanEach time
4490e49fc963SAndy Fiddaman.Sy k
4491e49fc963SAndy Fiddamanis entered, the previous command back in time is accessed.
4492e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&-
4493e49fc963SAndy FiddamanFetch the previous command.
4494e49fc963SAndy FiddamanEach time
4495e49fc963SAndy Fiddaman.Sy \&-
4496e49fc963SAndy Fiddamanis entered, the previous command back in time is accessed.
4497e49fc963SAndy FiddamanEquivalent to
4498e49fc963SAndy Fiddaman.Sy k .
4499e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy [A
4500e49fc963SAndy FiddamanFetch the previous command.
4501e49fc963SAndy FiddamanEach time
4502e49fc963SAndy Fiddaman.Sy [A
4503e49fc963SAndy Fiddamanis entered, the previous command back in time is accessed.
4504e49fc963SAndy FiddamanEquivalent to
4505e49fc963SAndy Fiddaman.Sy k .
4506e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy j
4507e49fc963SAndy FiddamanFetch the next command.
4508e49fc963SAndy FiddamanEach time
4509e49fc963SAndy Fiddaman.Sy j
4510e49fc963SAndy Fiddamanis entered, the next command forward
4511c10c16deSRichard Lowein time is accessed.
4512e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&+
4513e49fc963SAndy FiddamanFetch the next command.
4514e49fc963SAndy FiddamanEach time
4515e49fc963SAndy Fiddaman.Sy \&+
4516e49fc963SAndy Fiddamanis entered, the next command forward in time is accessed.
4517e49fc963SAndy FiddamanEquivalent to
4518e49fc963SAndy Fiddaman.Sy j .
4519e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy [B
4520e49fc963SAndy FiddamanFetch the next command.
4521e49fc963SAndy FiddamanEach time
4522e49fc963SAndy Fiddaman.Sy [B
4523e49fc963SAndy Fiddamanis entered, the next command forward in time is accessed.
4524e49fc963SAndy FiddamanEquivalent to
4525e49fc963SAndy Fiddaman.Sy j .
4526e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy G
4527e49fc963SAndy FiddamanFetch command number
4528e49fc963SAndy Fiddaman.Ar count .
4529e49fc963SAndy FiddamanThe default is the least recent history command.
4530e49fc963SAndy Fiddaman.It Sy / Ns Ar string
4531e49fc963SAndy FiddamanSearch backward through history for a previous command containing
4532e49fc963SAndy Fiddaman.Ar string .
4533e49fc963SAndy Fiddaman.Ar string
4534e49fc963SAndy Fiddamanis terminated by a RETURN or NEWLINE.
4535e49fc963SAndy FiddamanIf string is preceded by a
4536e49fc963SAndy Fiddaman.Sy ^ ,
4537e49fc963SAndy Fiddamanthe matched line must begin with
4538e49fc963SAndy Fiddaman.Ar string .
4539e49fc963SAndy FiddamanIf
4540e49fc963SAndy Fiddaman.Ar string
4541e49fc963SAndy Fiddamanis null, the previous string is used.
4542e49fc963SAndy Fiddaman.It Sy \&? Ns Ar string
4543e49fc963SAndy FiddamanSearch forward through history for a previous command containing
4544e49fc963SAndy Fiddaman.Ar string .
4545e49fc963SAndy Fiddaman.Ar string
4546e49fc963SAndy Fiddamanis terminated by a RETURN or NEWLINE.
4547e49fc963SAndy FiddamanIf string is preceded by a
4548e49fc963SAndy Fiddaman.Sy ^ ,
4549e49fc963SAndy Fiddamanthe matched line must begin with
4550e49fc963SAndy Fiddaman.Ar string .
4551e49fc963SAndy FiddamanIf
4552e49fc963SAndy Fiddaman.Ar string
4553e49fc963SAndy Fiddamanis null, the previous string is used.
4554e49fc963SAndy Fiddaman.Pp
4555e49fc963SAndy FiddamanSame as
4556e49fc963SAndy Fiddaman.Sy /
4557e49fc963SAndy Fiddamanexcept that search is in the forward direction.
4558e49fc963SAndy Fiddaman.It Sy n
4559c10c16deSRichard LoweSearch in the backwards direction for the next match of the last pattern to
4560e49fc963SAndy Fiddaman.Sy /
4561e49fc963SAndy Fiddamanor
4562e49fc963SAndy Fiddaman.Sy \&?
4563e49fc963SAndy Fiddamancommands.
4564e49fc963SAndy Fiddaman.It Sy N
4565e49fc963SAndy FiddamanSearch in the forward direction for next match of the last pattern to
4566e49fc963SAndy Fiddaman.Sy /
4567e49fc963SAndy Fiddamanor
4568e49fc963SAndy Fiddaman.Sy \&?
4569e49fc963SAndy Fiddamancommands.
4570e49fc963SAndy Fiddaman.El
4571e49fc963SAndy Fiddaman.Ss "Text Modification Edit Commands"
4572c10c16deSRichard LoweThe following commands modify the line:
4573e49fc963SAndy Fiddaman.Pp
4574e49fc963SAndy Fiddaman.Bl -tag -width Ar -compact
4575e49fc963SAndy Fiddaman.It Sy a
4576c10c16deSRichard LoweEnter input mode and enter text after the current character.
4577e49fc963SAndy Fiddaman.Pp
4578e49fc963SAndy Fiddaman.It Sy A
4579e49fc963SAndy FiddamanAppend text to the end of the line.
4580e49fc963SAndy FiddamanEquivalent to
4581e49fc963SAndy Fiddaman.Sy $a .
4582e49fc963SAndy Fiddaman.Pp
4583e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy c Ns Ar motion
4584e49fc963SAndy Fiddaman.It Sy c Ns Oo Ar count Oc Ns Ar motion
4585e49fc963SAndy FiddamanDelete current character through to the character that
4586e49fc963SAndy Fiddaman.Ar motion
4587e49fc963SAndy Fiddamanwould move the cursor to, and enter input mode.
4588e49fc963SAndy FiddamanIf
4589e49fc963SAndy Fiddaman.Ar motion
4590e49fc963SAndy Fiddamanis
4591e49fc963SAndy Fiddaman.Sy c ,
4592e49fc963SAndy Fiddamanthe entire line is deleted and input mode is entered.
4593e49fc963SAndy Fiddaman.Pp
4594e49fc963SAndy Fiddaman.It Sy C
4595e49fc963SAndy FiddamanDelete the current character through to the end of line and enter input mode.
4596e49fc963SAndy FiddamanEquivalent to
4597e49fc963SAndy Fiddaman.Sy c$ .
4598e49fc963SAndy Fiddaman.Pp
4599e49fc963SAndy Fiddaman.It Sy S
4600e49fc963SAndy FiddamanEquivalent to
4601e49fc963SAndy Fiddaman.Sy cc .
4602e49fc963SAndy Fiddaman.Pp
4603e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy s
4604c10c16deSRichard LoweReplace characters under the cursor in input mode.
4605e49fc963SAndy Fiddaman.Pp
4606e49fc963SAndy Fiddaman.It Sy D Ns Oo Ar count Oc Ns Sy d Ns Ar motion
4607e49fc963SAndy FiddamanDelete the current character through to the end of line.
4608e49fc963SAndy FiddamanEquivalent to
4609e49fc963SAndy Fiddaman.Sy d$ .
4610e49fc963SAndy Fiddaman.Pp
4611e49fc963SAndy Fiddaman.It Sy d Oo Ar count Oc Ns Ar motion
4612e49fc963SAndy FiddamanDelete current character through to the character that
4613e49fc963SAndy Fiddaman.Ar motion
4614e49fc963SAndy Fiddamanwould move to.
4615e49fc963SAndy FiddamanIf
4616e49fc963SAndy Fiddaman.Ar motion
4617e49fc963SAndy Fiddamanis
4618e49fc963SAndy Fiddaman.Sy d ,
4619e49fc963SAndy Fiddamanthe entire line is deleted.
4620e49fc963SAndy Fiddaman.Pp
4621e49fc963SAndy Fiddaman.It Sy i
4622c10c16deSRichard LoweEnter input mode and insert text before the current character.
4623e49fc963SAndy Fiddaman.Pp
4624e49fc963SAndy Fiddaman.It Sy I
4625e49fc963SAndy FiddamanInsert text before the beginning of the line.
4626e49fc963SAndy FiddamanEquivalent to
4627e49fc963SAndy Fiddaman.Sy 0i .
4628e49fc963SAndy Fiddaman.Pp
4629e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy P
4630c10c16deSRichard LowePlace the previous text modification before the cursor.
4631e49fc963SAndy Fiddaman.Pp
4632e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy p
4633c10c16deSRichard LowePlace the previous text modification after the cursor.
4634e49fc963SAndy Fiddaman.Pp
4635e49fc963SAndy Fiddaman.It Sy R
4636c10c16deSRichard LoweEnter input mode and replace characters on the screen with characters you type
4637c10c16deSRichard Loweoverlay fashion.
4638e49fc963SAndy Fiddaman.Pp
4639e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy r Ns Ar c
4640e49fc963SAndy FiddamanReplace the
4641e49fc963SAndy Fiddaman.Ar count
4642e49fc963SAndy Fiddamancharacters starting at the current cursor position with
4643e49fc963SAndy Fiddaman.Ar c ,
4644e49fc963SAndy Fiddamanand advance the cursor.
4645e49fc963SAndy Fiddaman.Pp
4646e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy x
4647c10c16deSRichard LoweDelete current character.
4648e49fc963SAndy Fiddaman.Pp
4649e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy X
4650c10c16deSRichard LoweDelete preceding character.
4651e49fc963SAndy Fiddaman.Pp
4652e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&.
4653c10c16deSRichard LoweRepeat the previous text modification command.
4654e49fc963SAndy Fiddaman.Pp
4655e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&~
4656e49fc963SAndy FiddamanInvert the case of the
4657e49fc963SAndy Fiddaman.Ar count
4658e49fc963SAndy Fiddamancharacters starting at the current cursor
4659c10c16deSRichard Loweposition and advance the cursor.
4660e49fc963SAndy Fiddaman.Pp
4661e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&_
4662e49fc963SAndy FiddamanCauses the
4663e49fc963SAndy Fiddaman.Ar count
4664e49fc963SAndy Fiddamanword of the previous command to be appended and input mode entered.
4665e49fc963SAndy FiddamanThe last word is used if
4666e49fc963SAndy Fiddaman.Ar count
4667e49fc963SAndy Fiddamanis omitted.
4668e49fc963SAndy Fiddaman.Pp
4669e49fc963SAndy Fiddaman.It Sy \&*
4670e49fc963SAndy FiddamanCauses an
4671e49fc963SAndy Fiddaman.Sy \&*
4672e49fc963SAndy Fiddamanto be appended to the current word and file name generation attempted.
4673e49fc963SAndy FiddamanIf no match is found, it rings the bell.
4674e49fc963SAndy FiddamanOtherwise, the word is replaced by the matching pattern and input mode is
4675e49fc963SAndy Fiddamanentered.
4676e49fc963SAndy Fiddaman.Pp
4677e49fc963SAndy Fiddaman.It Sy \e
4678c10c16deSRichard LoweCommand or file name completion as described in this manual page.
4679e49fc963SAndy Fiddaman.El
4680e49fc963SAndy Fiddaman.Ss "Other Edit Commands"
4681c10c16deSRichard LoweThe following miscellaneous edit commands are supported:
4682e49fc963SAndy Fiddaman.Pp
4683e49fc963SAndy Fiddaman.Bl -tag -width Ar -compact
4684e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy y Ns Ar motion
4685e49fc963SAndy Fiddaman.It Sy y Ns Oo Ar count Oc Ns Ar motion
4686e49fc963SAndy FiddamanYank the current character through to the character to which
4687e49fc963SAndy Fiddaman.Ar motion
4688e49fc963SAndy Fiddamanwould move the cursor.
4689e49fc963SAndy FiddamanPut the yanked characters in the delete buffer.
4690e49fc963SAndy FiddamanThe text and cursor position are unchanged.
4691e49fc963SAndy Fiddaman.Pp
4692e49fc963SAndy Fiddaman.It Sy yy
4693c10c16deSRichard LoweYank the current line.
4694e49fc963SAndy Fiddaman.Pp
4695e49fc963SAndy Fiddaman.It Sy Y
4696c10c16deSRichard LoweYank the current line from the current cursor location to the end of the line.
4697e49fc963SAndy FiddamanEquivalent to
4698e49fc963SAndy Fiddaman.Sy y$ .
4699e49fc963SAndy Fiddaman.Pp
4700e49fc963SAndy Fiddaman.It Sy u
4701c10c16deSRichard LoweUndo the last text modifying command.
4702e49fc963SAndy Fiddaman.Pp
4703e49fc963SAndy Fiddaman.It Sy U
4704c10c16deSRichard LoweUndo all the text modifying commands performed on current line.
4705e49fc963SAndy Fiddaman.Pp
4706e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy V
4707e49fc963SAndy FiddamanReturn the command:
4708e49fc963SAndy Fiddaman.Pp
4709e49fc963SAndy Fiddaman.D1 Ic hist Fl e No ${ Ns Ev VISUAL Ns :-${ Ns Ev EDITOR Ns :-vi}} Ar count
4710e49fc963SAndy Fiddaman.Pp
4711e49fc963SAndy Fiddamanin the input buffer.
4712e49fc963SAndy FiddamanIf
4713e49fc963SAndy Fiddaman.Ar count
4714e49fc963SAndy Fiddamanis omitted, the current line is used.
4715e49fc963SAndy Fiddaman.Pp
4716e49fc963SAndy Fiddaman.It Sy ^L
4717e49fc963SAndy FiddamanLine feed and print the current line.
4718e49fc963SAndy FiddamanThis command only works in control mode.
4719e49fc963SAndy Fiddaman.Pp
4720e49fc963SAndy Fiddaman.It Sy ^J
4721e49fc963SAndy FiddamanNew line.
4722e49fc963SAndy FiddamanExecute the current line, regardless of mode.
4723e49fc963SAndy Fiddaman.Pp
4724e49fc963SAndy Fiddaman.It Sy ^M
4725e49fc963SAndy FiddamanReturn.
4726e49fc963SAndy FiddamanExecute the current line, regardless of mode.
4727e49fc963SAndy Fiddaman.Pp
4728e49fc963SAndy Fiddaman.It Sy #
4729e49fc963SAndy FiddamanIf the first character of the command is a
4730e49fc963SAndy Fiddaman.Sy # ,
4731e49fc963SAndy Fiddamandelete this
4732e49fc963SAndy Fiddaman.Sy #
4733e49fc963SAndy Fiddamanand each
4734e49fc963SAndy Fiddaman.Sy #
4735e49fc963SAndy Fiddamanthat follows a NEWLINE.
4736e49fc963SAndy Fiddaman.Pp
4737e49fc963SAndy FiddamanOtherwise, send the line after inserting a
4738e49fc963SAndy Fiddaman.Sy #
4739e49fc963SAndy Fiddamanin front of each line in the command.
4740e49fc963SAndy Fiddaman.Pp
4741c10c16deSRichard LoweThis is command is useful for causing the current line to be inserted in the
4742c10c16deSRichard Lowehistory as a comment and un-commenting previously commented commands in the
4743c10c16deSRichard Lowehistory file.
4744e49fc963SAndy Fiddaman.Pp
4745e49fc963SAndy Fiddaman.It Oo Ar count Oc Ns Sy \&=
4746e49fc963SAndy FiddamanIf
4747e49fc963SAndy Fiddaman.Ar count
4748e49fc963SAndy Fiddamanis not specified, generate the list of matching commands or file names as
4749e49fc963SAndy Fiddamandescribed in this manual page.
4750e49fc963SAndy Fiddaman.Pp
4751e49fc963SAndy FiddamanOtherwise, replace the word at the current cursor location with the
4752e49fc963SAndy Fiddaman.Ar count
4753e49fc963SAndy Fiddamanitem from the most recently generated command or file list.
4754e49fc963SAndy FiddamanIf the cursor is not on a word, it is inserted after the current cursor
4755e49fc963SAndy Fiddamanlocation.
4756e49fc963SAndy Fiddaman.Pp
4757e49fc963SAndy Fiddaman.It Sy @ Ns Ar letter
4758e49fc963SAndy FiddamanSearch your alias list for an alias by the name
4759e49fc963SAndy Fiddaman.Ar letter .
4760e49fc963SAndy FiddamanIf an alias of this name is defined, insert its value on the input queue for
4761e49fc963SAndy Fiddamanprocessing.
4762e49fc963SAndy Fiddaman.Pp
4763e49fc963SAndy Fiddaman.It Sy ^V
4764c10c16deSRichard LoweDisplay version of the shell.
4765e49fc963SAndy Fiddaman.El
4766e49fc963SAndy Fiddaman.Ss "Built-in Commands"
4767e49fc963SAndy FiddamanThe following simple-commands are executed in the shell process.
4768e49fc963SAndy FiddamanInput and output redirection is permitted.
4769e49fc963SAndy FiddamanUnless otherwise indicated, the output is written on file descriptor
4770e49fc963SAndy Fiddaman.Sy 1
4771e49fc963SAndy Fiddamanand the exit status, when there is no syntax error, is
4772e49fc963SAndy Fiddaman.Sy 0 .
4773e49fc963SAndy FiddamanExcept for
4774e49fc963SAndy Fiddaman.Sy \&: ,
4775e49fc963SAndy Fiddaman.Sy true ,
4776e49fc963SAndy Fiddaman.Sy false ,
4777e49fc963SAndy Fiddaman.Sy echo ,
4778e49fc963SAndy Fiddaman.Sy newgrp ,
4779e49fc963SAndy Fiddamanand
4780e49fc963SAndy Fiddaman.Sy login ,
4781e49fc963SAndy Fiddamanall built-in commands accept
4782e49fc963SAndy Fiddaman.Fl -
4783e49fc963SAndy Fiddamanto indicate the end of options.
4784e49fc963SAndy FiddamanThey also interpret the option
4785e49fc963SAndy Fiddaman.Fl -man
4786e49fc963SAndy Fiddamanas a request to display the manual page onto standard error and
4787e49fc963SAndy Fiddaman.Fl \&?
4788e49fc963SAndy Fiddamanas a help request which prints a usage message on standard error.
4789e49fc963SAndy Fiddaman.Pp
4790e49fc963SAndy FiddamanIn the list below, commands that are preceded by one or two
4791e49fc963SAndy Fiddaman.Sy \&+
4792e49fc963SAndy Fiddamansymbols are special built-in commands and are treated specially in the
4793e49fc963SAndy Fiddamanfollowing ways:
4794e49fc963SAndy Fiddaman.Bl -enum -offset Ds
4795e49fc963SAndy Fiddaman.It
4796c10c16deSRichard LoweVariable assignment lists preceding the command remain in effect when the
4797c10c16deSRichard Lowecommand completes.
4798e49fc963SAndy Fiddaman.It
4799c10c16deSRichard LoweI/O redirections are processed after variable assignments.
4800e49fc963SAndy Fiddaman.It
4801c10c16deSRichard LoweErrors cause a script that contains them to abort.
4802e49fc963SAndy Fiddaman.It
4803c10c16deSRichard LoweThey are not valid function names.
4804e49fc963SAndy Fiddaman.It
4805e49fc963SAndy FiddamanWords following a command preceded by
4806e49fc963SAndy Fiddaman.Sy ++
4807e49fc963SAndy Fiddamanthat are in the format of a variable assignment are expanded with the same
4808e49fc963SAndy Fiddamanrules as a variable assignment.
4809e49fc963SAndy FiddamanThis means that tilde substitution is performed after the
4810e49fc963SAndy Fiddaman.Sy \&=
4811e49fc963SAndy Fiddamansign and field splitting and file name generation are not performed.
4812e49fc963SAndy Fiddaman.El
4813e49fc963SAndy Fiddaman.Pp
4814e49fc963SAndy Fiddaman.Bl -tag -width Ds -compact
4815e49fc963SAndy Fiddaman.It Sy + Ic \&: Op Ar arg No ...
4816c10c16deSRichard LoweThe command only expands parameters.
4817e49fc963SAndy Fiddaman.Pp
4818e49fc963SAndy Fiddaman.It Sy + Ic \&. Ar name Op Ar arg No ...
4819e49fc963SAndy FiddamanIf
4820e49fc963SAndy Fiddaman.Ar name
4821e49fc963SAndy Fiddamanis a function defined with the
4822e49fc963SAndy Fiddaman.Ic function Ar name
4823e49fc963SAndy Fiddamanreserved word syntax, the function is executed in the current environment
4824e49fc963SAndy Fiddaman.Pq as if it had been defined with the Ar name Ns Sy () No syntax .
4825e49fc963SAndy FiddamanOtherwise if
4826e49fc963SAndy Fiddaman.Ar name
4827e49fc963SAndy Fiddamanrefers to a file, the file is read in its entirety and the commands are
4828e49fc963SAndy Fiddamanexecuted in the current shell environment.
4829e49fc963SAndy FiddamanThe search path specified by
4830e49fc963SAndy Fiddaman.Ev PATH
4831e49fc963SAndy Fiddamanis used to find the directory containing the file.
4832e49fc963SAndy FiddamanIf any arguments
4833e49fc963SAndy Fiddaman.Ar arg
4834e49fc963SAndy Fiddamanare specified, they become the positional parameters while processing the
4835e49fc963SAndy Fiddaman.Ic \&.
4836e49fc963SAndy Fiddamancommand and the original positional parameters are restored upon completion.
4837e49fc963SAndy FiddamanOtherwise the positional parameters are unchanged.
4838e49fc963SAndy FiddamanThe exit status is the exit status of the last command executed.
4839e49fc963SAndy Fiddaman.Pp
4840e49fc963SAndy Fiddaman.It Sy ++ Ic alias Oo Fl ptx Oc Oo Ar name Ns Oo Sy = Ns Ar value Oc Oc No ...
4841e49fc963SAndy Fiddaman.Ic alias
4842e49fc963SAndy Fiddamanwith no arguments prints the list of aliases in the form
4843e49fc963SAndy Fiddaman.Ar name Ns Sy = Ns Ar value
4844e49fc963SAndy Fiddamanon standard output.
4845e49fc963SAndy FiddamanThe
4846e49fc963SAndy Fiddaman.Fl p
4847e49fc963SAndy Fiddamanoption causes the word alias to be inserted before each one.
4848e49fc963SAndy FiddamanWhen one or more arguments are specified, an alias is defined for each
4849e49fc963SAndy Fiddaman.Ar name
4850e49fc963SAndy Fiddamanwhose
4851e49fc963SAndy Fiddaman.Ar value
4852e49fc963SAndy Fiddamanis specified.
4853e49fc963SAndy FiddamanA trailing space in
4854e49fc963SAndy Fiddaman.Ar value
4855e49fc963SAndy Fiddamancauses the next word to be checked for alias substitution.
4856e49fc963SAndy FiddamanThe obsolete
4857e49fc963SAndy Fiddaman.Fl t
4858e49fc963SAndy Fiddamanoption is used to set and list tracked aliases.
4859e49fc963SAndy FiddamanThe value of a tracked alias is the full pathname corresponding to the
4860e49fc963SAndy Fiddamanspecified
4861e49fc963SAndy Fiddaman.Ar name .
4862e49fc963SAndy FiddamanThe value becomes undefined when the value of
4863e49fc963SAndy Fiddaman.Ev PATH
4864e49fc963SAndy Fiddamanis reset but the alias remains tracked.
4865e49fc963SAndy FiddamanWithout the
4866e49fc963SAndy Fiddaman.Fl t
4867e49fc963SAndy Fiddamanoption, for each
4868e49fc963SAndy Fiddaman.Ar name
4869e49fc963SAndy Fiddamanin the argument list for which no
4870e49fc963SAndy Fiddaman.Ar value
4871e49fc963SAndy Fiddamanis specified, the name and value of the alias is printed.
4872e49fc963SAndy FiddamanThe obsolete
4873e49fc963SAndy Fiddaman.Fl x
4874e49fc963SAndy Fiddamanoption has no effect.
4875e49fc963SAndy FiddamanThe exit status is
4876e49fc963SAndy Fiddaman.Sy non-zero
4877e49fc963SAndy Fiddamanif a
4878e49fc963SAndy Fiddaman.Ar name
4879e49fc963SAndy Fiddamanis specified, but no value, and no alias has been defined for the
4880e49fc963SAndy Fiddaman.Ar name .
4881e49fc963SAndy Fiddaman.Pp
4882e49fc963SAndy Fiddaman.It Ic bg Op Ar job No ...
4883e49fc963SAndy FiddamanThis command is only on systems that support job control.
4884e49fc963SAndy FiddamanPuts each specified
4885e49fc963SAndy Fiddaman.Ar job
4886e49fc963SAndy Fiddamaninto the background.
4887e49fc963SAndy FiddamanThe current job is put in the background if
4888e49fc963SAndy Fiddaman.Ar job
4889e49fc963SAndy Fiddamanis not specified.
4890e49fc963SAndy FiddamanSee the
4891e49fc963SAndy Fiddaman.Sx Jobs
4892e49fc963SAndy Fiddamansection of this manual page for a description of the format of
4893e49fc963SAndy Fiddaman.Ar job .
4894e49fc963SAndy Fiddaman.Pp
4895e49fc963SAndy Fiddaman.It Sy + Ic break Op Ar n
4896e49fc963SAndy FiddamanExit from the enclosing
4897e49fc963SAndy Fiddaman.Ic for ,
4898e49fc963SAndy Fiddaman.Ic while ,
4899e49fc963SAndy Fiddaman.Ic until ,
4900e49fc963SAndy Fiddamanor
4901e49fc963SAndy Fiddaman.Ic select
4902e49fc963SAndy Fiddamanloop, if any.
4903e49fc963SAndy FiddamanIf
4904e49fc963SAndy Fiddaman.Ar n
4905e49fc963SAndy Fiddamanis specified, then break
4906e49fc963SAndy Fiddaman.Ar n
4907e49fc963SAndy Fiddamanlevels.
4908e49fc963SAndy Fiddaman.Pp
4909e49fc963SAndy Fiddaman.It Ic builtin Oo Fl ds Oc Oo Fl f Ar file Oc Oo Ar name No ... Oc
4910e49fc963SAndy FiddamanIf
4911e49fc963SAndy Fiddaman.Ar name
4912e49fc963SAndy Fiddamanis not specified, and no
4913e49fc963SAndy Fiddaman.Fl f
4914e49fc963SAndy Fiddamanoption is specified, the built-ins are printed on standard output.
4915e49fc963SAndy FiddamanThe
4916e49fc963SAndy Fiddaman.Fl s
4917e49fc963SAndy Fiddamanoption prints only the special built-ins.
4918e49fc963SAndy FiddamanOtherwise, each
4919e49fc963SAndy Fiddaman.Ar name
4920e49fc963SAndy Fiddamanrepresents the pathname whose basename is the name of the built-in.
4921e49fc963SAndy FiddamanThe entry point function name is determined by prepending
4922e49fc963SAndy Fiddaman.Ar b_
4923e49fc963SAndy Fiddamanto the built-in name.
4924e49fc963SAndy FiddamanA built-in specified by a pathname will only be executed when that pathname
4925e49fc963SAndy Fiddamanwould be found during the path search.
4926e49fc963SAndy FiddamanBuilt-ins found in libraries loaded via the
4927e49fc963SAndy Fiddaman.Pa \&.paths
4928e49fc963SAndy Fiddamanfile will be associated with the pathname of the directory containing the
4929e49fc963SAndy Fiddaman.Pa \&.paths
4930b30d1939SAndy Fiddamanfile.
4931e49fc963SAndy Fiddaman.Pp
4932e49fc963SAndy FiddamanThe ISO C/C++ prototype is
4933e49fc963SAndy Fiddaman.Ft int
4934e49fc963SAndy Fiddaman.Fo b_mycommand
4935e49fc963SAndy Fiddaman.Fa "int argc"
4936e49fc963SAndy Fiddaman.Fa "char **argv"
4937e49fc963SAndy Fiddaman.Fa "Shbltin_t *context"
4938e49fc963SAndy Fiddaman.Fc
4939e49fc963SAndy Fiddamanfor the built-in command
4940e49fc963SAndy Fiddaman.Ic mycommand
4941e49fc963SAndy Fiddamanwhere
4942e49fc963SAndy Fiddaman.Fa argv
4943e49fc963SAndy Fiddamanis an array of
4944e49fc963SAndy Fiddaman.Fa argc
4945e49fc963SAndy Fiddamanelements and
4946e49fc963SAndy Fiddaman.Fa context
4947e49fc963SAndy Fiddamanis an optional pointer to a
4948e49fc963SAndy Fiddaman.Vt Shbltin_t
4949e49fc963SAndy Fiddamanstructure as described in
4950e49fc963SAndy Fiddaman.In ast/shell.h
4951e49fc963SAndy FiddamanSpecial built-ins cannot be bound to a pathname or deleted.
4952e49fc963SAndy FiddamanThe
4953e49fc963SAndy Fiddaman.Fl d
4954e49fc963SAndy Fiddamanoption deletes each of the specified built-ins.
4955e49fc963SAndy FiddamanOn systems that support dynamic loading, the
4956e49fc963SAndy Fiddaman.Fl f
4957e49fc963SAndy Fiddamanoption names a shared library containing the code for built-ins.
4958e49fc963SAndy FiddamanThe shared library prefix and/or suffix, which depend on the system, can be
4959e49fc963SAndy Fiddamanomitted.
4960e49fc963SAndy FiddamanOnce a library is loaded, its symbols become available for subsequent
4961e49fc963SAndy Fiddamaninvocations of
4962e49fc963SAndy Fiddaman.Ic builtin .
4963e49fc963SAndy FiddamanMultiple libraries can be specified with separate invocations of the
4964e49fc963SAndy Fiddaman.Ic builtin
4965e49fc963SAndy Fiddamancommand.
4966e49fc963SAndy FiddamanLibraries are searched in the reverse order in which they are specified.
4967e49fc963SAndy FiddamanWhen a library is loaded, it looks for a function in the library whose name is
4968e49fc963SAndy Fiddaman.Fn lib_init
4969e49fc963SAndy Fiddamanand invokes this function with an argument of
4970e49fc963SAndy Fiddaman.Sy 0 .
4971e49fc963SAndy Fiddaman.Pp
4972e49fc963SAndy Fiddaman.It Ic cd Oo Fl LP Oc Op Ar arg
4973e49fc963SAndy Fiddaman.It Ic cd Oo Fl LP Oc Ar old Ar new
4974c10c16deSRichard LoweThis command has two forms.
4975e49fc963SAndy Fiddaman.Pp
4976e49fc963SAndy FiddamanIn the first form it changes the current directory to
4977e49fc963SAndy Fiddaman.Ar arg .
4978e49fc963SAndy FiddamanIf
4979e49fc963SAndy Fiddaman.Ar arg
4980e49fc963SAndy Fiddamanis a literal
4981e49fc963SAndy Fiddaman.Sy \&- ,
4982e49fc963SAndy Fiddamanthe directory is changed to the previous directory.
4983e49fc963SAndy FiddamanThe shell variable
4984e49fc963SAndy Fiddaman.Ev HOME
4985e49fc963SAndy Fiddamanis the default
4986e49fc963SAndy Fiddaman.Ar arg .
4987e49fc963SAndy FiddamanThe variable
4988e49fc963SAndy Fiddaman.Ev PWD
4989e49fc963SAndy Fiddamanis set to the current directory.
4990e49fc963SAndy FiddamanThe shell variable
4991e49fc963SAndy Fiddaman.Ev CDPATH
4992e49fc963SAndy Fiddamandefines the search path for the directory containing
4993e49fc963SAndy Fiddaman.Ar arg .
4994e49fc963SAndy FiddamanAlternative directory names are
4995e49fc963SAndy Fiddamanseparated by a colon
4996e49fc963SAndy Fiddaman.Pq Sy \&: .
4997e49fc963SAndy FiddamanThe default path is
4998e49fc963SAndy Fiddaman.Dv NULL
4999e49fc963SAndy Fiddaman(specifying the current directory).
5000e49fc963SAndy FiddamanThe current directory is specified by a null path name, which can appear
5001e49fc963SAndy Fiddamanimmediately after the equal sign or between the colon delimiters anywhere else
5002e49fc963SAndy Fiddamanin the path list.
5003e49fc963SAndy FiddamanIf
5004e49fc963SAndy Fiddaman.Ar arg
5005e49fc963SAndy Fiddamanbegins with a
5006e49fc963SAndy Fiddaman.Sy / ,
5007e49fc963SAndy Fiddamanthe search path is not used.
5008e49fc963SAndy FiddamanOtherwise, each directory in the path is searched for
5009e49fc963SAndy Fiddaman.Ar arg .
5010e49fc963SAndy Fiddaman.Pp
5011e49fc963SAndy FiddamanThe second form of
5012e49fc963SAndy Fiddaman.Ic cd
5013e49fc963SAndy Fiddamansubstitutes the string
5014e49fc963SAndy Fiddaman.Ar new
5015e49fc963SAndy Fiddamanfor the string
5016e49fc963SAndy Fiddaman.Ar old
5017e49fc963SAndy Fiddamanin the current directory name,
5018e49fc963SAndy Fiddaman.Ev PWD ,
5019e49fc963SAndy Fiddamanand tries to change to this new directory.
5020e49fc963SAndy Fiddaman.Pp
5021e49fc963SAndy FiddamanBy default, symbolic link names are treated literally when finding the
5022e49fc963SAndy Fiddamandirectory name.
5023e49fc963SAndy FiddamanThis is equivalent to the
5024e49fc963SAndy Fiddaman.Fl L
5025e49fc963SAndy Fiddamanoption.
5026e49fc963SAndy FiddamanThe
5027e49fc963SAndy Fiddaman.Fl P
5028e49fc963SAndy Fiddamanoption causes symbolic links to be resolved when determining the directory.
5029e49fc963SAndy FiddamanThe last instance of
5030e49fc963SAndy Fiddaman.Fl L
5031e49fc963SAndy Fiddamanor
5032e49fc963SAndy Fiddaman.Fl P
5033e49fc963SAndy Fiddamanon the command line determines which method is used.
5034e49fc963SAndy FiddamanThe
5035e49fc963SAndy Fiddaman.Ic cd
5036e49fc963SAndy Fiddamancommand cannot be executed by
5037e49fc963SAndy Fiddaman.Nm rksh93 .
5038e49fc963SAndy Fiddaman.Pp
5039e49fc963SAndy Fiddaman.It Ic command Oo Fl pvVx Oc Ar name Op Ar arg No ...
5040e49fc963SAndy FiddamanWithout the
5041e49fc963SAndy Fiddaman.Fl v
5042e49fc963SAndy Fiddamanor
5043e49fc963SAndy Fiddaman.Fl V
5044e49fc963SAndy Fiddamanoptions, executes
5045e49fc963SAndy Fiddaman.Ar name
5046e49fc963SAndy Fiddamanwith the arguments specified by
5047e49fc963SAndy Fiddaman.Ar arg .
5048e49fc963SAndy Fiddaman.Pp
5049e49fc963SAndy FiddamanThe
5050e49fc963SAndy Fiddaman.Fl p
5051e49fc963SAndy Fiddamanoption causes a default path to be searched rather than the one defined by the
5052e49fc963SAndy Fiddamanvalue of
5053e49fc963SAndy Fiddaman.Ev PATH .
5054e49fc963SAndy FiddamanFunctions are not searched when finding
5055e49fc963SAndy Fiddaman.Ar name .
5056e49fc963SAndy FiddamanIn addition, if
5057e49fc963SAndy Fiddaman.Ar name
5058e49fc963SAndy Fiddamanrefers to a special built-in, none of the special properties associated with
5059e49fc963SAndy Fiddamanthe leading daggers are honored.
5060e49fc963SAndy FiddamanFor example, the predefined alias
5061e49fc963SAndy Fiddaman.Sy redirect='command exec'
5062e49fc963SAndy Fiddamanprevents a script from terminating when an invalid redirection is specified.
5063e49fc963SAndy Fiddaman.Pp
5064e49fc963SAndy FiddamanWith the
5065e49fc963SAndy Fiddaman.Fl x
5066e49fc963SAndy Fiddamanoption, if command execution would result in a failure because there are too
5067e49fc963SAndy Fiddamanmany arguments,
5068e49fc963SAndy Fiddaman.Er E2BIG ,
5069e49fc963SAndy Fiddamanthe shell invokes command
5070e49fc963SAndy Fiddaman.Ar name
5071e49fc963SAndy Fiddamanmultiple times with a subset of the arguments on each invocation.
5072e49fc963SAndy FiddamanArguments that occur prior to the first word that expands to multiple arguments
5073e49fc963SAndy Fiddamanand after the last word that expands to multiple arguments are passed on each
5074e49fc963SAndy Fiddamaninvocation.
5075e49fc963SAndy FiddamanThe exit status is the maximum invocation exit status.
5076e49fc963SAndy Fiddaman.Pp
5077e49fc963SAndy FiddamanWith the
5078e49fc963SAndy Fiddaman.Fl v
5079e49fc963SAndy Fiddamanoption,
5080e49fc963SAndy Fiddaman.Ic command
5081e49fc963SAndy Fiddamanis equivalent to the built-in
5082e49fc963SAndy Fiddaman.Ic whence
5083e49fc963SAndy Fiddamancommand described in this section.
5084e49fc963SAndy FiddamanThe
5085e49fc963SAndy Fiddaman.Fl V
5086e49fc963SAndy Fiddamanoption causes
5087e49fc963SAndy Fiddaman.Ic command
5088e49fc963SAndy Fiddamanto act like
5089e49fc963SAndy Fiddaman.Ic whence -v .
5090e49fc963SAndy Fiddaman.Pp
5091e49fc963SAndy Fiddaman.It Sy + Ic continue Op Ar n
5092e49fc963SAndy FiddamanResumes the next iteration of the enclosing
5093e49fc963SAndy Fiddaman.Ic for ,
5094e49fc963SAndy Fiddaman.Ic while ,
5095e49fc963SAndy Fiddaman.Ic until ,
5096e49fc963SAndy Fiddamanor
5097e49fc963SAndy Fiddaman.Ic select
5098e49fc963SAndy Fiddamanloop.
5099e49fc963SAndy FiddamanIf
5100e49fc963SAndy Fiddaman.Ar n
5101e49fc963SAndy Fiddamanis specified, then resume at the
5102e49fc963SAndy Fiddaman.Ar n Ns No th
5103e49fc963SAndy Fiddamanenclosing loop.
5104e49fc963SAndy Fiddaman.Pp
5105e49fc963SAndy Fiddaman.It Ic disown Op Ar job No ...
5106e49fc963SAndy FiddamanCauses the shell not to send a
5107e49fc963SAndy Fiddaman.Sy HUP
5108e49fc963SAndy Fiddamansignal to each specified
5109e49fc963SAndy Fiddaman.Ar job ,
5110e49fc963SAndy Fiddamanor all active jobs if
5111e49fc963SAndy Fiddaman.Ar job
5112e49fc963SAndy Fiddamanis omitted, when a login shell terminates.
5113e49fc963SAndy Fiddaman.Pp
5114e49fc963SAndy Fiddaman.It Ic echo Op arg No ...
5115e49fc963SAndy FiddamanWhen the first
5116e49fc963SAndy Fiddaman.Ar arg
5117e49fc963SAndy Fiddamandoes not begin with a
5118e49fc963SAndy Fiddaman.Sy - ,
5119e49fc963SAndy Fiddamanand none of the arguments contain a backslash
5120e49fc963SAndy Fiddaman.Pq Sy \e ,
5121e49fc963SAndy Fiddamanprints each of its arguments separated by a SPACE and terminated by a NEWLINE.
5122e49fc963SAndy FiddamanOtherwise, the behavior of
5123e49fc963SAndy Fiddaman.Ic echo
5124e49fc963SAndy Fiddamanis system dependent and
5125e49fc963SAndy Fiddaman.Ic print
5126e49fc963SAndy Fiddamanor
5127e49fc963SAndy Fiddaman.Ic printf
5128e49fc963SAndy Fiddamandescribed in this section should be used.
5129e49fc963SAndy FiddamanSee
5130e49fc963SAndy Fiddaman.Xr echo 1
5131e49fc963SAndy Fiddamanfor usage and description.
5132e49fc963SAndy Fiddaman.Pp
5133e49fc963SAndy Fiddaman.It Sy ++ Ic enum Oo Fl i Oc Ar type Ns Op Sy =( Ns Ar value No ... Ns Sy \&)
5134b30d1939SAndy FiddamanCreates a declaration command named type that is an integer type that allows
5135e49fc963SAndy Fiddamanone of the specified values as enumeration names.
5136e49fc963SAndy FiddamanIf
5137e49fc963SAndy Fiddaman.Sy =( Ns Ar value No ... Ns Sy \&)
5138e49fc963SAndy Fiddamanis omitted, then type must be an indexed array variable with at least two
5139e49fc963SAndy Fiddamanelements and the values are taken from this array variable.
5140e49fc963SAndy FiddamanIf
5141e49fc963SAndy Fiddaman.Fl i
5142e49fc963SAndy Fiddamanis specified the values are case insensitive.
5143e49fc963SAndy Fiddaman.Pp
5144e49fc963SAndy Fiddaman.It Sy + Ic eval Op arg No ...
5145c10c16deSRichard LoweThe arguments are read as input to the shell and the resulting commands are
5146c10c16deSRichard Loweexecuted.
5147e49fc963SAndy Fiddaman.Pp
5148e49fc963SAndy Fiddaman.It Sy + Ic exec Oo Fl c Oc Oo Fl a Ar name No ... Oc Op Ar arg No ...
5149e49fc963SAndy FiddamanIf
5150e49fc963SAndy Fiddaman.Ar arg
5151e49fc963SAndy Fiddamanis specified, the command specified by the arguments is executed in place of
5152e49fc963SAndy Fiddamanthis shell without creating a new process.
5153e49fc963SAndy FiddamanThe
5154e49fc963SAndy Fiddaman.Fl c
5155e49fc963SAndy Fiddamanoption causes the environment to be cleared before applying variable
5156e49fc963SAndy Fiddamanassignments associated with the exec invocation.
5157e49fc963SAndy FiddamanThe
5158e49fc963SAndy Fiddaman.Fl a
5159e49fc963SAndy Fiddamanoption causes
5160e49fc963SAndy Fiddaman.Ar name
5161e49fc963SAndy Fiddamanrather than the first
5162e49fc963SAndy Fiddaman.Ar arg ,
5163e49fc963SAndy Fiddamanto become
5164e49fc963SAndy Fiddaman.Fa argv[0]
5165e49fc963SAndy Fiddamanfor the new process.
5166e49fc963SAndy FiddamanInput and output arguments can appear and affect the current process.
5167e49fc963SAndy FiddamanIf
5168e49fc963SAndy Fiddaman.Ar arg
5169e49fc963SAndy Fiddamanis not specified, the effect of this command is to modify file descriptors as
5170e49fc963SAndy Fiddamanprescribed by the input/output redirection list.
5171e49fc963SAndy FiddamanIn this case, any file descriptor numbers greater than
5172e49fc963SAndy Fiddaman.Sy 2
5173e49fc963SAndy Fiddamanthat are opened with this mechanism are closed when invoking another program.
5174e49fc963SAndy Fiddaman.Pp
5175e49fc963SAndy Fiddaman.It Sy + Ic exit Op Ar n
5176e49fc963SAndy FiddamanCauses the shell to exit with the exit status specified by
5177e49fc963SAndy Fiddaman.Ar n .
5178e49fc963SAndy FiddamanThe value is the least significant 8 bits of the specified status.
5179e49fc963SAndy FiddamanIf
5180e49fc963SAndy Fiddaman.Ar n
5181e49fc963SAndy Fiddamanis omitted, then the exit status is that of the last command executed.
5182e49fc963SAndy FiddamanAn end-of-file also causes the shell to exit except for a shell which has the
5183e49fc963SAndy Fiddaman.Sy ignoreeof
5184e49fc963SAndy Fiddamanoption turned on.
5185e49fc963SAndy FiddamanSee
5186e49fc963SAndy Fiddaman.Ic set .
5187e49fc963SAndy Fiddaman.Pp
5188e49fc963SAndy Fiddaman.It Sy ++ Ic export Oo Fl p Oc Oo Ar name Ns Oo Sy = Ns Ar value Oc Oc No ...
5189e49fc963SAndy FiddamanIf
5190e49fc963SAndy Fiddaman.Ar name
5191e49fc963SAndy Fiddamanis not specified, the names and values of each variable with the export
5192e49fc963SAndy Fiddamanattribute are printed with the values quoted in a manner that allows them to be
5193e49fc963SAndy Fiddamanre-entered.
5194e49fc963SAndy FiddamanThe
5195e49fc963SAndy Fiddaman.Ic export
5196e49fc963SAndy Fiddamancommand is the same as
5197e49fc963SAndy Fiddaman.Ic typeset -x
5198e49fc963SAndy Fiddamanexcept that if you use
5199e49fc963SAndy Fiddaman.Ic export
5200e49fc963SAndy Fiddamanwithin a function, no local variable is created.
5201e49fc963SAndy FiddamanThe
5202e49fc963SAndy Fiddaman.Fl p
5203e49fc963SAndy Fiddamanoption causes the word export to be inserted before each one.
5204e49fc963SAndy FiddamanOtherwise, the specified
5205e49fc963SAndy Fiddaman.Ar name
5206e49fc963SAndy Fiddamans are marked for automatic export to the environment of subsequently-executed
5207e49fc963SAndy Fiddamancommands.
5208e49fc963SAndy Fiddaman.Pp
5209e49fc963SAndy Fiddaman.It Ic false
5210e49fc963SAndy FiddamanDoes nothing, and exits
5211e49fc963SAndy Fiddaman.Sy 1 .
5212e49fc963SAndy FiddamanUsed with
5213e49fc963SAndy Fiddaman.Ic until
5214e49fc963SAndy Fiddamanfor infinite loops.
5215e49fc963SAndy Fiddaman.Pp
5216e49fc963SAndy Fiddaman.It Ic fg Op Ar job No ...
5217e49fc963SAndy FiddamanThis command is only on systems that support job control.
5218e49fc963SAndy FiddamanEach
5219e49fc963SAndy Fiddaman.Ar job
5220c10c16deSRichard Lowespecified is brought to the foreground and waited for in the specified order.
5221e49fc963SAndy FiddamanOtherwise, the current job is brought into the foreground.
5222e49fc963SAndy FiddamanSee
5223e49fc963SAndy Fiddaman.Sx Jobs
5224e49fc963SAndy Fiddamanfor a description of the format of
5225e49fc963SAndy Fiddaman.Ar job .
5226e49fc963SAndy Fiddaman.Pp
5227e49fc963SAndy Fiddaman.It Ic getconf Oo Ar name Oo Ar pathname Oc Oc
5228c10c16deSRichard LowePrints the current value of the configuration parameter specified by
5229e49fc963SAndy Fiddaman.Ar name .
5230e49fc963SAndy FiddamanThe configuration parameters are defined by the IEEE POSIX 1003.1
5231e49fc963SAndy Fiddamanand IEEE POSIX 1003.2 standards.
5232e49fc963SAndy FiddamanSee
5233e49fc963SAndy Fiddaman.Xr pathconf 2
5234e49fc963SAndy Fiddamanand
5235e49fc963SAndy Fiddaman.Xr sysconf 3C .
5236e49fc963SAndy Fiddaman.Pp
5237e49fc963SAndy FiddamanThe
5238e49fc963SAndy Fiddaman.Ar pathname
5239e49fc963SAndy Fiddamanargument is required for parameters whose value depends on the location in the
5240e49fc963SAndy Fiddamanfile system.
5241e49fc963SAndy FiddamanIf no arguments are specified,
5242e49fc963SAndy Fiddaman.Ic getconf
5243e49fc963SAndy Fiddamanprints the names and values of the current configuration parameters.
5244e49fc963SAndy FiddamanThe pathname
5245e49fc963SAndy Fiddaman.Pa /
5246e49fc963SAndy Fiddamanis used for each of the parameters that requires
5247e49fc963SAndy Fiddaman.Ar pathname .
5248e49fc963SAndy Fiddaman.Pp
5249e49fc963SAndy Fiddaman.It Ic getopts Oo Fl a Ar name Oc Ar optstring Ar vname Op Ar arg No ...
5250e49fc963SAndy FiddamanChecks
5251e49fc963SAndy Fiddaman.Ar arg
5252e49fc963SAndy Fiddamanfor legal options.
5253e49fc963SAndy FiddamanIf
5254e49fc963SAndy Fiddaman.Ar arg
5255e49fc963SAndy Fiddamanis omitted, the positional parameters are used.
5256e49fc963SAndy FiddamanAn option argument begins with a
5257e49fc963SAndy Fiddaman.Sy \&+
5258e49fc963SAndy Fiddamanor a
5259e49fc963SAndy Fiddaman.Sy \&- .
5260e49fc963SAndy FiddamanAn option that does not begin with
5261e49fc963SAndy Fiddaman.Sy \&+
5262e49fc963SAndy Fiddamanor
5263e49fc963SAndy Fiddaman.Sy \&-
5264e49fc963SAndy Fiddamanor the argument
5265e49fc963SAndy Fiddaman.Fl \-
5266e49fc963SAndy Fiddamanends the options.
5267e49fc963SAndy FiddamanOptions beginning with
5268e49fc963SAndy Fiddaman.Sy \&+
5269e49fc963SAndy Fiddamanare only recognized when
5270e49fc963SAndy Fiddaman.Ar optstring
5271e49fc963SAndy Fiddamanbegins with a
5272e49fc963SAndy Fiddaman.Sy \&+ .
5273e49fc963SAndy Fiddaman.Ar optstring
5274e49fc963SAndy Fiddamancontains the letters that
5275e49fc963SAndy Fiddaman.Sy getopts
5276e49fc963SAndy Fiddamanrecognizes.
5277e49fc963SAndy FiddamanIf a letter is followed by a
5278e49fc963SAndy Fiddaman.Sy \&: ,
5279e49fc963SAndy Fiddamanthat option is expected to have an argument.
5280e49fc963SAndy FiddamanThe options can be separated from the argument by blanks.
5281e49fc963SAndy FiddamanThe option
5282e49fc963SAndy Fiddaman.Fl \&?
5283e49fc963SAndy Fiddamancauses
5284e49fc963SAndy Fiddaman.Ic getopts
5285e49fc963SAndy Fiddamanto generate a usage message on standard error.
5286e49fc963SAndy FiddamanThe
5287e49fc963SAndy Fiddaman.Fl a
5288e49fc963SAndy Fiddamanoption can be used to specify the name to use for the usage message, which
5289e49fc963SAndy Fiddamandefaults to
5290e49fc963SAndy Fiddaman.Sy $0 .
5291e49fc963SAndy Fiddaman.Ic getopts
5292e49fc963SAndy Fiddamanplaces the next option letter it finds inside variable
5293e49fc963SAndy Fiddaman.Ar vname
5294e49fc963SAndy Fiddamaneach time it is invoked.
5295e49fc963SAndy FiddamanThe option letter is prepended with a
5296e49fc963SAndy Fiddaman.Sy \&+
5297e49fc963SAndy Fiddamanwhen
5298e49fc963SAndy Fiddaman.Ar arg
5299e49fc963SAndy Fiddamanbegins with a
5300e49fc963SAndy Fiddaman.Sy \&+ .
5301e49fc963SAndy FiddamanThe index of the next
5302e49fc963SAndy Fiddaman.Ar arg
5303e49fc963SAndy Fiddamanis stored in
5304e49fc963SAndy Fiddaman.Ev OPTIND .
5305e49fc963SAndy FiddamanThe option argument, if any, gets stored in
5306e49fc963SAndy Fiddaman.Ev OPTARG .
5307e49fc963SAndy FiddamanA leading \&: in
5308e49fc963SAndy Fiddaman.Ar optstring
5309e49fc963SAndy Fiddamancauses
5310e49fc963SAndy Fiddaman.Ic getopts
5311e49fc963SAndy Fiddamanto store the letter of an invalid option in
5312e49fc963SAndy Fiddaman.Ev OPTARG ,
5313e49fc963SAndy Fiddamanand to set
5314e49fc963SAndy Fiddaman.Ar vname
5315e49fc963SAndy Fiddamanto
5316e49fc963SAndy Fiddaman.Sy \&?
5317e49fc963SAndy Fiddamanfor an unknown option and to
5318e49fc963SAndy Fiddaman.Sy \&:
5319e49fc963SAndy Fiddamanwhen a required option argument is missing.
5320e49fc963SAndy FiddamanOtherwise,
5321e49fc963SAndy Fiddaman.Ic getopts
5322e49fc963SAndy Fiddamanprints an error message.
5323e49fc963SAndy FiddamanThe exit status is
5324e49fc963SAndy Fiddaman.Sy non-zero
5325e49fc963SAndy Fiddamanwhen there are no more options.
5326e49fc963SAndy FiddamanThere is no way to specify any of the options
5327e49fc963SAndy Fiddaman.Sy \&: ,
5328e49fc963SAndy Fiddaman.Sy \&+ ,
5329e49fc963SAndy Fiddaman.Sy \&- ,
5330e49fc963SAndy Fiddaman.Sy \&? ,
5331e49fc963SAndy Fiddaman.Sy \&[ ,
5332e49fc963SAndy Fiddamanand
5333e49fc963SAndy Fiddaman.Sy \&] .
5334e49fc963SAndy FiddamanThe option
5335e49fc963SAndy Fiddaman.Sy \&#
5336e49fc963SAndy Fiddamancan only be specified as the first option.
5337e49fc963SAndy Fiddaman.Pp
5338e49fc963SAndy Fiddaman.It Ic hist Oo Fl e Ar ename Oc Oo Fl nlr Oc Oo Ar first Oo Ar last Oc Oc
5339e49fc963SAndy Fiddaman.It Ic hist Fl s Oo Ar old Ns Sy = Ns Ar new Oc Oo Ar command Oc
5340e49fc963SAndy FiddamanIn the first form, a range of commands from
5341e49fc963SAndy Fiddaman.Ar first
5342e49fc963SAndy Fiddamanto
5343e49fc963SAndy Fiddaman.Ar last
5344e49fc963SAndy Fiddamanis selected from the last
5345e49fc963SAndy Fiddaman.Ev HISTSIZE
5346e49fc963SAndy Fiddamancommands that were typed at the terminal.
5347e49fc963SAndy FiddamanThe arguments
5348e49fc963SAndy Fiddaman.Ar first
5349e49fc963SAndy Fiddamanand
5350e49fc963SAndy Fiddaman.Ar last
5351e49fc963SAndy Fiddamancan be specified as a number or as a string.
5352e49fc963SAndy FiddamanA string is used to locate the most recent command starting with the
5353e49fc963SAndy Fiddamanspecified string.
5354e49fc963SAndy FiddamanA negative number is used as an offset to the current command number.
5355e49fc963SAndy FiddamanIf the
5356e49fc963SAndy Fiddaman.Fl l
5357e49fc963SAndy Fiddamanoption is selected, the commands are listed on standard output.
5358e49fc963SAndy FiddamanOtherwise, the editor program
5359e49fc963SAndy Fiddaman.Ar ename
5360e49fc963SAndy Fiddamanis invoked on a file containing these keyboard commands.
5361e49fc963SAndy FiddamanIf
5362e49fc963SAndy Fiddaman.Ar ename
5363e49fc963SAndy Fiddamanis not supplied, then the value of the variable
5364e49fc963SAndy Fiddaman.Ev HISTEDIT
5365e49fc963SAndy Fiddamanis used.
5366e49fc963SAndy FiddamanIf
5367e49fc963SAndy Fiddaman.Ev HISTEDIT
5368e49fc963SAndy Fiddamanis not set, then
5369e49fc963SAndy Fiddaman.Ev FCEDIT
5370e49fc963SAndy Fiddaman.Pq default Pa /bin/ed
5371e49fc963SAndy Fiddamanis used as the editor.
5372e49fc963SAndy FiddamanWhen editing is complete, the edited command(s) is executed if the changes have
5373e49fc963SAndy Fiddamanbeen saved.
5374e49fc963SAndy FiddamanIf
5375e49fc963SAndy Fiddaman.Ar last
5376e49fc963SAndy Fiddamanis not specified, then it is set to
5377e49fc963SAndy Fiddaman.Ar first .
5378e49fc963SAndy FiddamanIf
5379e49fc963SAndy Fiddaman.Ar first
5380e49fc963SAndy Fiddamanis not specified, the default is the previous command for editing and
5381e49fc963SAndy Fiddaman.Fl 16
5382e49fc963SAndy Fiddamanfor listing.
5383e49fc963SAndy FiddamanThe option
5384e49fc963SAndy Fiddaman.Fl r
5385e49fc963SAndy Fiddamanreverses the order of the commands and the option
5386e49fc963SAndy Fiddaman.Fl n
5387e49fc963SAndy Fiddamansuppresses command numbers when listing.
5388e49fc963SAndy FiddamanIn the second form,
5389e49fc963SAndy Fiddaman.Ar command
5390e49fc963SAndy Fiddamanis interpreted as
5391e49fc963SAndy Fiddaman.Ar first
5392e49fc963SAndy Fiddamandescribed in this section and defaults to the last command executed.
5393e49fc963SAndy FiddamanThe resulting command is executed after the optional substitution
5394e49fc963SAndy Fiddaman.Ar old Ns Sy = Ns Ar new
5395e49fc963SAndy Fiddamanis performed.
5396e49fc963SAndy Fiddaman.Pp
5397e49fc963SAndy Fiddaman.It Ic jobs Fl lnp Op Ar job No ...
5398e49fc963SAndy FiddamanLists information about each specified job, or all active jobs if
5399e49fc963SAndy Fiddaman.Ar job
5400e49fc963SAndy Fiddamanis omitted.
5401e49fc963SAndy FiddamanThe
5402e49fc963SAndy Fiddaman.Fl l
5403e49fc963SAndy Fiddamanoption lists process ids in addition to the normal information.
5404e49fc963SAndy FiddamanThe
5405e49fc963SAndy Fiddaman.Fl n
5406e49fc963SAndy Fiddamanoption only displays jobs that have stopped or exited since last notified.
5407e49fc963SAndy FiddamanThe
5408e49fc963SAndy Fiddaman.Fl p
5409e49fc963SAndy Fiddamanoption causes only the process group to be listed.
5410e49fc963SAndy FiddamanSee
5411e49fc963SAndy Fiddaman.Sx Jobs
5412e49fc963SAndy Fiddamanfor a description of the format of
5413e49fc963SAndy Fiddaman.Ar job .
5414e49fc963SAndy Fiddaman.Pp
5415e49fc963SAndy Fiddaman.It Ic kill Oo Fl s Ar signame Oc Ar job No ...
5416e49fc963SAndy Fiddaman.It Ic kill Oo Fl n Ar signum Oc Ar job No ...
5417e49fc963SAndy Fiddaman.It Ic kill Fl Ll Op Ar sig No ...
5418e49fc963SAndy FiddamanSends either the
5419e49fc963SAndy Fiddaman.Sy TERM
5420e49fc963SAndy Fiddaman(terminate) signal or the specified signal to the specified jobs or processes.
5421e49fc963SAndy FiddamanSignals are either specified by number with the
5422e49fc963SAndy Fiddaman.Fl n
5423e49fc963SAndy Fiddamanoption or by name with the
5424e49fc963SAndy Fiddaman.Fl s
5425e49fc963SAndy Fiddamanoption
5426e49fc963SAndy Fiddaman.Po
5427e49fc963SAndy Fiddamanas specified in
5428e49fc963SAndy Fiddaman.In signal.h ,
5429e49fc963SAndy Fiddamanstripped of the prefix
5430e49fc963SAndy Fiddaman.Ql SIG
5431e49fc963SAndy Fiddamanwith the exception that
5432e49fc963SAndy Fiddaman.Sy SIGCLD
5433e49fc963SAndy Fiddamanis named
5434e49fc963SAndy Fiddaman.Sy CHLD
5435e49fc963SAndy Fiddaman.Pc .
5436e49fc963SAndy FiddamanFor backwards compatibility, the
5437e49fc963SAndy Fiddaman.Sy n
5438e49fc963SAndy Fiddamanand
5439e49fc963SAndy Fiddaman.Sy s
5440e49fc963SAndy Fiddamancan be omitted and the number or name placed immediately after the
5441e49fc963SAndy Fiddaman.Fl .
5442e49fc963SAndy FiddamanIf the signal being sent is
5443e49fc963SAndy Fiddaman.Sy TERM
5444e49fc963SAndy Fiddaman(terminate) or
5445e49fc963SAndy Fiddaman.Sy HUP
5446e49fc963SAndy Fiddaman(hang up), then the job or process is sent a
5447e49fc963SAndy Fiddaman.Sy CONT
5448e49fc963SAndy Fiddaman(continue) signal if it is stopped.
5449e49fc963SAndy FiddamanThe argument
5450e49fc963SAndy Fiddaman.Ar job
5451e49fc963SAndy Fiddamancan be the process id of a process that is not a member of one of the active
5452e49fc963SAndy Fiddamanjobs.
5453e49fc963SAndy FiddamanSee
5454e49fc963SAndy Fiddaman.Sx Jobs
5455e49fc963SAndy Fiddamanfor a description of the format of
5456e49fc963SAndy Fiddaman.Ar job .
5457e49fc963SAndy FiddamanIn the third form,
5458e49fc963SAndy Fiddaman.Ic kill Fl l
5459e49fc963SAndy Fiddamanor
5460e49fc963SAndy Fiddaman.Ic kill Fl L ,
5461e49fc963SAndy Fiddamanif
5462e49fc963SAndy Fiddaman.Ar sig
5463e49fc963SAndy Fiddamanis not specified, the signal names are listed.
5464e49fc963SAndy FiddamanThe
5465e49fc963SAndy Fiddaman.Fl l
5466e49fc963SAndy Fiddamanoption
5467e49fc963SAndy Fiddamanlists only the signal names whereas
5468e49fc963SAndy Fiddaman.Fl L
5469e49fc963SAndy Fiddamanlists each signal name and corresponding number.
5470e49fc963SAndy FiddamanOtherwise, for each
5471e49fc963SAndy Fiddaman.Ar sig
5472e49fc963SAndy Fiddamanthat is a name, the corresponding signal number is listed.
5473e49fc963SAndy FiddamanFor each
5474e49fc963SAndy Fiddaman.Ar sig
5475e49fc963SAndy Fiddamanthat is a number, the signal name corresponding to the least significant 8 bits
5476e49fc963SAndy Fiddamanof
5477e49fc963SAndy Fiddaman.Ar sig
5478e49fc963SAndy Fiddamanis listed.
5479e49fc963SAndy Fiddaman.Pp
5480e49fc963SAndy Fiddaman.It Ic let Op Ar arg No ...
5481e49fc963SAndy FiddamanEach
5482e49fc963SAndy Fiddaman.Ar arg
5483e49fc963SAndy Fiddamanis a separate arithmetic expression to be evaluated.
5484e49fc963SAndy Fiddaman.Ic let
5485e49fc963SAndy Fiddamanonly recognizes octal constants starting with
5486e49fc963SAndy Fiddaman.Sy 0
5487e49fc963SAndy Fiddamanwhen the
5488e49fc963SAndy Fiddaman.Ic set
5489e49fc963SAndy Fiddamanoption
5490e49fc963SAndy Fiddaman.Sy letoctal
5491e49fc963SAndy Fiddamanis on.
5492e49fc963SAndy FiddamanSee the
5493e49fc963SAndy Fiddaman.Sx Arithmetic Evaluation
5494b30d1939SAndy Fiddamansection of this manual page for a description of arithmetic expression
5495e49fc963SAndy Fiddamanevaluation.
5496e49fc963SAndy FiddamanThe exit status is
5497e49fc963SAndy Fiddaman.Sy 0
5498e49fc963SAndy Fiddamanif the value of the last expression is
5499e49fc963SAndy Fiddaman.Sy non-zero ,
5500e49fc963SAndy Fiddamanand
5501e49fc963SAndy Fiddaman.Sy 1
5502e49fc963SAndy Fiddamanotherwise.
5503e49fc963SAndy Fiddaman.Pp
5504e49fc963SAndy Fiddaman.It Sy + Ic newgrp Op arg No ...
5505e49fc963SAndy FiddamanEquivalent to
5506e49fc963SAndy Fiddaman.Ic exec Pa /bin/newgrp Ar arg No ...
5507e49fc963SAndy Fiddaman.Pp
5508e49fc963SAndy Fiddaman.It Xo
5509e49fc963SAndy Fiddaman.Ic print
5510e49fc963SAndy Fiddaman.Op Fl CRenprsv
5511e49fc963SAndy Fiddaman.Op Fl u Ar unit
5512e49fc963SAndy Fiddaman.Op Fl f Ar format
5513e49fc963SAndy Fiddaman.Op Ar arg No ...
5514e49fc963SAndy Fiddaman.Xc
5515e49fc963SAndy FiddamanWith no options or with option
5516e49fc963SAndy Fiddaman.Sy -
5517e49fc963SAndy Fiddamanor
5518e49fc963SAndy Fiddaman.Fl \- ,
5519e49fc963SAndy Fiddamaneach
5520e49fc963SAndy Fiddaman.Ar arg
5521e49fc963SAndy Fiddamanis printed on standard output.
5522e49fc963SAndy FiddamanThe
5523e49fc963SAndy Fiddaman.Fl f
5524e49fc963SAndy Fiddamanoption causes the arguments to be printed as described by
5525e49fc963SAndy Fiddaman.Ic printf .
5526e49fc963SAndy FiddamanIn this case, any
5527e49fc963SAndy Fiddaman.Fl e ,
5528e49fc963SAndy Fiddaman.Fl n ,
5529e49fc963SAndy Fiddaman.Fl r ,
5530e49fc963SAndy Fiddamanor
5531e49fc963SAndy Fiddaman.Fl R
5532e49fc963SAndy Fiddamanoptions are ignored.
5533e49fc963SAndy FiddamanOtherwise, unless the
5534e49fc963SAndy Fiddaman.Fl R
5535e49fc963SAndy Fiddamanor
5536e49fc963SAndy Fiddaman.Fl r
5537e49fc963SAndy Fiddamanoptions are specified, the following escape conventions are applied:
5538e49fc963SAndy Fiddaman.Bl -tag -width Ds
5539e49fc963SAndy Fiddaman.It Sy \ea
5540e49fc963SAndy FiddamanAlert character
5541e49fc963SAndy Fiddaman.Pq Sy ASCII 007
5542e49fc963SAndy Fiddaman.It Sy \eb
5543e49fc963SAndy FiddamanBackspace character
5544e49fc963SAndy Fiddaman.Pq Sy ASCII 010
5545e49fc963SAndy Fiddaman.It Sy \ec
5546c10c16deSRichard LoweCauses print to end without processing more arguments and not adding a NEWLINE
5547e49fc963SAndy Fiddaman.It Sy \ef
5548e49fc963SAndy FiddamanForm-feed character
5549e49fc963SAndy Fiddaman.Pq Sy ASCII 014
5550e49fc963SAndy Fiddaman.It Sy \en
5551e49fc963SAndy FiddamanNEWLINE character
5552e49fc963SAndy Fiddaman.Pq Sy ASCII 012
5553e49fc963SAndy Fiddaman.It Sy \er
5554e49fc963SAndy FiddamanRETURN character
5555e49fc963SAndy Fiddaman.Pq Sy ASCII 015
5556e49fc963SAndy Fiddaman.It Sy \et
5557e49fc963SAndy FiddamanTAB character
5558e49fc963SAndy Fiddaman.Pq Sy ASCII 011
5559e49fc963SAndy Fiddaman.It Sy \ev
5560e49fc963SAndy FiddamanVertical TAB character
5561e49fc963SAndy Fiddaman.Pq Sy ASCII 013
5562e49fc963SAndy Fiddaman.It Sy \eE
5563e49fc963SAndy FiddamanEscape character
5564e49fc963SAndy Fiddaman.Pq Sy ASCII 033
5565e49fc963SAndy Fiddaman.It Sy \e\e
5566e49fc963SAndy FiddamanBackslash character
5567e49fc963SAndy Fiddaman.Sy \e
5568e49fc963SAndy Fiddaman.It Sy \e0 Ns Ar x
5569e49fc963SAndy FiddamanCharacter defined by the 1, 2, or 3-digit octal string specified by
5570e49fc963SAndy Fiddaman.Ar x
5571e49fc963SAndy Fiddaman.El
5572e49fc963SAndy Fiddaman.Pp
5573e49fc963SAndy FiddamanThe
5574e49fc963SAndy Fiddaman.Fl R
5575e49fc963SAndy Fiddamanoption prints all subsequent arguments and options other than
5576e49fc963SAndy Fiddaman.Fl n .
5577e49fc963SAndy FiddamanThe
5578e49fc963SAndy Fiddaman.Fl e
5579e49fc963SAndy Fiddamancauses the escape conventions to be applied.
5580e49fc963SAndy FiddamanThis is the default behavior.
5581e49fc963SAndy FiddamanIt reverses the effect of an earlier
5582e49fc963SAndy Fiddaman.Fl r .
5583e49fc963SAndy FiddamanThe
5584e49fc963SAndy Fiddaman.Fl p
5585c10c16deSRichard Loweoption causes the arguments to be written onto the pipe of the process spawned
5586e49fc963SAndy Fiddamanwith
5587e49fc963SAndy Fiddaman.Sy |&
5588e49fc963SAndy Fiddamaninstead of standard output.
5589e49fc963SAndy FiddamanThe
5590e49fc963SAndy Fiddaman.Fl v
5591e49fc963SAndy Fiddamanoption treats each
5592e49fc963SAndy Fiddaman.Ar arg
5593e49fc963SAndy Fiddamanas a variable name and writes the value in the
5594e49fc963SAndy Fiddaman.Ic printf Cm \&%B
5595e49fc963SAndy Fiddamanformat.
5596e49fc963SAndy FiddamanThe
5597e49fc963SAndy Fiddaman.Fl C
5598e49fc963SAndy Fiddamanoption treats each
5599e49fc963SAndy Fiddaman.Ar arg
5600e49fc963SAndy Fiddamanas a variable name and writes the values in the
5601e49fc963SAndy Fiddaman.Ic printf Cm \&%#B
5602e49fc963SAndy Fiddamanformat.
5603e49fc963SAndy FiddamanThe
5604e49fc963SAndy Fiddaman.Fl s
5605e49fc963SAndy Fiddamanoption causes the arguments to be written onto the history file instead of
5606e49fc963SAndy Fiddamanstandard output.
5607e49fc963SAndy FiddamanThe
5608e49fc963SAndy Fiddaman.Fl u
5609e49fc963SAndy Fiddamanoption can be used to specify a one digit file descriptor unit number
5610e49fc963SAndy Fiddaman.Ar unit
5611e49fc963SAndy Fiddamanon which the output is placed.
5612e49fc963SAndy FiddamanThe default is
5613e49fc963SAndy Fiddaman.Sy 1 .
5614e49fc963SAndy FiddamanIf the option
5615e49fc963SAndy Fiddaman.Fl n
5616e49fc963SAndy Fiddamanis used, no NEWLINE is added to the output.
5617e49fc963SAndy Fiddaman.Pp
5618e49fc963SAndy Fiddaman.It Ic printf Ar format Op Ar arg No ...
5619e49fc963SAndy FiddamanThe arguments
5620e49fc963SAndy Fiddaman.Ar arg
5621e49fc963SAndy Fiddamanare printed on standard output in accordance with the
5622e49fc963SAndy Fiddaman.Sy ANSI-C
5623e49fc963SAndy Fiddamanformatting rules associated with the format string
5624e49fc963SAndy Fiddaman.Ar format .
5625c10c16deSRichard LoweIf the number of arguments exceeds the number of format specifications, the
5626e49fc963SAndy Fiddamanformat string is reused to format remaining arguments.
5627e49fc963SAndy FiddamanThe following extensions can also be used:
5628e49fc963SAndy Fiddaman.Bl -tag -width Ds
5629e49fc963SAndy Fiddaman.It Sy %b
5630e49fc963SAndy FiddamanA
5631e49fc963SAndy Fiddaman.Sy %b
5632e49fc963SAndy Fiddamanformat can be used instead of
5633e49fc963SAndy Fiddaman.Sy %s
5634e49fc963SAndy Fiddamanto cause escape sequences in the corresponding
5635e49fc963SAndy Fiddaman.Ar arg
5636e49fc963SAndy Fiddamanto be expanded as described in
5637e49fc963SAndy Fiddaman.Ic print .
5638e49fc963SAndy Fiddaman.It Sy \&%B
5639e49fc963SAndy FiddamanA
5640e49fc963SAndy Fiddaman.Sy \&%B
5641e49fc963SAndy Fiddamanoption causes each of the arguments to be treated as variable names and the
5642e49fc963SAndy Fiddamanbinary value of the variables is printed.
5643e49fc963SAndy FiddamanThis is most useful for variables with an attribute of b.
5644e49fc963SAndy Fiddaman.It Sy \&%H
5645e49fc963SAndy FiddamanA
5646e49fc963SAndy Fiddaman.Sy \&%H
5647e49fc963SAndy Fiddamanformat can be used instead of
5648e49fc963SAndy Fiddaman.Sy %s
5649e49fc963SAndy Fiddamanto cause characters in
5650e49fc963SAndy Fiddaman.Ar arg
5651e49fc963SAndy Fiddamanthat are special in
5652e49fc963SAndy Fiddaman.Sy HTML
5653e49fc963SAndy Fiddamanand
5654e49fc963SAndy Fiddaman.Sy XML
5655e49fc963SAndy Fiddamanto be output as their entity name.
5656e49fc963SAndy FiddamanThe alternate flag
5657e49fc963SAndy Fiddaman.Sy #
5658e49fc963SAndy Fiddamanformats the output for use as a URI.
5659e49fc963SAndy Fiddaman.It Sy \&%P
5660e49fc963SAndy FiddamanA
5661e49fc963SAndy Fiddaman.Sy \&%P
5662e49fc963SAndy Fiddamanformat can be used instead of
5663e49fc963SAndy Fiddaman.Sy \&%s
5664e49fc963SAndy Fiddamanto cause
5665e49fc963SAndy Fiddaman.Ar arg
5666e49fc963SAndy Fiddamanto be interpreted as an extended regular expression and be printed as a shell
5667b30d1939SAndy Fiddamanpattern.
5668e49fc963SAndy Fiddaman.It Sy \&%R
5669e49fc963SAndy FiddamanA
5670e49fc963SAndy Fiddaman.Sy \&%R
5671e49fc963SAndy Fiddamanformat can be used instead of
5672e49fc963SAndy Fiddaman.Sy \&%s
5673e49fc963SAndy Fiddamanto cause
5674e49fc963SAndy Fiddaman.Ar arg
5675e49fc963SAndy Fiddamanto be interpreted as a shell pattern and to be printed as an extended regular
5676e49fc963SAndy Fiddamanexpression.
5677e49fc963SAndy Fiddaman.It Sy \&%q
5678e49fc963SAndy FiddamanA
5679e49fc963SAndy Fiddaman.Sy \&%q
5680e49fc963SAndy Fiddamanformat can be used instead of
5681e49fc963SAndy Fiddaman.Sy \&%
5682e49fc963SAndy Fiddamans to cause the resulting string to be quoted in a manner than can be input
5683e49fc963SAndy Fiddamanagain to the shell.
5684e49fc963SAndy FiddamanWhen
5685e49fc963SAndy Fiddaman.Sy q
5686e49fc963SAndy Fiddamanis preceded by the alternative format specifier,
5687e49fc963SAndy Fiddaman.Sy # ,
5688e49fc963SAndy Fiddamanthe string is quoted in manner suitable for a field in a
5689e49fc963SAndy Fiddaman.Sy .csv
5690e49fc963SAndy Fiddamanformat file.
5691e49fc963SAndy Fiddaman.It Sy \&% Ns Oo Sy \&( Ns Ar date-format Ns Sy \&) Oc Ns Sy T
5692e49fc963SAndy FiddamanA
5693e49fc963SAndy Fiddaman.Sy \&% Ns Oo Sy \&( Ns Ar date-format Ns Sy \&) Oc Ns Sy T
5694e49fc963SAndy Fiddamanformat can be used to treat an argument as a date/time string and to format the
5695e49fc963SAndy Fiddamandate/time according to the
5696e49fc963SAndy Fiddaman.Ar date-format
5697e49fc963SAndy Fiddamanas defined for the
5698e49fc963SAndy Fiddaman.Xr date 1
5699e49fc963SAndy Fiddamancommand.
5700e49fc963SAndy FiddamanFor example,
5701e49fc963SAndy Fiddaman.Sq printf '%(%s)T' now
5702e49fc963SAndy Fiddamanwould print the current time in UNIX timestamp format
5703e49fc963SAndy Fiddaman.Pq seconds since 00:00:00 UTC, January 1, 1970 .
5704e49fc963SAndy Fiddaman.It Sy %Z
5705e49fc963SAndy FiddamanA
5706e49fc963SAndy Fiddaman.Sy %Z
5707e49fc963SAndy Fiddamanformat outputs a byte whose value is 0.
5708e49fc963SAndy Fiddaman.It Sy %d
5709e49fc963SAndy FiddamanThe precision field of the %d format can be followed by a \&. and the output
5710e49fc963SAndy Fiddamanbase.
5711e49fc963SAndy FiddamanIn this case, the
5712e49fc963SAndy Fiddaman.Sy #
5713e49fc963SAndy Fiddamanflag character causes
5714e49fc963SAndy Fiddaman.Sy base Ar #
5715e49fc963SAndy Fiddamanto be prepended.
5716e49fc963SAndy Fiddaman.It Sy #
5717e49fc963SAndy FiddamanThe
5718e49fc963SAndy Fiddaman.Sy #
5719e49fc963SAndy Fiddamanflag, when used with the
5720e49fc963SAndy Fiddaman.Sy %d
5721e49fc963SAndy Fiddamanformat without an output base, displays the output in powers of 1000 indicated
5722e49fc963SAndy Fiddamanby one of the following suffixes:
5723e49fc963SAndy Fiddaman.Sy k M G T P E ,
5724e49fc963SAndy Fiddamanand when used with the
5725e49fc963SAndy Fiddaman.Sy %i
5726e49fc963SAndy Fiddamanformat displays the output in powers of 1024 indicated by one of the following
5727e49fc963SAndy Fiddamansuffixes:
5728e49fc963SAndy Fiddaman.Sy Ki Mi Gi Ti Pi Ei .
5729e49fc963SAndy Fiddaman.It Sy =
5730e49fc963SAndy FiddamanThe
5731e49fc963SAndy Fiddaman.Sy =
5732e49fc963SAndy Fiddamanflag centers the output within the specified field width.
5733e49fc963SAndy Fiddaman.It Sy L
5734e49fc963SAndy FiddamanThe
5735e49fc963SAndy Fiddaman.Sy L
5736e49fc963SAndy Fiddamanflag, when used with the
5737e49fc963SAndy Fiddaman.Sy %c
5738e49fc963SAndy Fiddamanor
5739e49fc963SAndy Fiddaman.Sy %s
5740b30d1939SAndy Fiddamanformats, treats precision as character width instead of byte count.
5741e49fc963SAndy Fiddaman.It Sy \&,
5742e49fc963SAndy FiddamanThe
5743e49fc963SAndy Fiddaman.Sy \&,
5744e49fc963SAndy Fiddamanflag, when used with the
5745e49fc963SAndy Fiddaman.Sy %d
5746e49fc963SAndy Fiddamanor
5747e49fc963SAndy Fiddaman.Sy %f
5748b30d1939SAndy Fiddamanformats, separates groups of digits with the grouping delimiter
5749e49fc963SAndy Fiddaman.Po Sq Sy \&,
5750e49fc963SAndy Fiddamanin groups of 3 in the C locale
5751e49fc963SAndy Fiddaman.Pc .
5752e49fc963SAndy Fiddaman.El
5753e49fc963SAndy Fiddaman.Pp
5754e49fc963SAndy Fiddaman.It Ic pwd Op Fl LP
5755e49fc963SAndy FiddamanOutputs the value of the current working directory.
5756e49fc963SAndy FiddamanThe
5757e49fc963SAndy Fiddaman.Fl L
5758e49fc963SAndy Fiddamanoption is the default.
5759e49fc963SAndy FiddamanIt prints the logical name of the current directory.
5760e49fc963SAndy FiddamanIf the
5761e49fc963SAndy Fiddaman.Fl P
5762e49fc963SAndy Fiddamanoption is specified, all symbolic links are resolved from the name.
5763e49fc963SAndy FiddamanThe last instance of
5764e49fc963SAndy Fiddaman.Fl L
5765e49fc963SAndy Fiddamanor
5766e49fc963SAndy Fiddaman.Fl P
5767e49fc963SAndy Fiddamanon the command line determines which method is used.
5768e49fc963SAndy Fiddaman.Pp
5769e49fc963SAndy Fiddaman.It Xo
5770e49fc963SAndy Fiddaman.Bk -words
5771e49fc963SAndy Fiddaman.Ic read Op Fl ACSprsv
5772e49fc963SAndy Fiddaman.Op Fl d Ar delim
5773e49fc963SAndy Fiddaman.Op Fl n Ar n | Fl N Ar n
5774e49fc963SAndy Fiddaman.Op Fl t Ar timeout
5775e49fc963SAndy Fiddaman.Op Fl u Ar unit
5776e49fc963SAndy Fiddaman.Op Ar vname Ns Sy \&? Ns Ar prompt
5777e49fc963SAndy Fiddaman.Op Ar name No ...
5778e49fc963SAndy Fiddaman.Ek
5779e49fc963SAndy Fiddaman.Xc
5780e49fc963SAndy Fiddaman.Pp
5781e49fc963SAndy FiddamanThe shell input mechanism.
5782e49fc963SAndy FiddamanOne line is read and is broken up into fields using the characters in
5783e49fc963SAndy Fiddaman.Ev IFS
5784e49fc963SAndy Fiddamanas separators.
5785e49fc963SAndy FiddamanThe escape character,
5786e49fc963SAndy Fiddaman.Sy \e ,
5787e49fc963SAndy Fiddamanis used to remove any special meaning for the next character and for line
5788e49fc963SAndy Fiddamancontinuation.
5789e49fc963SAndy FiddamanThe
5790e49fc963SAndy Fiddaman.Fl d
5791e49fc963SAndy Fiddamanoption causes the read to continue to the first character of
5792e49fc963SAndy Fiddaman.Ar delim
5793e49fc963SAndy Fiddamanrather than NEWLINE.
5794e49fc963SAndy FiddamanThe
5795e49fc963SAndy Fiddaman.Fl n
5796e49fc963SAndy Fiddamanoption causes at most
5797e49fc963SAndy Fiddaman.Ar n
5798e49fc963SAndy Fiddamanbytes to read rather a full line but returns when reading from a slow device as
5799e49fc963SAndy Fiddamansoon as any characters have been read.
5800e49fc963SAndy FiddamanThe
5801e49fc963SAndy Fiddaman.Fl N
5802e49fc963SAndy Fiddamanoption causes exactly
5803e49fc963SAndy Fiddaman.Ar n
5804e49fc963SAndy Fiddamanto be read unless an end-of-file has been encountered or the read times out
5805e49fc963SAndy Fiddamanbecause of the
5806e49fc963SAndy Fiddaman.Fl t
5807e49fc963SAndy Fiddamanoption.
5808e49fc963SAndy FiddamanIn raw mode,
5809e49fc963SAndy Fiddaman.Fl r ,
5810e49fc963SAndy Fiddamanthe
5811e49fc963SAndy Fiddaman.Sy \e
5812e49fc963SAndy Fiddamancharacter is not treated specially.
5813e49fc963SAndy FiddamanThe first field is assigned to the first
5814e49fc963SAndy Fiddaman.Ar vname ,
5815e49fc963SAndy Fiddamanthe second field to the second
5816e49fc963SAndy Fiddaman.Ar vname ,
5817e49fc963SAndy Fiddamanetc., with leftover fields assigned to the last
5818e49fc963SAndy Fiddaman.Ar vname .
5819e49fc963SAndy FiddamanWhen
5820e49fc963SAndy Fiddaman.Ar vname
5821e49fc963SAndy Fiddamanhas the binary attribute and
5822e49fc963SAndy Fiddaman.Fl n
5823e49fc963SAndy Fiddamanor
5824e49fc963SAndy Fiddaman.Fl N
5825e49fc963SAndy Fiddamanis specified, the bytes that are read are stored directly into the variable.
5826e49fc963SAndy FiddamanIf
5827e49fc963SAndy Fiddaman.Fl v
5828e49fc963SAndy Fiddamanis specified, then the value of the first
5829e49fc963SAndy Fiddaman.Ar vname
5830e49fc963SAndy Fiddamanis used as a default value when reading from a terminal device.
5831e49fc963SAndy FiddamanThe
5832e49fc963SAndy Fiddaman.Fl A
5833e49fc963SAndy Fiddamanoption causes the variable
5834e49fc963SAndy Fiddaman.Ar vname
5835e49fc963SAndy Fiddamanto be unset and each field that is read to be stored in successive elements of
5836e49fc963SAndy Fiddamanthe indexed array
5837e49fc963SAndy Fiddaman.Ar vname .
5838e49fc963SAndy FiddamanThe
5839e49fc963SAndy Fiddaman.Fl C
5840e49fc963SAndy Fiddamanoption causes the variable vname to be read as a compound variable.
5841e49fc963SAndy FiddamanBlanks will be ignored when finding the beginning open parenthesis.
5842e49fc963SAndy FiddamanThe
5843e49fc963SAndy Fiddaman.Fl S
5844e49fc963SAndy Fiddamanoption causes the line to be treated like a record in a .csv format file so
5845e49fc963SAndy Fiddamanthat double quotes can be used to allow the delimiter character and the
5846e49fc963SAndy Fiddamannew-line character to appear within a field.
5847e49fc963SAndy FiddamanThe
5848e49fc963SAndy Fiddaman.Fl p
5849e49fc963SAndy Fiddamanoption causes the input line to be taken from the input pipe of a process
5850e49fc963SAndy Fiddamanspawned by the shell using
5851e49fc963SAndy Fiddaman.Sy |& .
5852e49fc963SAndy FiddamanIf the
5853e49fc963SAndy Fiddaman.Fl s
5854e49fc963SAndy Fiddamanoption is present, the input is saved as a command in the history file.
5855e49fc963SAndy FiddamanThe option
5856e49fc963SAndy Fiddaman.Fl u
5857e49fc963SAndy Fiddamancan be used to specify a one digit file descriptor unit
5858e49fc963SAndy Fiddaman.Ar unit
5859e49fc963SAndy Fiddamanto read from.
5860e49fc963SAndy FiddamanThe file descriptor can be opened with the
5861e49fc963SAndy Fiddaman.Ic exec
5862e49fc963SAndy Fiddamanspecial built-in command.
5863e49fc963SAndy FiddamanThe default value of unit
5864e49fc963SAndy Fiddaman.Ar n
5865e49fc963SAndy Fiddamanis
5866e49fc963SAndy Fiddaman.Sy 0 .
5867e49fc963SAndy FiddamanThe option
5868e49fc963SAndy Fiddaman.Fl t
5869e49fc963SAndy Fiddamanis used to specify a time out in seconds when reading from a terminal or pipe.
5870e49fc963SAndy FiddamanIf
5871e49fc963SAndy Fiddaman.Ar vname
5872e49fc963SAndy Fiddamanis omitted, then
5873e49fc963SAndy Fiddaman.Ev REPLY
5874e49fc963SAndy Fiddamanis used as the default
5875e49fc963SAndy Fiddaman.Ar vname .
5876e49fc963SAndy FiddamanAn end-of-file with the
5877e49fc963SAndy Fiddaman.Fl p
5878e49fc963SAndy Fiddamanoption causes cleanup for this process so that another can be spawned.
5879e49fc963SAndy FiddamanIf the first argument contains a
5880e49fc963SAndy Fiddaman.Sy \&? ,
5881e49fc963SAndy Fiddamanthe remainder of this word is used as a prompt on standard error when the shell
5882e49fc963SAndy Fiddamanis interactive.
5883e49fc963SAndy FiddamanThe exit status is
5884e49fc963SAndy Fiddaman.Sy 0
5885e49fc963SAndy Fiddamanunless an end-of-file is encountered or read has timed out.
5886e49fc963SAndy Fiddaman.Pp
5887e49fc963SAndy Fiddaman.It Xo
5888e49fc963SAndy Fiddaman.Sy ++ Ic readonly
5889e49fc963SAndy Fiddaman.Op Fl p
5890e49fc963SAndy Fiddaman.Oo Ar vname Ns Oo Sy = Ns Ar value Oc Oc ...
5891e49fc963SAndy Fiddaman.Xc
5892e49fc963SAndy FiddamanIf
5893e49fc963SAndy Fiddaman.Ar vname
5894e49fc963SAndy Fiddamanis not specified, the names and values of each variable with the read-only
5895e49fc963SAndy Fiddamanattribute is printed with the values quoted in a manner that allows them to be
5896e49fc963SAndy Fiddamaninput again.
5897e49fc963SAndy FiddamanThe
5898e49fc963SAndy Fiddaman.Fl p
5899e49fc963SAndy Fiddamanoption causes the word
5900e49fc963SAndy Fiddaman.Ic readonly
5901e49fc963SAndy Fiddamanto be inserted before each one.
5902e49fc963SAndy FiddamanOtherwise, the specified
5903e49fc963SAndy Fiddaman.Ar vname Ns No s
5904e49fc963SAndy Fiddamanare marked
5905e49fc963SAndy Fiddaman.Ic readonly
5906e49fc963SAndy Fiddamanand these names cannot be changed by subsequent assignment.
5907e49fc963SAndy Fiddaman.Pp
5908e49fc963SAndy Fiddaman.It Sy + Ic return Op Ar n
5909c10c16deSRichard LoweCauses a shell function or script to return to the invoking script with the
5910e49fc963SAndy Fiddamanexit status specified by
5911e49fc963SAndy Fiddaman.Ar n .
5912e49fc963SAndy FiddamanThe value is the least significant 8 bits of the specified status.
5913e49fc963SAndy FiddamanIf
5914e49fc963SAndy Fiddaman.Sy n
5915e49fc963SAndy Fiddamanis omitted, then the return status is that of the last command executed.
5916e49fc963SAndy FiddamanIf return is invoked while not in a function or a script, then it behaves the
5917e49fc963SAndy Fiddamansame as exit.
5918e49fc963SAndy Fiddaman.Pp
5919e49fc963SAndy Fiddaman.It Xo
5920e49fc963SAndy Fiddaman.Sy + Ic set
5921e49fc963SAndy Fiddaman.Op Sy + Ns Fl BCGabefhkmnoprstuvx
5922e49fc963SAndy Fiddaman.Oo Sy + Ns Fl o Oo Ar option Oc Oc ...
5923e49fc963SAndy Fiddaman.Op Sy + Ns Fl A Ar vname
5924e49fc963SAndy Fiddaman.Op Ar arg No ...
5925e49fc963SAndy Fiddaman.Xc
5926e49fc963SAndy FiddamanThe
5927e49fc963SAndy Fiddaman.Ic set
5928e49fc963SAndy Fiddamancommand supports the following options:
5929e49fc963SAndy Fiddaman.Bl -tag -width Ds
5930e49fc963SAndy Fiddaman.It Fl a
5931c10c16deSRichard LoweAll subsequent variables that are defined are automatically exported.
5932e49fc963SAndy Fiddaman.It Fl A
5933e49fc963SAndy FiddamanArray assignment.
5934e49fc963SAndy FiddamanUnset the variable
5935e49fc963SAndy Fiddaman.Ar vname
5936e49fc963SAndy Fiddamanand assign values sequentially from the
5937e49fc963SAndy Fiddaman.Ar arg
5938e49fc963SAndy Fiddamanlist.
5939e49fc963SAndy FiddamanIf
5940e49fc963SAndy Fiddaman.Sy +A
5941e49fc963SAndy Fiddamanis used, the variable
5942e49fc963SAndy Fiddaman.Ar vname
5943e49fc963SAndy Fiddamanis not unset first.
5944e49fc963SAndy Fiddaman.It Fl b
5945c10c16deSRichard LowePrints job completion messages as soon as a background job changes state rather
5946c10c16deSRichard Lowethan waiting for the next prompt.
5947e49fc963SAndy Fiddaman.It Fl B
5948e49fc963SAndy FiddamanEnable brace pattern field generation.
5949e49fc963SAndy FiddamanThis is the default behavior.
5950e49fc963SAndy Fiddaman.It Fl C
5951e49fc963SAndy FiddamanPrevents redirection
5952e49fc963SAndy Fiddaman.Pq Sy \&>
5953e49fc963SAndy Fiddamanfrom truncating existing files.
5954e49fc963SAndy FiddamanFiles that are created are opened with the
5955e49fc963SAndy Fiddaman.Sy O_EXCL
5956e49fc963SAndy Fiddamanmode.
5957e49fc963SAndy FiddamanRequires
5958e49fc963SAndy Fiddaman.Sy >|
5959e49fc963SAndy Fiddamanto truncate a file when turned on.
5960e49fc963SAndy Fiddaman.It Fl e
5961e49fc963SAndy FiddamanUnless contained in a
5962e49fc963SAndy Fiddaman.Sy ||
5963e49fc963SAndy Fiddamanor
5964e49fc963SAndy Fiddaman.Sy &&
5965e49fc963SAndy Fiddamancommand, or the command following an
5966e49fc963SAndy Fiddaman.Ic if ,
5967e49fc963SAndy Fiddaman.Ic while
5968e49fc963SAndy Fiddamanor
5969e49fc963SAndy Fiddaman.Ic until
5970e49fc963SAndy Fiddamancommand or in the pipeline following
5971e49fc963SAndy Fiddaman.Sy \&! ,
5972e49fc963SAndy Fiddamanif a command has a non-zero exit status, execute the
5973e49fc963SAndy Fiddaman.Sy ERR
5974e49fc963SAndy Fiddamantrap, if set, and exit.
5975e49fc963SAndy FiddamanThis mode is disabled while reading profiles.
5976e49fc963SAndy Fiddaman.It Fl f
5977c10c16deSRichard LoweDisables file name generation.
5978e49fc963SAndy Fiddaman.It Fl G
5979e49fc963SAndy FiddamanCauses the pattern
5980e49fc963SAndy Fiddaman.Sy \&**
5981e49fc963SAndy Fiddamanby itself to match files and zero or more directories and subdirectories when
5982e49fc963SAndy Fiddamanused for file name generation.
5983e49fc963SAndy FiddamanIf followed by a
5984e49fc963SAndy Fiddaman.Sy /
5985e49fc963SAndy Fiddamanonly directories and subdirectories are matched.
5986e49fc963SAndy Fiddaman.It Fl h
5987c10c16deSRichard LoweEach command becomes a tracked alias when first encountered.
5988e49fc963SAndy Fiddaman.It Fl k
5989e49fc963SAndy FiddamanObsolete.
5990e49fc963SAndy FiddamanAll variable assignment arguments are placed in the environment for a command,
5991e49fc963SAndy Fiddamannot just those that precede the command name.
5992e49fc963SAndy Fiddaman.It Fl m
5993c10c16deSRichard LoweBackground jobs run in a separate process group and a line prints upon
5994e49fc963SAndy Fiddamancompletion.
5995e49fc963SAndy FiddamanThe exit status of background jobs is reported in a completion message.
5996e49fc963SAndy FiddamanOn systems with job control, this option is turned on automatically for
5997e49fc963SAndy Fiddamaninteractive shells.
5998e49fc963SAndy Fiddaman.It Fl n
5999c10c16deSRichard LoweRead commands and check them for syntax errors, but do not execute them.
6000c10c16deSRichard LoweIgnored for interactive shells.
6001e49fc963SAndy Fiddaman.It Fl o
6002c10c16deSRichard LoweIf no option name is supplied, the list of options and their current settings
6003e49fc963SAndy Fiddamanare written to standard output.
6004e49fc963SAndy FiddamanWhen invoked with a
6005e49fc963SAndy Fiddaman.Sy \&+ ,
6006e49fc963SAndy Fiddamanthe options are written in a format that can be input again to the shell to
6007e49fc963SAndy Fiddamanrestore the settings.
6008e49fc963SAndy FiddamanThis option can be repeated to enable or disable multiple options.
6009e49fc963SAndy Fiddaman.Pp
6010c10c16deSRichard LoweThe following argument can be one of the following option names:
6011e49fc963SAndy Fiddaman.Bl -tag -width Ar
6012e49fc963SAndy Fiddaman.It Cm allexport
6013e49fc963SAndy FiddamanSame as
6014e49fc963SAndy Fiddaman.Fl a .
6015e49fc963SAndy Fiddaman.It Cm bgnice
6016e49fc963SAndy FiddamanAll background jobs are run at a lower priority.
6017e49fc963SAndy FiddamanThis is the default mode.
6018e49fc963SAndy Fiddaman.It Cm braceexpand
6019e49fc963SAndy FiddamanSame as
6020e49fc963SAndy Fiddaman.Fl B .
6021e49fc963SAndy Fiddaman.It Cm emacs
6022e49fc963SAndy FiddamanPuts you in an
6023e49fc963SAndy Fiddaman.Sy emacs
6024e49fc963SAndy Fiddamanstyle inline editor for command entry.
6025e49fc963SAndy Fiddaman.It Cm errexit
6026e49fc963SAndy FiddamanSame as
6027e49fc963SAndy Fiddaman.Fl e .
6028e49fc963SAndy Fiddaman.It Cm globstar
6029e49fc963SAndy FiddamanSame as
6030e49fc963SAndy Fiddaman.Fl G .
6031e49fc963SAndy Fiddaman.It Cm gmacs
6032e49fc963SAndy FiddamanPuts you in a
6033e49fc963SAndy Fiddaman.Sy gmacs
6034e49fc963SAndy Fiddamanstyle inline editor for command entry.
6035e49fc963SAndy Fiddaman.It Cm ignoreeof
6036e49fc963SAndy FiddamanThe shell does not exit on end-of-file.
6037e49fc963SAndy FiddamanThe command
6038e49fc963SAndy Fiddaman.Ic exit
6039e49fc963SAndy Fiddamanmust be used.
6040e49fc963SAndy Fiddaman.It Cm keyword
6041e49fc963SAndy FiddamanSame as
6042e49fc963SAndy Fiddaman.Fl k .
6043e49fc963SAndy Fiddaman.It Cm letoctal
6044e49fc963SAndy FiddamanThe
6045e49fc963SAndy Fiddaman.Ic let
6046e49fc963SAndy Fiddamancommand allows octal constants starting with
6047e49fc963SAndy Fiddaman.Sy 0 .
6048e49fc963SAndy Fiddaman.It Cm markdirs
6049c10c16deSRichard LoweAll directory names resulting from file name generation have a trailing /
6050c10c16deSRichard Loweappended.
6051e49fc963SAndy Fiddaman.It Cm monitor
6052e49fc963SAndy FiddamanSame as
6053e49fc963SAndy Fiddaman.Fl m .
6054e49fc963SAndy Fiddaman.It Cm multiline
6055c10c16deSRichard LoweThe built-in editors use multiple lines on the screen for lines that are longer
6056e49fc963SAndy Fiddamanthan the width of the screen.
6057e49fc963SAndy FiddamanThis might not work for all terminals.
6058e49fc963SAndy Fiddaman.It Cm noclobber
6059e49fc963SAndy FiddamanSame as
6060e49fc963SAndy Fiddaman.Fl C .
6061e49fc963SAndy Fiddaman.It Cm noexec
6062e49fc963SAndy FiddamanSame as
6063e49fc963SAndy Fiddaman.Fl n .
6064e49fc963SAndy Fiddaman.It Cm noglob
6065e49fc963SAndy FiddamanSame as
6066e49fc963SAndy Fiddaman.Fl f .
6067e49fc963SAndy Fiddaman.It Cm nolog
6068c10c16deSRichard LoweDo not save function definitions in the history file.
6069e49fc963SAndy Fiddaman.It Cm notify
6070e49fc963SAndy FiddamanSame as
6071e49fc963SAndy Fiddaman.Fl b .
6072e49fc963SAndy Fiddaman.It Cm nounset
6073e49fc963SAndy FiddamanSame as
6074e49fc963SAndy Fiddaman.Fl u .
6075e49fc963SAndy Fiddaman.It Cm pipefail
6076c10c16deSRichard LoweA pipeline does not complete until all components of the pipeline have
6077e49fc963SAndy Fiddamancompleted, and the return value is the value of the last
6078e49fc963SAndy Fiddaman.Sy non-zero
6079e49fc963SAndy Fiddamancommand to fail or zero if no command has failed.
6080e49fc963SAndy Fiddaman.It Cm privileged
6081e49fc963SAndy FiddamanSame as
6082e49fc963SAndy Fiddaman.Fl p .
6083e49fc963SAndy Fiddaman.It Cm showme
6084e49fc963SAndy FiddamanWhen enabled, simple commands or pipelines preceded by a a semicolon
6085e49fc963SAndy Fiddaman.Pq \&;
6086e49fc963SAndy Fiddamanis displayed as if the
6087e49fc963SAndy Fiddaman.Cm xtrace
6088e49fc963SAndy Fiddamanoption were enabled but is not executed.
6089e49fc963SAndy FiddamanOtherwise, the leading
6090e49fc963SAndy Fiddaman.Sy \&;
6091e49fc963SAndy Fiddamanis ignored.
6092e49fc963SAndy Fiddaman.It Cm trackall
6093e49fc963SAndy FiddamanSame as
6094e49fc963SAndy Fiddaman.Fl h .
6095e49fc963SAndy Fiddaman.It Cm verbose
6096e49fc963SAndy FiddamanSame as
6097e49fc963SAndy Fiddaman.Fl v .
6098e49fc963SAndy Fiddaman.It Cm vi
6099e49fc963SAndy FiddamanPuts you in insert mode of a
6100e49fc963SAndy Fiddaman.Sy vi
6101e49fc963SAndy Fiddamanstyle inline editor until you hit the escape character 033.
6102e49fc963SAndy FiddamanThis puts you in control mode.
6103e49fc963SAndy FiddamanA return sends the line.
6104e49fc963SAndy Fiddaman.It Cm viraw
6105e49fc963SAndy FiddamanEach character is processed as it is typed in
6106e49fc963SAndy Fiddaman.Sy vi
6107e49fc963SAndy Fiddamanmode.
6108e49fc963SAndy Fiddaman.It Cm xtrace
6109e49fc963SAndy FiddamanSame as
6110e49fc963SAndy Fiddaman.Fl x .
6111e49fc963SAndy Fiddaman.El
6112e49fc963SAndy Fiddaman.Pp
6113c10c16deSRichard LoweIf no option name is supplied, the current options settings are printed.
6114e49fc963SAndy Fiddaman.It Fl p
6115e49fc963SAndy FiddamanDisables processing of the
6116e49fc963SAndy Fiddaman.Pa $HOME/.profile
6117e49fc963SAndy Fiddamanfile and uses the file
6118e49fc963SAndy Fiddaman.Pa /etc/suid_profile
6119e49fc963SAndy Fiddamaninstead of the
6120e49fc963SAndy Fiddaman.Ev ENV
6121e49fc963SAndy Fiddamanfile.
6122e49fc963SAndy FiddamanThis mode is on whenever the effective
6123e49fc963SAndy Fiddaman.Sy uid Pq Sy gid
6124e49fc963SAndy Fiddamanis not equal to the real
6125e49fc963SAndy Fiddaman.Sy uid Pq Sy gid .
6126e49fc963SAndy FiddamanTurning this off causes the effective
6127e49fc963SAndy Fiddaman.Sy uid
6128e49fc963SAndy Fiddamanand
6129e49fc963SAndy Fiddaman.Sy gid
6130e49fc963SAndy Fiddamanto be set to the real
6131e49fc963SAndy Fiddaman.Sy uid
6132e49fc963SAndy Fiddamanand
6133e49fc963SAndy Fiddaman.Sy gid .
6134e49fc963SAndy Fiddaman.It Fl r
6135e49fc963SAndy FiddamanEnables the restricted shell.
6136e49fc963SAndy FiddamanThis option cannot be unset once set.
6137e49fc963SAndy Fiddaman.It Fl s
6138c10c16deSRichard LoweSort the positional parameters lexicographically.
6139e49fc963SAndy Fiddaman.It Fl t
6140e49fc963SAndy FiddamanObsolete.
6141e49fc963SAndy FiddamanExit after reading and executing one command.
6142e49fc963SAndy Fiddaman.It Fl u
6143e49fc963SAndy FiddamanTreat
6144e49fc963SAndy Fiddaman.Sy unset
6145e49fc963SAndy Fiddamanparameters as an error when substituting.
6146e49fc963SAndy Fiddaman.It Fl v
6147c10c16deSRichard LowePrint shell input lines as they are read.
6148e49fc963SAndy Fiddaman.It Fl x
6149c10c16deSRichard LowePrint commands and their arguments as they are executed.
6150e49fc963SAndy Fiddaman.It Fl \-
6151e49fc963SAndy FiddamanDo not change any of the options.
6152e49fc963SAndy FiddamanThis is useful in setting
6153e49fc963SAndy Fiddaman.Sy $1
6154e49fc963SAndy Fiddamanto a value
6155e49fc963SAndy Fiddamanbeginning with
6156e49fc963SAndy Fiddaman.Sy \- .
6157e49fc963SAndy FiddamanIf no arguments follow this option then the positional parameters are unset.
6158e49fc963SAndy Fiddaman.El
6159e49fc963SAndy Fiddaman.Pp
6160e49fc963SAndy FiddamanAs an obsolete feature, if the first
6161e49fc963SAndy Fiddaman.Ar arg
6162e49fc963SAndy Fiddamanis
6163e49fc963SAndy Fiddaman.Sy \-
6164e49fc963SAndy Fiddamanthen the
6165e49fc963SAndy Fiddaman.Fl x
6166e49fc963SAndy Fiddamanand
6167e49fc963SAndy Fiddaman.Fl v
6168e49fc963SAndy Fiddamanoptions are turned off and the next
6169e49fc963SAndy Fiddaman.Ar arg
6170e49fc963SAndy Fiddamanis treated as the first argument.
6171e49fc963SAndy FiddamanUsing
6172e49fc963SAndy Fiddaman.Sy \&+
6173e49fc963SAndy Fiddamanrather than
6174e49fc963SAndy Fiddaman.Fl
6175e49fc963SAndy Fiddamancauses these options to be turned off.
6176e49fc963SAndy FiddamanThese options can also be used upon invocation of the shell.
6177e49fc963SAndy FiddamanThe current set of options can be found in
6178e49fc963SAndy Fiddaman.Sy $- .
6179e49fc963SAndy FiddamanUnless
6180e49fc963SAndy Fiddaman.Fl A
6181e49fc963SAndy Fiddamanis specified, the remaining arguments are positional parameters and are
6182e49fc963SAndy Fiddamanassigned, in order, to
6183e49fc963SAndy Fiddaman.Sy $1 $2 \&... .
6184e49fc963SAndy FiddamanIf no arguments are specified, then
6185e49fc963SAndy Fiddamanthe names and values of all variables are printed on the standard output.
6186e49fc963SAndy Fiddaman.Pp
6187e49fc963SAndy Fiddaman.It Sy + Ic shift Op Ar n
6188e49fc963SAndy FiddamanThe positional parameters from
6189e49fc963SAndy Fiddaman.Sy $ Ns Ar n Ns Sy +1
6190e49fc963SAndy Fiddamanare renamed
6191e49fc963SAndy Fiddaman.Sy $1 \&... ,
6192e49fc963SAndy Fiddamanthe default
6193e49fc963SAndy Fiddaman.Ar n
6194e49fc963SAndy Fiddamanis
6195e49fc963SAndy Fiddaman.Sy 1 .
6196e49fc963SAndy FiddamanThe parameter
6197e49fc963SAndy Fiddaman.Ar n
6198e49fc963SAndy Fiddamancan be any arithmetic expression that evaluates to a non-negative number less
6199e49fc963SAndy Fiddamanthan or equal to
6200e49fc963SAndy Fiddaman.Sy $# .
6201e49fc963SAndy Fiddaman.Pp
6202e49fc963SAndy Fiddaman.It Ic sleep Ar seconds
6203c10c16deSRichard LoweSuspends execution for the number of decimal seconds or fractions of a second
6204e49fc963SAndy Fiddamanspecified by
6205e49fc963SAndy Fiddaman.Ar seconds .
6206e49fc963SAndy Fiddaman.Pp
6207e49fc963SAndy Fiddaman.It Sy + Ic trap Oo Fl p Oc Oo Ar action Oc Oo Ar sig Oc ...
6208e49fc963SAndy FiddamanThe
6209e49fc963SAndy Fiddaman.Fl p
6210e49fc963SAndy Fiddamanoption causes the trap action associated with each trap as specified by the
6211e49fc963SAndy Fiddamanarguments to be printed with appropriate quoting.
6212e49fc963SAndy FiddamanOtherwise,
6213e49fc963SAndy Fiddaman.Ar action
6214e49fc963SAndy Fiddamanis processed as if it were an argument to
6215e49fc963SAndy Fiddaman.Ic eval
6216e49fc963SAndy Fiddamanwhen the shell receives signal(s)
6217e49fc963SAndy Fiddaman.Ar sig .
6218e49fc963SAndy FiddamanEach
6219e49fc963SAndy Fiddaman.Ar sig
6220e49fc963SAndy Fiddamancan be specified as a number or as the name of the signal.
6221e49fc963SAndy FiddamanTrap commands are executed in order of signal number.
6222e49fc963SAndy FiddamanAny attempt to set a trap on a signal that was ignored on entry to the current
6223e49fc963SAndy Fiddamanshell is ineffective.
6224e49fc963SAndy FiddamanIf
6225e49fc963SAndy Fiddaman.Ar action
6226e49fc963SAndy Fiddamanis omitted and the first
6227e49fc963SAndy Fiddaman.Ar sig
6228e49fc963SAndy Fiddamanis a number, or if
6229e49fc963SAndy Fiddaman.Ar action
6230e49fc963SAndy Fiddamanis
6231e49fc963SAndy Fiddaman.Sy - ,
6232e49fc963SAndy Fiddamanthen the trap(s) for each
6233e49fc963SAndy Fiddaman.Ar sig
6234e49fc963SAndy Fiddamanare reset to their original values.
6235e49fc963SAndy FiddamanIf
6236e49fc963SAndy Fiddaman.Ar action
6237e49fc963SAndy Fiddamanis the null string then this signal is ignored by the shell and by the commands
6238e49fc963SAndy Fiddamanit invokes.
6239e49fc963SAndy FiddamanIf
6240e49fc963SAndy Fiddaman.Ar sig
6241e49fc963SAndy Fiddamanis
6242e49fc963SAndy Fiddaman.Sy ERR
6243e49fc963SAndy Fiddamanthen
6244e49fc963SAndy Fiddaman.Ar action
6245e49fc963SAndy Fiddamanis executed whenever a command has a
6246e49fc963SAndy Fiddaman.Sy non-zero
6247e49fc963SAndy Fiddamanexit status.
6248e49fc963SAndy FiddamanIf
6249e49fc963SAndy Fiddaman.Ar sig
6250e49fc963SAndy Fiddamanis
6251e49fc963SAndy Fiddaman.Sy DEBUG
6252e49fc963SAndy Fiddamanthen
6253e49fc963SAndy Fiddaman.Ar action
6254e49fc963SAndy Fiddamanis executed before each command.
6255e49fc963SAndy FiddamanThe variable
6256e49fc963SAndy Fiddaman.Sy \&.sh.command
6257e49fc963SAndy Fiddamancontains the contents of the current command line when
6258e49fc963SAndy Fiddaman.Ar action
6259e49fc963SAndy Fiddamanis running.
6260e49fc963SAndy FiddamanIf
6261e49fc963SAndy Fiddaman.Ar sig
6262e49fc963SAndy Fiddamanis
6263e49fc963SAndy Fiddaman.Sy 0
6264e49fc963SAndy Fiddamanor
6265e49fc963SAndy Fiddaman.Sy EXIT
6266e49fc963SAndy Fiddamanand the trap statement is executed inside the body of a function defined with
6267e49fc963SAndy Fiddamanthe
6268e49fc963SAndy Fiddaman.Ic function Ar name
6269e49fc963SAndy Fiddamansyntax, then the command
6270e49fc963SAndy Fiddaman.Ar action
6271e49fc963SAndy Fiddamanis executed after the function completes.
6272e49fc963SAndy FiddamanIf
6273e49fc963SAndy Fiddaman.Ar sig
6274e49fc963SAndy Fiddamanis
6275e49fc963SAndy Fiddaman.Sy 0
6276e49fc963SAndy Fiddamanor
6277e49fc963SAndy Fiddaman.Sy EXIT
6278e49fc963SAndy Fiddamanfor a trap set outside any function then the command
6279e49fc963SAndy Fiddaman.Ar action
6280e49fc963SAndy Fiddamanis executed on exit from the shell.
6281e49fc963SAndy FiddamanIf
6282e49fc963SAndy Fiddaman.Ar sig
6283e49fc963SAndy Fiddamanis
6284e49fc963SAndy Fiddaman.Sy KEYBD ,
6285e49fc963SAndy Fiddamanthen
6286e49fc963SAndy Fiddaman.Ar action
6287e49fc963SAndy Fiddamanis executed whenever a key is read while in
6288e49fc963SAndy Fiddaman.Sy emacs ,
6289e49fc963SAndy Fiddaman.Sy gmacs ,
6290e49fc963SAndy Fiddamanor
6291e49fc963SAndy Fiddaman.Sy vi
6292e49fc963SAndy Fiddamanmode.
6293e49fc963SAndy FiddamanThe
6294e49fc963SAndy Fiddaman.Sy trap
6295e49fc963SAndy Fiddamancommand with no arguments prints a list of commands associated with each signal
6296e49fc963SAndy Fiddamannumber.
6297e49fc963SAndy Fiddaman.Pp
6298e49fc963SAndy Fiddaman.It Ic true
6299e49fc963SAndy FiddamanDoes nothing, and exits
6300e49fc963SAndy Fiddaman.Sy 0 .
6301e49fc963SAndy FiddamanUsed with while for infinite loops.
6302e49fc963SAndy Fiddaman.Pp
6303e49fc963SAndy Fiddaman.It Xo
6304e49fc963SAndy Fiddaman.Bk -words
6305e49fc963SAndy Fiddaman.Sy ++ Ic typeset
6306e49fc963SAndy Fiddaman.Op Sy + Ns Fl ACHSfblmnprtux
6307e49fc963SAndy Fiddaman.Op Sy + Ns Fl EFLRXZi Ns Op Ar n
6308e49fc963SAndy Fiddaman.Op Sy + Ns Fl M Op Ar mapname
6309e49fc963SAndy Fiddaman.Op Fl T Op Ar tname Ns Sy =( Ns Ar assign_list Ns Sy \&)
6310e49fc963SAndy Fiddaman.Op Fl h Ar str
6311e49fc963SAndy Fiddaman.Op Fl a Op Ar type
6312e49fc963SAndy Fiddaman.Op Ar vname Ns Op Sy = Ns Ar value
6313e49fc963SAndy Fiddaman.Ek
6314e49fc963SAndy Fiddaman.Xc
6315e49fc963SAndy Fiddaman.Pp
6316e49fc963SAndy FiddamanSets attributes and values for shell variables and functions.
6317e49fc963SAndy FiddamanWhen invoked inside a function defined with the
6318e49fc963SAndy Fiddaman.Sy function Ar name
6319e49fc963SAndy Fiddamansyntax, a new instance of the variable
6320e49fc963SAndy Fiddaman.Ar vname
6321e49fc963SAndy Fiddamanis created, and the variable's value and type are restored when the function
6322e49fc963SAndy Fiddamancompletes.
6323e49fc963SAndy Fiddaman.Pp
6324e49fc963SAndy FiddamanUsing
6325e49fc963SAndy Fiddaman.Sy +
6326e49fc963SAndy Fiddamanrather than
6327e49fc963SAndy Fiddaman.Fl
6328e49fc963SAndy Fiddamancauses these options to be turned off.
6329e49fc963SAndy FiddamanIf no
6330e49fc963SAndy Fiddaman.Ar vname
6331e49fc963SAndy Fiddamanarguments are specified, a list of
6332e49fc963SAndy Fiddaman.Ar vname Ns No s
6333e49fc963SAndy Fiddaman.Po and optionally the
6334e49fc963SAndy Fiddaman.Ar value Ns No s
6335e49fc963SAndy Fiddaman.Pc
6336e49fc963SAndy Fiddamanof the variables is printed.
6337e49fc963SAndy FiddamanUsing
6338e49fc963SAndy Fiddaman.Sy +
6339e49fc963SAndy Fiddamanrather than
6340e49fc963SAndy Fiddaman.Fl -
6341e49fc963SAndy Fiddamankeeps the values from being printed.
6342e49fc963SAndy FiddamanThe
6343e49fc963SAndy Fiddaman.Fl p
6344e49fc963SAndy Fiddamanoption causes
6345e49fc963SAndy Fiddaman.Ic typeset
6346c10c16deSRichard Lowefollowed by the option letters to be printed before each name rather than the
6347e49fc963SAndy Fiddamannames of the options.
6348e49fc963SAndy FiddamanIf any option other than
6349e49fc963SAndy Fiddaman.Fl p
6350e49fc963SAndy Fiddamanis specified, only those variables which have all of the specified options are
6351c10c16deSRichard Loweprinted.
6352e49fc963SAndy FiddamanOtherwise, the
6353e49fc963SAndy Fiddaman.Ar vname Ns No s
6354e49fc963SAndy Fiddamanand
6355e49fc963SAndy Fiddaman.Ar attribute Ns No s
6356e49fc963SAndy Fiddamanof all variables that have attributes are printed.
6357e49fc963SAndy Fiddaman.Pp
6358c10c16deSRichard LoweThe following list of attributes can be specified:
6359e49fc963SAndy Fiddaman.Bl -tag -width Ds
6360e49fc963SAndy Fiddaman.It Fl a
6361e49fc963SAndy FiddamanDeclares
6362e49fc963SAndy Fiddaman.Ar vname
6363e49fc963SAndy Fiddamanto be an indexed array.
6364e49fc963SAndy FiddamanThis is optional unless except for compound variable assignments.
6365e49fc963SAndy Fiddaman.It Fl A
6366e49fc963SAndy FiddamanDeclares
6367e49fc963SAndy Fiddaman.Ar vname
6368e49fc963SAndy Fiddamanto be an associative array.
6369e49fc963SAndy FiddamanSub-scripts are strings rather than arithmetic expressions.
6370e49fc963SAndy Fiddaman.It Fl b
6371e49fc963SAndy FiddamanThe variable can hold any number of bytes of data.
6372e49fc963SAndy FiddamanThe data can be text or binary.
6373e49fc963SAndy FiddamanThe value is represented by the
6374e49fc963SAndy Fiddaman.Sy base64
6375e49fc963SAndy Fiddamanencoding of the data.
6376e49fc963SAndy FiddamanIf
6377e49fc963SAndy Fiddaman.Fl Z
6378e49fc963SAndy Fiddamanis also specified, the size in bytes of the data in the buffer is determined by
6379e49fc963SAndy Fiddamanthe size associated with the
6380e49fc963SAndy Fiddaman.Fl Z .
6381e49fc963SAndy FiddamanIf the
6382e49fc963SAndy Fiddaman.Sy base64
6383e49fc963SAndy Fiddamanstring assigned results in more data, it is truncated.
6384e49fc963SAndy FiddamanOtherwise, it is filled with bytes whose value is zero.
6385e49fc963SAndy FiddamanThe
6386e49fc963SAndy Fiddaman.Ic printf
6387e49fc963SAndy Fiddamanformat
6388e49fc963SAndy Fiddaman.Cm \&%B
6389e49fc963SAndy Fiddamancan be used to output the actual data in this buffer instead of the
6390e49fc963SAndy Fiddaman.Sy base64
6391e49fc963SAndy Fiddamanencoding of the data.
6392e49fc963SAndy Fiddaman.It Fl C
6393e49fc963SAndy FiddamanCauses each
6394e49fc963SAndy Fiddaman.Ar vname
6395e49fc963SAndy Fiddamanto be a compound variable.
6396e49fc963SAndy FiddamanIf
6397e49fc963SAndy Fiddaman.Ar value
6398e49fc963SAndy Fiddamannames a compound variable it is copied into
6399e49fc963SAndy Fiddaman.Ar vname .
6400e49fc963SAndy FiddamanOtherwise, it unsets each
6401e49fc963SAndy Fiddaman.Ar vname .
6402e49fc963SAndy Fiddaman.It Fl E
6403e49fc963SAndy FiddamanDeclares
6404e49fc963SAndy Fiddaman.Ar vname
6405e49fc963SAndy Fiddamanto be a double precision floating point number.
6406e49fc963SAndy FiddamanIf
6407e49fc963SAndy Fiddaman.Ar n
6408e49fc963SAndy Fiddamanis
6409e49fc963SAndy Fiddaman.Sy non-zero ,
6410e49fc963SAndy Fiddamanit defines the number of significant figures that are used when expanding
6411e49fc963SAndy Fiddaman.Ar vname .
6412e49fc963SAndy FiddamanOtherwise, ten significant figures is used.
6413e49fc963SAndy Fiddaman.It Fl f
6414e49fc963SAndy FiddamanThe names refer to function names rather than variable names.
6415e49fc963SAndy FiddamanNo assignments can be made and the only other valid options are
6416e49fc963SAndy Fiddaman.Fl t ,
6417e49fc963SAndy Fiddaman.Fl u ,
6418e49fc963SAndy Fiddamanand
6419e49fc963SAndy Fiddaman.Fl x .
6420e49fc963SAndy FiddamanThe
6421e49fc963SAndy Fiddaman.Fl t
6422e49fc963SAndy Fiddamanoption turns on execution tracing for this function.
6423e49fc963SAndy FiddamanThe
6424e49fc963SAndy Fiddaman.Fl u
6425e49fc963SAndy Fiddamanoption causes this function to be marked undefined.
6426e49fc963SAndy FiddamanThe
6427e49fc963SAndy Fiddaman.Ev FPATH
6428c10c16deSRichard Lowevariable is searched to find the function definition when the function is
6429e49fc963SAndy Fiddamanreferenced.
6430e49fc963SAndy FiddamanIf no options other than
6431e49fc963SAndy Fiddaman.Fl f
6432e49fc963SAndy Fiddamanare specified, then the function definition is displayed on standard output.
6433e49fc963SAndy FiddamanIf
6434e49fc963SAndy Fiddaman.Sy +f
6435e49fc963SAndy Fiddamanis specified, then a line containing the function name followed by a shell
6436e49fc963SAndy Fiddamancomment containing the line number and path name of the file where this
6437e49fc963SAndy Fiddamanfunction was defined, if any, is displayed.
6438b30d1939SAndy FiddamanThe names refer to function names rather than variable names.
6439b30d1939SAndy FiddamanNo assignments can be made and the only other valid options are
6440e49fc963SAndy Fiddaman.Fl S ,
6441e49fc963SAndy Fiddaman.Fl t ,
6442e49fc963SAndy Fiddaman.Fl u
6443e49fc963SAndy Fiddamanand
6444e49fc963SAndy Fiddaman.Fl x .
6445e49fc963SAndy FiddamanThe
6446e49fc963SAndy Fiddaman.Fl S
6447e49fc963SAndy Fiddamanoption can be used with discipline functions defined in a type to indicate that
6448e49fc963SAndy Fiddamanthe function is static.
6449e49fc963SAndy FiddamanFor a static function, the same method will be used by all instances of that
6450e49fc963SAndy Fiddamantype no matter which instance references it.
6451e49fc963SAndy FiddamanIn addition, it can only use value of variables from the original type
6452e49fc963SAndy Fiddamandefinition.
6453e49fc963SAndy FiddamanThese discipline functions cannot be redefined in any type instance.
6454e49fc963SAndy FiddamanThe
6455e49fc963SAndy Fiddaman.Fl t
6456e49fc963SAndy Fiddamanoption turns on execution tracing for this function.
6457e49fc963SAndy FiddamanThe
6458e49fc963SAndy Fiddaman.Fl u
6459e49fc963SAndy Fiddamanoption causes this function to be marked undefined.
6460e49fc963SAndy FiddamanThe
6461e49fc963SAndy Fiddaman.Ev FPATH
6462e49fc963SAndy Fiddamanvariable will be searched to find the function definition when the function is
6463e49fc963SAndy Fiddamanreferenced.
6464e49fc963SAndy FiddamanIf no options other than
6465e49fc963SAndy Fiddaman.Fl f
6466e49fc963SAndy Fiddamanare specified, then the function definition will be displayed on standard
6467e49fc963SAndy Fiddamanoutput.
6468e49fc963SAndy FiddamanIf
6469e49fc963SAndy Fiddaman.Sy +f
6470e49fc963SAndy Fiddamanis specified, then a line containing the function name followed by a shell
6471e49fc963SAndy Fiddamancomment containing the line number and path name of the file where this
6472e49fc963SAndy Fiddamanfunction was defined, if any, is displayed.
6473e49fc963SAndy FiddamanThe exit status can be used to determine whether the function is defined so
6474e49fc963SAndy Fiddamanthat
6475e49fc963SAndy Fiddaman.Ic typeset Fl f Sy .sh.math\&. Ns Ar name
6476e49fc963SAndy Fiddamanwill return
6477e49fc963SAndy Fiddaman.Sy 0
6478e49fc963SAndy Fiddamanwhen math function
6479e49fc963SAndy Fiddaman.Ar name
6480e49fc963SAndy Fiddamanis defined and non-zero otherwise.
6481e49fc963SAndy Fiddaman.Pp
6482e49fc963SAndy FiddamanThe
6483e49fc963SAndy Fiddaman.Fl i
6484e49fc963SAndy Fiddamanattribute cannot be specified with
6485e49fc963SAndy Fiddaman.Fl f .
6486e49fc963SAndy Fiddaman.It Fl F
6487e49fc963SAndy FiddamanDeclares
6488e49fc963SAndy Fiddaman.Ar vname
6489e49fc963SAndy Fiddamanto be a double precision floating point number.
6490e49fc963SAndy FiddamanIf
6491e49fc963SAndy Fiddaman.Ar n
6492e49fc963SAndy Fiddamanis
6493e49fc963SAndy Fiddaman.Sy non-zero ,
6494e49fc963SAndy Fiddamanit defines the number of places after the decimal point that are used when
6495e49fc963SAndy Fiddamanexpanding
6496e49fc963SAndy Fiddaman.Ar vname .
6497e49fc963SAndy FiddamanOtherwise ten places after the decimal point is used.
6498e49fc963SAndy Fiddaman.It Fl h
6499b30d1939SAndy FiddamanUsed within type definitions to add information when generating information
6500e49fc963SAndy Fiddamanabout the sub-variable on the man page.
6501e49fc963SAndy FiddamanIt is ignored when used outside of a type definition.
6502e49fc963SAndy FiddamanWhen used with
6503e49fc963SAndy Fiddaman.Fl f
6504e49fc963SAndy Fiddamanthe information is associated with the corresponding discipline function.
6505e49fc963SAndy Fiddaman.It Fl H
6506c10c16deSRichard LoweThis option provides UNIX to hostname file mapping on non-UNIX machines.
6507e49fc963SAndy Fiddaman.It Fl i
6508e49fc963SAndy FiddamanDeclares
6509e49fc963SAndy Fiddaman.Ar vname
6510e49fc963SAndy Fiddamanto be represented internally as integer.
6511e49fc963SAndy FiddamanThe right hand side of an assignment is evaluated as an arithmetic expression
6512e49fc963SAndy Fiddamanwhen assigning to an integer.
6513e49fc963SAndy FiddamanIf
6514e49fc963SAndy Fiddaman.Ar n
6515e49fc963SAndy Fiddamanis
6516e49fc963SAndy Fiddaman.Sy non-zero ,
6517e49fc963SAndy Fiddamanit defines the output arithmetic base, otherwise the output base is ten.
6518e49fc963SAndy Fiddaman.Pp
6519e49fc963SAndy FiddamanThe
6520e49fc963SAndy Fiddaman.Fl i
6521e49fc963SAndy Fiddamanattribute cannot be specified along with
6522e49fc963SAndy Fiddaman.Fl R ,
6523e49fc963SAndy Fiddaman.Fl L ,
6524e49fc963SAndy Fiddaman.Fl Z ,
6525e49fc963SAndy Fiddamanor
6526e49fc963SAndy Fiddaman.Fl f .
6527e49fc963SAndy Fiddaman.It Fl l
6528e49fc963SAndy FiddamanUsed with
6529e49fc963SAndy Fiddaman.Fl i ,
6530e49fc963SAndy Fiddaman.Fl E
6531e49fc963SAndy Fiddamanor
6532e49fc963SAndy Fiddaman.Fl F
6533e49fc963SAndy Fiddamanto indicate long integer, or long float.
6534b30d1939SAndy FiddamanOtherwise, all upper-case characters are converted to lower-case.
6535e49fc963SAndy FiddamanThe upper-case option,
6536e49fc963SAndy Fiddaman.Fl u ,
6537e49fc963SAndy Fiddamanis turned off.
6538e49fc963SAndy FiddamanEquivalent to
6539e49fc963SAndy Fiddaman.Fl M Cm tolower .
6540e49fc963SAndy Fiddaman.It Fl L
6541e49fc963SAndy FiddamanLeft justify and remove leading blanks from
6542e49fc963SAndy Fiddaman.Ar value .
6543e49fc963SAndy FiddamanIf
6544e49fc963SAndy Fiddaman.Ar n
6545e49fc963SAndy Fiddamanis
6546e49fc963SAndy Fiddaman.Sy non-zero ,
6547e49fc963SAndy Fiddamanit defines the width of the field, otherwise it is determined by the width of
6548e49fc963SAndy Fiddamanthe value of first assignment.
6549e49fc963SAndy FiddamanWhen the variable is assigned to, it is filled on the right with blanks or
6550e49fc963SAndy Fiddamantruncated, if necessary, to fit into the field.
6551e49fc963SAndy FiddamanThe
6552e49fc963SAndy Fiddaman.Fl R
6553e49fc963SAndy Fiddamanoption is turned off.
6554e49fc963SAndy Fiddaman.Pp
6555e49fc963SAndy FiddamanThe
6556e49fc963SAndy Fiddaman.Fl i
6557e49fc963SAndy Fiddamanattribute cannot be specified with
6558e49fc963SAndy Fiddaman.Fl L .
6559e49fc963SAndy Fiddaman.It Fl m
6560e49fc963SAndy Fiddamanmoves or renames the variable.
6561e49fc963SAndy FiddamanThe value is the name of a variable whose value will be moved to
6562e49fc963SAndy Fiddaman.Ar vname .
6563e49fc963SAndy FiddamanThe original variable will be unset.
6564e49fc963SAndy FiddamanCannot be used with any other options.
6565e49fc963SAndy Fiddaman.It Fl M
6566e49fc963SAndy FiddamanUse the character mapping
6567e49fc963SAndy Fiddaman.Ar mapping
6568e49fc963SAndy Fiddamansuch as
6569e49fc963SAndy Fiddaman.Sy tolower
6570e49fc963SAndy Fiddamanand
6571e49fc963SAndy Fiddaman.Sy toupper
6572e49fc963SAndy Fiddamanwhen assigning a value to each of the specified operands.
6573e49fc963SAndy FiddamanWhen
6574e49fc963SAndy Fiddaman.Ar mapping
6575e49fc963SAndy Fiddamanis specified and there are not operands, all variables that use this mapping
6576e49fc963SAndy Fiddamanare written to standard output.
6577e49fc963SAndy FiddamanWhen
6578e49fc963SAndy Fiddaman.Ar mapping
6579e49fc963SAndy Fiddamanis omitted and there are no operands, all mapped variables are written to
6580e49fc963SAndy Fiddamanstandard output.
6581e49fc963SAndy Fiddaman.It Fl n
6582e49fc963SAndy FiddamanDeclares
6583e49fc963SAndy Fiddaman.Ar vname
6584e49fc963SAndy Fiddamanto be a reference to the variable whose name is defined by the value of
6585e49fc963SAndy Fiddamanvariable
6586e49fc963SAndy Fiddaman.Ar vname .
6587e49fc963SAndy FiddamanThis is usually used to reference a variable inside a function whose name has
6588e49fc963SAndy Fiddamanbeen passed as an argument.
6589e49fc963SAndy Fiddaman.It Fl p
6590e49fc963SAndy FiddamanThe name, attributes and values for the given
6591e49fc963SAndy Fiddaman.Ar vname
6592b30d1939SAndy Fiddamanare written on standard output in a form that can be used as shell input.
6593e49fc963SAndy FiddamanIf
6594e49fc963SAndy Fiddaman.Sy +p
6595e49fc963SAndy Fiddamanis specified, then the values are not displayed.
6596e49fc963SAndy Fiddaman.It Fl R
6597e49fc963SAndy FiddamanRight justify and fill with leading blanks.
6598e49fc963SAndy FiddamanIf
6599e49fc963SAndy Fiddaman.Ar n
6600e49fc963SAndy Fiddamanis
6601e49fc963SAndy Fiddaman.Sy non-zero ,
6602e49fc963SAndy Fiddamanit defines the width of the field, otherwise it is determined by the width of
6603e49fc963SAndy Fiddamanthe value of first assignment.
6604e49fc963SAndy FiddamanThe field is left filled with blanks or truncated from the end if the variable
6605e49fc963SAndy Fiddamanis reassigned.
6606e49fc963SAndy FiddamanThe
6607e49fc963SAndy Fiddaman.Fl L
6608e49fc963SAndy Fiddamanoption is turned off.
6609e49fc963SAndy Fiddaman.Pp
6610e49fc963SAndy FiddamanThe
6611e49fc963SAndy Fiddaman.Fl i
6612e49fc963SAndy Fiddamanattribute cannot be specified with
6613e49fc963SAndy Fiddaman.Fl R .
6614e49fc963SAndy Fiddaman.It Fl r
6615e49fc963SAndy FiddamanThe specified
6616e49fc963SAndy Fiddaman.Ar vname Ns No s
6617e49fc963SAndy Fiddamanare marked read-only and these names cannot be changed by subsequent
6618e49fc963SAndy Fiddamanassignment.
6619e49fc963SAndy Fiddaman.It Fl S
6620e49fc963SAndy FiddamanWhen used within the
6621e49fc963SAndy Fiddaman.Ar assign_list
6622e49fc963SAndy Fiddamanof a type definition, it causes the specified sub-variable to be shared by all
6623e49fc963SAndy Fiddamaninstances of the type.
6624e49fc963SAndy FiddamanWhen used inside a function defined with the
6625e49fc963SAndy Fiddaman.Ic function
6626e49fc963SAndy Fiddamanreserved word, the specified variables will have
6627e49fc963SAndy Fiddaman.Em function static
6628e49fc963SAndy Fiddamanscope.
6629e49fc963SAndy FiddamanOtherwise, the variable is unset prior to processing the assignment list.
6630e49fc963SAndy Fiddaman.It Fl t
6631e49fc963SAndy FiddamanTags the variables.
6632e49fc963SAndy FiddamanTags are user definable and have no special meaning to the shell.
6633e49fc963SAndy Fiddaman.It Fl T
6634e49fc963SAndy FiddamanIf followed by
6635e49fc963SAndy Fiddaman.Ar tname ,
6636e49fc963SAndy Fiddamanit creates a type named by
6637e49fc963SAndy Fiddaman.Ar tname
6638e49fc963SAndy Fiddamanusing the compound assignment
6639e49fc963SAndy Fiddaman.Ar assign_list
6640e49fc963SAndy Fiddamanto
6641e49fc963SAndy Fiddaman.Ar tname .
6642e49fc963SAndy FiddamanOtherwise, it writes all
6643b30d1939SAndy Fiddamanthe type definitions to standard output.
6644e49fc963SAndy Fiddaman.It Fl u
6645e49fc963SAndy FiddamanWhen given along with
6646e49fc963SAndy Fiddaman.Fl i
6647e49fc963SAndy Fiddamanspecifies unsigned integer.
6648b30d1939SAndy FiddamanOtherwise, all lower-case characters are converted to upper-case.
6649e49fc963SAndy FiddamanThe lower-case option,
6650e49fc963SAndy Fiddaman.Fl l ,
6651e49fc963SAndy Fiddamanis turned off.
6652e49fc963SAndy FiddamanEquivalent to
6653e49fc963SAndy Fiddaman.Fl M Cm toupper .
6654e49fc963SAndy Fiddaman.It Fl x
6655e49fc963SAndy FiddamanThe specified
6656e49fc963SAndy Fiddaman.Ar vname Ns No s
6657e49fc963SAndy Fiddamanare marked for automatic export to the environment of subsequently-executed
6658e49fc963SAndy Fiddamancommands.
6659e49fc963SAndy FiddamanVariables whose names contain a
6660e49fc963SAndy Fiddaman.Sy \&.
6661b30d1939SAndy Fiddamancannot be exported.
6662e49fc963SAndy Fiddaman.It Fl X
6663e49fc963SAndy FiddamanDeclares
6664e49fc963SAndy Fiddaman.Ar vname
6665e49fc963SAndy Fiddamanto be a double precision floating point number and expands using the
6666e49fc963SAndy Fiddaman.Cm %a
6667e49fc963SAndy Fiddamanformat of ISO-C99.
6668e49fc963SAndy FiddamanIf
6669e49fc963SAndy Fiddaman.Ar n
6670e49fc963SAndy Fiddamanis non-zero, it defines the number of hex digits after the radix point that is
6671e49fc963SAndy Fiddamanused when expanding
6672e49fc963SAndy Fiddaman.Ar vname .
6673b30d1939SAndy FiddamanThe default is 10.
6674e49fc963SAndy Fiddaman.It Fl Z
6675c10c16deSRichard LoweRight justify and fill with leading zeros if the first non-blank character is a
6676e49fc963SAndy Fiddamandigit and the
6677e49fc963SAndy Fiddaman.Fl L
6678e49fc963SAndy Fiddamanoption has not been set.
6679e49fc963SAndy FiddamanRemove leading zeros if the
6680e49fc963SAndy Fiddaman.Fl L
6681e49fc963SAndy Fiddamanoption is also set.
6682e49fc963SAndy FiddamanIf
6683e49fc963SAndy Fiddaman.Ar n
6684e49fc963SAndy Fiddamanis
6685e49fc963SAndy Fiddaman.Sy non-zero ,
6686e49fc963SAndy Fiddamanit defines the width of the field, otherwise it is determined by the width of
6687e49fc963SAndy Fiddamanthe value of first assignment.
6688e49fc963SAndy Fiddaman.Pp
6689e49fc963SAndy FiddamanThe
6690e49fc963SAndy Fiddaman.Fl i
6691e49fc963SAndy Fiddamanattribute cannot be specified with
6692e49fc963SAndy Fiddaman.Fl Z .
6693e49fc963SAndy Fiddaman.El
6694e49fc963SAndy Fiddaman.Pp
6695e49fc963SAndy Fiddaman.It Ic ulimit Oo Fl HSacdfmnpstv Oc Op Ar limit
6696e49fc963SAndy FiddamanSet or display a resource limit.
6697e49fc963SAndy FiddamanMany systems do not support one or more of these limits.
6698e49fc963SAndy FiddamanThe limit for a specified resource is set when
6699e49fc963SAndy Fiddaman.Ar limit
6700e49fc963SAndy Fiddamanis specified.
6701e49fc963SAndy FiddamanThe value of
6702e49fc963SAndy Fiddaman.Ar limit
6703e49fc963SAndy Fiddamancan be a number in the unit specified with each resource, or the value
6704e49fc963SAndy Fiddamanunlimited.
6705e49fc963SAndy FiddamanWhen more than one resource is specified, then the limit name and unit is
6706e49fc963SAndy Fiddamanprinted before the value.
6707e49fc963SAndy Fiddaman.Pp
6708e49fc963SAndy FiddamanIf no option is specified,
6709e49fc963SAndy Fiddaman.Fl f
6710e49fc963SAndy Fiddamanis assumed.
6711e49fc963SAndy Fiddaman.Pp
6712c10c16deSRichard LoweThe following are the available resource limits:
6713e49fc963SAndy Fiddaman.Bl -tag -width Ds
6714e49fc963SAndy Fiddaman.It Fl a
6715c10c16deSRichard LoweLists all of the current resource limits.
6716e49fc963SAndy Fiddaman.It Fl c
6717c10c16deSRichard LoweThe number of 512-byte blocks on the size of core dumps.
6718e49fc963SAndy Fiddaman.It Fl d
6719c10c16deSRichard LoweThe number of Kbytes on the size of the data area.
6720e49fc963SAndy Fiddaman.It Fl f
6721c10c16deSRichard LoweThe number of 512-byte blocks on files that can be written by the current
6722c10c16deSRichard Loweprocess or by child processes (files of any size can be read).
6723e49fc963SAndy Fiddaman.It Fl H
6724c10c16deSRichard LoweSpecifies a hard limit for the specified resource.
6725e49fc963SAndy Fiddaman.Pp
6726c10c16deSRichard LoweA hard limit cannot be increased once it is set.
6727e49fc963SAndy Fiddaman.Pp
6728e49fc963SAndy FiddamanIf neither the
6729e49fc963SAndy Fiddaman.Fl H
6730e49fc963SAndy Fiddamannor
6731e49fc963SAndy Fiddaman.Fl S
6732e49fc963SAndy Fiddamanoption is specified, the limit applies to
6733e49fc963SAndy Fiddamanboth.
6734e49fc963SAndy FiddamanThe current resource limit is printed when
6735e49fc963SAndy Fiddaman.Ar limit
6736e49fc963SAndy Fiddamanis omitted.
6737e49fc963SAndy FiddamanIn this case, the soft limit is printed unless
6738e49fc963SAndy Fiddaman.Fl H
6739e49fc963SAndy Fiddamanis specified.
6740e49fc963SAndy Fiddaman.It Fl m
6741c10c16deSRichard LoweThe number of Kbytes on the size of physical memory.
6742e49fc963SAndy Fiddaman.It Fl n
6743c10c16deSRichard LoweThe number of file descriptors plus 1.
6744e49fc963SAndy Fiddaman.It Fl p
6745c10c16deSRichard LoweThe number of 512-byte blocks for pipe buffering.
6746e49fc963SAndy Fiddaman.It Fl s
6747c10c16deSRichard LoweThe number of Kbytes on the size of the stack area.
6748e49fc963SAndy Fiddaman.It Fl S
6749c10c16deSRichard LoweSpecifies a soft limit for the specified resource.
6750e49fc963SAndy Fiddaman.Pp
6751c10c16deSRichard LoweA soft limit can be increased up to the value of the hard limit.
6752e49fc963SAndy Fiddaman.Pp
6753e49fc963SAndy FiddamanIf neither the
6754e49fc963SAndy Fiddaman.Fl H
6755e49fc963SAndy Fiddamannor
6756e49fc963SAndy Fiddaman.Fl S
6757e49fc963SAndy Fiddamanoption is specified, the limit applies to both.
6758e49fc963SAndy FiddamanThe current resource limit is printed when
6759e49fc963SAndy Fiddaman.Ar limit
6760e49fc963SAndy Fiddamanis omitted.
6761e49fc963SAndy FiddamanIn this case, the soft limit is printed unless
6762e49fc963SAndy Fiddaman.Fl H
6763e49fc963SAndy Fiddamanis specified.
6764e49fc963SAndy Fiddaman.It Fl t
6765c10c16deSRichard LoweThe number of CPU seconds to be used by each process.
6766e49fc963SAndy Fiddaman.It Fl v
6767c10c16deSRichard LoweThe number of Kbytes for virtual memory.
6768e49fc963SAndy Fiddaman.El
6769e49fc963SAndy Fiddaman.Pp
6770e49fc963SAndy Fiddaman.It Ic umask Oo Fl S Oc Op Ar mask
6771e49fc963SAndy FiddamanThe user file-creation mask is set to
6772e49fc963SAndy Fiddaman.Ar mask .
6773e49fc963SAndy Fiddaman.Ar mask
6774e49fc963SAndy Fiddamancan either be an octal number or a symbolic value as described in
6775e49fc963SAndy Fiddaman.Xr chmod 1 .
6776e49fc963SAndy Fiddaman.Pp
6777e49fc963SAndy FiddamanIf a symbolic value is specified, the new
6778e49fc963SAndy Fiddaman.Sy umask
6779e49fc963SAndy Fiddamanvalue is the complement of the result of applying
6780e49fc963SAndy Fiddaman.Ar mask
6781e49fc963SAndy Fiddamanto the complement of the previous
6782e49fc963SAndy Fiddaman.Sy umask
6783e49fc963SAndy Fiddamanvalue.
6784e49fc963SAndy FiddamanIf
6785e49fc963SAndy Fiddaman.Ar mask
6786e49fc963SAndy Fiddamanis omitted, the current value of the mask is printed.
6787e49fc963SAndy FiddamanThe
6788e49fc963SAndy Fiddaman.Fl S
6789e49fc963SAndy Fiddamanoption causes the mode to be printed as a symbolic value.
6790c10c16deSRichard LoweOtherwise, the mask is printed in octal.
6791e49fc963SAndy Fiddaman.Pp
6792e49fc963SAndy FiddamanSee
6793e49fc963SAndy Fiddaman.Xr umask 2
6794e49fc963SAndy Fiddaman.Pp
6795e49fc963SAndy Fiddaman.It Sy + Ic unalias Oo Fl a Oc Ar name No ...
6796e49fc963SAndy FiddamanThe aliases specified by the list of
6797e49fc963SAndy Fiddaman.Ar name Ns No s
6798e49fc963SAndy Fiddamanare removed from the alias list.
6799e49fc963SAndy FiddamanThe
6800e49fc963SAndy Fiddaman.Fl a
6801e49fc963SAndy Fiddamanoption causes all the aliases to be unset.
6802e49fc963SAndy Fiddaman.Pp
6803e49fc963SAndy Fiddaman.It Sy + Ic unset Oo Fl fnv Oc Ar vname No ...
6804e49fc963SAndy FiddamanThe variables specified by the list of
6805e49fc963SAndy Fiddaman.Ar vname Ns No s
6806e49fc963SAndy Fiddamanare unassigned, i.e., their values and attributes are erased.
6807e49fc963SAndy FiddamanRead-only variables cannot be unset.
6808e49fc963SAndy FiddamanIf the
6809e49fc963SAndy Fiddaman.Fl f
6810e49fc963SAndy Fiddamanoption is set, then the names refer to function names.
6811e49fc963SAndy FiddamanIf the
6812e49fc963SAndy Fiddaman.Fl v
6813e49fc963SAndy Fiddamanoption is set, then the names refer to variable names.
6814e49fc963SAndy FiddamanThe
6815e49fc963SAndy Fiddaman.Fl f
6816e49fc963SAndy Fiddamanoption overrides
6817e49fc963SAndy Fiddaman.Fl v .
6818e49fc963SAndy FiddamanIf
6819e49fc963SAndy Fiddaman.Fl n
6820e49fc963SAndy Fiddamanis set and
6821e49fc963SAndy Fiddaman.Ar name
6822e49fc963SAndy Fiddamanis a name reference, then
6823e49fc963SAndy Fiddaman.Ar name
6824e49fc963SAndy Fiddamanis unset rather than the variable that it references.
6825e49fc963SAndy FiddamanThe default is equivalent to
6826e49fc963SAndy Fiddaman.Fl v .
6827e49fc963SAndy FiddamanUnsetting
6828e49fc963SAndy Fiddaman.Ev LINENO ,
6829e49fc963SAndy Fiddaman.Ev MAILCHECK ,
6830e49fc963SAndy Fiddaman.Ev OPTARG ,
6831e49fc963SAndy Fiddaman.Ev OPTIND ,
6832e49fc963SAndy Fiddaman.Ev RANDOM ,
6833e49fc963SAndy Fiddaman.Ev SECONDS ,
6834e49fc963SAndy Fiddaman.Ev TMOUT ,
6835e49fc963SAndy Fiddamanand
6836e49fc963SAndy Fiddaman.Ev _
6837e49fc963SAndy Fiddamanremoves their special meaning even if they are subsequently assigned to.
6838e49fc963SAndy Fiddaman.Pp
6839e49fc963SAndy Fiddaman.It Ic wait Op Ar job
6840e49fc963SAndy FiddamanWait for the specified job and report its termination status.
6841e49fc963SAndy FiddamanIf
6842e49fc963SAndy Fiddaman.Ar job
6843e49fc963SAndy Fiddamanis not specified, then all currently active child processes are waited for.
6844e49fc963SAndy FiddamanThe exit status from this command is that of the last process waited for if
6845e49fc963SAndy Fiddaman.Ar job
6846e49fc963SAndy Fiddamanis specified; otherwise it is zero.
6847e49fc963SAndy FiddamanSee
6848e49fc963SAndy Fiddaman.Sx Jobs
6849e49fc963SAndy Fiddamanfor a description of the format of
6850e49fc963SAndy Fiddaman.Ar job .
6851e49fc963SAndy Fiddaman.Pp
6852e49fc963SAndy Fiddaman.It Ic whence Oo Fl afpv Oc Ar name No ...
6853e49fc963SAndy FiddamanFor each
6854e49fc963SAndy Fiddaman.Ar name ,
6855e49fc963SAndy Fiddamanindicate how it would be interpreted if used as a command name.
6856e49fc963SAndy FiddamanThe
6857e49fc963SAndy Fiddaman.Fl v
6858e49fc963SAndy Fiddamanoption produces a more verbose report.
6859e49fc963SAndy FiddamanThe
6860e49fc963SAndy Fiddaman.Fl f
6861e49fc963SAndy Fiddamanoption skips the search for functions.
6862e49fc963SAndy FiddamanThe
6863e49fc963SAndy Fiddaman.Fl p
6864e49fc963SAndy Fiddamanoption does a path search for
6865e49fc963SAndy Fiddaman.Ar name
6866e49fc963SAndy Fiddamaneven if name is an alias, a function, or a reserved word.
6867e49fc963SAndy FiddamanThe
6868e49fc963SAndy Fiddaman.Fl a
6869e49fc963SAndy Fiddamanoption is similar to the
6870e49fc963SAndy Fiddaman.Fl v
6871e49fc963SAndy Fiddamanoption but causes all interpretations of the specified name to be reported.
6872e49fc963SAndy Fiddaman.El
6873e49fc963SAndy Fiddaman.Ss "Invocation"
6874e49fc963SAndy FiddamanIf the shell is invoked by
6875e49fc963SAndy Fiddaman.Xr exec 2 ,
6876e49fc963SAndy Fiddamanand the first character of argument zero
6877e49fc963SAndy Fiddaman.Pq Sy $0
6878e49fc963SAndy Fiddamanis
6879e49fc963SAndy Fiddaman.Sy - ,
6880e49fc963SAndy Fiddamanthen the shell is assumed to be a login shell and commands are read from
6881e49fc963SAndy Fiddaman.Pa /etc/profile
6882e49fc963SAndy Fiddamanand then from either
6883e49fc963SAndy Fiddaman.Pa .profile
6884e49fc963SAndy Fiddamanin the current directory or
6885e49fc963SAndy Fiddaman.Pa $HOME/.profile ,
6886e49fc963SAndy Fiddamanif either file exists.
6887e49fc963SAndy FiddamanNext, for interactive shells, commands are read first from
6888e49fc963SAndy Fiddaman.Pa /etc/ksh.kshrc ,
6889e49fc963SAndy Fiddamanand then from the file named by performing parameter expansion, command
6890c10c16deSRichard Lowesubstitution, and arithmetic substitution on the value of the environment
6891e49fc963SAndy Fiddamanvariable
6892e49fc963SAndy Fiddaman.Ev ENV ,
6893e49fc963SAndy Fiddamanif the file exists.
6894e49fc963SAndy FiddamanIf the
6895e49fc963SAndy Fiddaman.Fl s
6896e49fc963SAndy Fiddamanoption is not present and
6897e49fc963SAndy Fiddaman.Ar arg
6898e49fc963SAndy Fiddamanis specified and a file by the name of
6899e49fc963SAndy Fiddaman.Ar arg
6900e49fc963SAndy Fiddamanexists, then it reads and executes this script.
6901e49fc963SAndy FiddamanOtherwise, if the first
6902e49fc963SAndy Fiddaman.Ar arg
6903e49fc963SAndy Fiddamandoes not contain a
6904e49fc963SAndy Fiddaman.Sy / ,
6905e49fc963SAndy Fiddamana path search is performed on the first
6906e49fc963SAndy Fiddaman.Ar arg
6907e49fc963SAndy Fiddamanto determine the name of the script to execute.
6908e49fc963SAndy FiddamanThe script
6909e49fc963SAndy Fiddaman.Ar arg
6910e49fc963SAndy Fiddamanmust have execute permission and any
6911e49fc963SAndy Fiddaman.Sy setuid
6912e49fc963SAndy Fiddamanand
6913e49fc963SAndy Fiddaman.Sy setgid
6914e49fc963SAndy Fiddamansettings are ignored.
6915e49fc963SAndy FiddamanIf the script is not found on the path,
6916e49fc963SAndy Fiddaman.Ar arg
6917e49fc963SAndy Fiddamanis processed as if it named a built-in command or function.
6918e49fc963SAndy Fiddaman.Pp
6919c10c16deSRichard LoweCommands are then read as described, and the following options are interpreted
6920c10c16deSRichard Loweby the shell when it is invoked:
6921e49fc963SAndy Fiddaman.Bl -tag -width Ds
6922e49fc963SAndy Fiddaman.It Fl c
6923e49fc963SAndy FiddamanIf the
6924e49fc963SAndy Fiddaman.Fl c
6925e49fc963SAndy Fiddamanoption is present, then commands are read from the first
6926e49fc963SAndy Fiddaman.Ar arg .
6927e49fc963SAndy FiddamanAny remaining arguments become positional parameters starting at
6928e49fc963SAndy Fiddaman.Sy 0 .
6929e49fc963SAndy Fiddaman.It Fl D
6930e49fc963SAndy FiddamanA list of all double quoted strings that are preceded by a
6931e49fc963SAndy Fiddaman.Sy $
6932e49fc963SAndy Fiddamanis printed on standard output and the shell exits.
6933e49fc963SAndy FiddamanThis set of strings is subject to language translation when the locale is not C
6934e49fc963SAndy Fiddamanor POSIX.
6935e49fc963SAndy FiddamanNo commands are executed.
6936e49fc963SAndy Fiddaman.It Fl E
6937e49fc963SAndy FiddamanReads the file named by the
6938e49fc963SAndy Fiddaman.Ev ENV
6939e49fc963SAndy Fiddamanvariable or by
6940e49fc963SAndy Fiddaman.Pa $HOME/.kshrc
6941e49fc963SAndy Fiddamanif not defined after the profiles.
6942e49fc963SAndy Fiddaman.It Fl i
6943e49fc963SAndy FiddamanIf the
6944e49fc963SAndy Fiddaman.Fl i
6945e49fc963SAndy Fiddamanoption is present or if the shell input and output are attached to a terminal
6946e49fc963SAndy Fiddaman.Pq as told by Xr tcgetattr 3C ) ,
6947e49fc963SAndy Fiddamanthis shell is interactive.
6948e49fc963SAndy FiddamanIn this case
6949e49fc963SAndy Fiddaman.Sy TERM
6950e49fc963SAndy Fiddamanis ignored
6951e49fc963SAndy Fiddaman.Po so that
6952e49fc963SAndy Fiddaman.Ic kill Ar 0
6953e49fc963SAndy Fiddamandoes not kill an
6954e49fc963SAndy Fiddamaninteractive shell
6955e49fc963SAndy Fiddaman.Pc
6956e49fc963SAndy Fiddamanand
6957e49fc963SAndy Fiddaman.Sy INTR
6958e49fc963SAndy Fiddamanis caught and ignored
6959e49fc963SAndy Fiddaman.Pq so that wait is interruptible .
6960e49fc963SAndy FiddamanIn all cases,
6961e49fc963SAndy Fiddaman.Sy QUIT
6962e49fc963SAndy Fiddamanis ignored by the shell.
6963e49fc963SAndy Fiddaman.It Fl R Ar filename
6964e49fc963SAndy FiddamanThe
6965e49fc963SAndy Fiddaman.Fl R Ar filename
6966e49fc963SAndy Fiddamanoption is used to generate a cross reference database that can be used by a
6967e49fc963SAndy Fiddamanseparate utility to find definitions and references for variables and commands.
6968e49fc963SAndy Fiddaman.It Fl r
6969e49fc963SAndy FiddamanIf the
6970e49fc963SAndy Fiddaman.Fl r
6971e49fc963SAndy Fiddamanoption is present, the shell is a restricted shell.
6972e49fc963SAndy Fiddaman.It Fl s
6973e49fc963SAndy FiddamanIf the
6974e49fc963SAndy Fiddaman.Fl s
6975e49fc963SAndy Fiddamanoption is present or if no arguments remain, then commands are read from the
6976e49fc963SAndy Fiddamanstandard input.
6977e49fc963SAndy FiddamanShell output, except for the output of the
6978e49fc963SAndy Fiddaman.Sx Special Commands
6979e49fc963SAndy Fiddamanlisted, is written to file descriptor 2.
6980e49fc963SAndy Fiddaman.El
6981e49fc963SAndy Fiddaman.Pp
6982e49fc963SAndy FiddamanThe remaining options and arguments are described under the
6983e49fc963SAndy Fiddaman.Ic set
6984e49fc963SAndy Fiddamancommand.
6985e49fc963SAndy FiddamanAn optional
6986e49fc963SAndy Fiddaman.Fl
6987e49fc963SAndy Fiddamanas the first argument is ignored.
6988e49fc963SAndy Fiddaman.Ss rksh93 Only
6989e49fc963SAndy Fiddaman.Sy rksh93
6990e49fc963SAndy Fiddamanis used to set up login names and execution environments whose capabilities are
6991e49fc963SAndy Fiddamanmore controlled than those of the standard shell.
6992e49fc963SAndy Fiddaman.Pp
6993e49fc963SAndy FiddamanThe actions of
6994e49fc963SAndy Fiddaman.Nm rksh93
6995e49fc963SAndy Fiddamanare identical to those of
6996e49fc963SAndy Fiddaman.Nm ksh93 ,
6997e49fc963SAndy Fiddamanexcept that the following are disallowed:
6998e49fc963SAndy Fiddaman.Bl -bullet -width Ds
6999e49fc963SAndy Fiddaman.It
7000c10c16deSRichard LoweUnsetting the restricted option
7001e49fc963SAndy Fiddaman.It
7002e49fc963SAndy FiddamanChanging directory.
7003e49fc963SAndy FiddamanSee
7004e49fc963SAndy Fiddaman.Xr cd 1 .
7005e49fc963SAndy Fiddaman.It
7006e49fc963SAndy FiddamanSetting or unsetting the value or attributes of
7007e49fc963SAndy Fiddaman.Ev SHELL ,
7008e49fc963SAndy Fiddaman.Ev ENV ,
7009e49fc963SAndy Fiddaman.Ev FPATH ,
7010e49fc963SAndy Fiddamanor
7011e49fc963SAndy Fiddaman.Ev PATH
7012e49fc963SAndy Fiddaman.It
7013e49fc963SAndy FiddamanSpecifying path or command names containing
7014e49fc963SAndy Fiddaman.Sy /
7015e49fc963SAndy Fiddaman.It
7016e49fc963SAndy FiddamanRedirecting output
7017e49fc963SAndy Fiddaman.Po
7018e49fc963SAndy Fiddaman.Sy \&> ,
7019e49fc963SAndy Fiddaman.Sy \&> ,
7020e49fc963SAndy Fiddaman.Sy \&| ,
7021e49fc963SAndy Fiddaman.Sy \&>\&; ,
7022e49fc963SAndy Fiddaman.Sy \&<> ,
7023e49fc963SAndy Fiddamanand
7024e49fc963SAndy Fiddaman.Sy \&>>
7025e49fc963SAndy Fiddaman.Pc .
7026e49fc963SAndy Fiddaman.It
7027c10c16deSRichard LoweAdding or deleting built-in commands.
7028e49fc963SAndy Fiddaman.It
7029e49fc963SAndy FiddamanUsing
7030e49fc963SAndy Fiddaman.Ic command Fl p
7031e49fc963SAndy Fiddamanto invoke a command.
7032e49fc963SAndy Fiddaman.El
7033e49fc963SAndy Fiddaman.Pp
7034e49fc963SAndy FiddamanThese restrictions are enforced after
7035e49fc963SAndy Fiddaman.Pa .profile
7036e49fc963SAndy Fiddamanand the
7037e49fc963SAndy Fiddaman.Ev ENV
7038e49fc963SAndy Fiddamanfiles are interpreted.
7039e49fc963SAndy Fiddaman.Pp
7040e49fc963SAndy FiddamanWhen a command to be executed is found to be a shell procedure,
7041e49fc963SAndy Fiddaman.Nm rksh93
7042e49fc963SAndy Fiddamaninvokes
7043e49fc963SAndy Fiddaman.Nm ksh93
7044e49fc963SAndy Fiddamanto execute it.
7045e49fc963SAndy FiddamanThus, it is possible to provide to the end-user shell procedures that have
7046e49fc963SAndy Fiddamanaccess to the full power of the standard shell, while imposing a limited menu
7047e49fc963SAndy Fiddamanof commands.
7048e49fc963SAndy FiddamanThis scheme assumes that the end-user does not have write and execute
7049e49fc963SAndy Fiddamanpermissions in the same directory.
7050e49fc963SAndy FiddamanThe net effect of these rules is that the writer of the
7051e49fc963SAndy Fiddaman.Pa .profile
7052e49fc963SAndy Fiddamanhas complete control over user actions, by performing guaranteed setup actions
7053e49fc963SAndy Fiddamanand leaving the user in an appropriate directory (probably not the login
7054e49fc963SAndy Fiddamandirectory).
7055e49fc963SAndy FiddamanThe system administrator often sets up a directory of commands, for example,
7056e49fc963SAndy Fiddaman.Pa /usr/rbin ,
7057e49fc963SAndy Fiddamanthat can be safely invoked by
7058e49fc963SAndy Fiddaman.Nm rksh93 .
7059e49fc963SAndy Fiddaman.Sh USAGE
7060e49fc963SAndy FiddamanSee
7061*bbf21555SRichard Lowe.Xr largefile 7
7062e49fc963SAndy Fiddamanfor the description of the behavior of
7063e49fc963SAndy Fiddaman.Nm ksh93
7064e49fc963SAndy Fiddamanand
7065e49fc963SAndy Fiddaman.Nm rksh93
7066e49fc963SAndy Fiddamanwhen encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
7067e49fc963SAndy Fiddaman.Sh FILES
7068e49fc963SAndy Fiddaman.Bl -tag -width Ds
7069e49fc963SAndy Fiddaman.It Pa /etc/profile
7070c10c16deSRichard LoweThe system initialization file, executed for login shells.
7071e49fc963SAndy Fiddaman.It Pa /etc/ksh.kshrc
7072c10c16deSRichard LoweThe system wide startup file, executed for interactive shells.
7073e49fc963SAndy Fiddaman.It Pa $HOME/.profile
7074c10c16deSRichard LoweThe personal initialization file, executed for login shells after
7075e49fc963SAndy Fiddaman.Pa /etc/profile .
7076e49fc963SAndy Fiddaman.It Pa $HOME/.kshrc
7077e49fc963SAndy FiddamanDefault personal initialization file, executed after
7078e49fc963SAndy Fiddaman.Pa /etc/ksh.kshrc ,
7079e49fc963SAndy Fiddamanfor interactive shells when
7080e49fc963SAndy Fiddaman.Ev ENV
7081e49fc963SAndy Fiddamanis not set.
7082e49fc963SAndy Fiddaman.It Pa /etc/suid-profile
7083c10c16deSRichard LoweAlternative initialization file, executed instead of the personal
7084c10c16deSRichard Loweinitialization file when the real and effective user or group id do not match.
7085e49fc963SAndy Fiddaman.It Pa /dev/null
7086c10c16deSRichard LoweNULL device.
7087e49fc963SAndy Fiddaman.El
7088e49fc963SAndy Fiddaman.Sh EXIT STATUS
7089e49fc963SAndy FiddamanThe following exit values are returned:
7090e49fc963SAndy Fiddaman.Bl -tag -width Ds
7091e49fc963SAndy Fiddaman.It Sy non-zero
7092e49fc963SAndy FiddamanReturns
7093e49fc963SAndy Fiddaman.Sy non-zero
7094e49fc963SAndy Fiddamanwhen errors, such as syntax errors, are detected by the shell.
7095e49fc963SAndy Fiddaman.Pp
7096e49fc963SAndy FiddamanIf the shell is being used non-interactively, then execution of the shell file
7097e49fc963SAndy Fiddamanis abandoned unless the error occurs inside a sub-shell in which case the
7098e49fc963SAndy Fiddamansub-shell is abandoned.
7099e49fc963SAndy Fiddaman.It Em exit-status-of-last-command-executed
7100e49fc963SAndy FiddamanReturns the exit status of the last command executed.
7101e49fc963SAndy Fiddaman.Pp
7102e49fc963SAndy FiddamanRun time errors detected by the shell are reported by printing the command or
7103e49fc963SAndy Fiddamanfunction name and the error condition.
7104e49fc963SAndy FiddamanIf the line number that the error occurred on is greater than one, then the
7105e49fc963SAndy Fiddamanline number is also printed in square brackets
7106e49fc963SAndy Fiddaman.Pq Sy []
7107e49fc963SAndy Fiddamanafter the command or function name.
7108e49fc963SAndy Fiddaman.Pp
7109e49fc963SAndy FiddamanSee the
7110e49fc963SAndy Fiddaman.Nm ksh93 Ic exit
7111e49fc963SAndy Fiddamancommand for additional details.
7112e49fc963SAndy Fiddaman.El
7113e49fc963SAndy Fiddaman.Sh INTERFACE STABILITY
7114e49fc963SAndy FiddamanThe scripting interface is
7115e49fc963SAndy Fiddaman.Sy Uncommitted .
7116e49fc963SAndy FiddamanThe environment variables,
7117e49fc963SAndy Fiddaman.Pa \&.paths
7118e49fc963SAndy Fiddamanfeature, and editing modes are
7119e49fc963SAndy Fiddaman.Sy Volatile .
7120e49fc963SAndy Fiddaman.Sh SEE ALSO
7121e49fc963SAndy Fiddaman.Xr cat 1 ,
7122e49fc963SAndy Fiddaman.Xr cd 1 ,
7123e49fc963SAndy Fiddaman.Xr chmod 1 ,
7124e49fc963SAndy Fiddaman.Xr cut 1 ,
7125e49fc963SAndy Fiddaman.Xr date 1 ,
7126e49fc963SAndy Fiddaman.Xr echo 1 ,
7127e49fc963SAndy Fiddaman.Xr egrep 1 ,
7128e49fc963SAndy Fiddaman.Xr env 1 ,
7129e49fc963SAndy Fiddaman.Xr fgrep 1 ,
7130e49fc963SAndy Fiddaman.Xr grep 1 ,
7131e49fc963SAndy Fiddaman.Xr login 1 ,
7132e49fc963SAndy Fiddaman.Xr newgrp 1 ,
7133e49fc963SAndy Fiddaman.Xr paste 1 ,
7134e49fc963SAndy Fiddaman.Xr perl 1 ,
7135e49fc963SAndy Fiddaman.Xr printf 1 ,
7136e49fc963SAndy Fiddaman.Xr stty 1 ,
7137e49fc963SAndy Fiddaman.Xr test 1 ,
7138e49fc963SAndy Fiddaman.Xr umask 1 ,
7139e49fc963SAndy Fiddaman.Xr vi 1 ,
7140e49fc963SAndy Fiddaman.Xr dup 2 ,
7141e49fc963SAndy Fiddaman.Xr exec 2 ,
7142e49fc963SAndy Fiddaman.Xr fork 2 ,
7143e49fc963SAndy Fiddaman.Xr ioctl 2 ,
7144e49fc963SAndy Fiddaman.Xr lseek 2 ,
7145e49fc963SAndy Fiddaman.Xr pathconf 2 ,
7146e49fc963SAndy Fiddaman.Xr pipe 2 ,
7147e49fc963SAndy Fiddaman.Xr ulimit 2 ,
7148e49fc963SAndy Fiddaman.Xr umask 2 ,
7149e49fc963SAndy Fiddaman.Xr rand 3C ,
7150e49fc963SAndy Fiddaman.Xr sysconf 3C ,
7151e49fc963SAndy Fiddaman.Xr tcgetattr 3C ,
7152e49fc963SAndy Fiddaman.Xr wait 3C ,
7153*bbf21555SRichard Lowe.Xr a.out 5 ,
7154*bbf21555SRichard Lowe.Xr profile 5 ,
7155*bbf21555SRichard Lowe.Xr attributes 7 ,
7156*bbf21555SRichard Lowe.Xr environ 7 ,
7157*bbf21555SRichard Lowe.Xr largefile 7 ,
7158*bbf21555SRichard Lowe.Xr standards 7
7159e49fc963SAndy Fiddaman.Pp
7160e49fc963SAndy Fiddaman.Rs
7161e49fc963SAndy Fiddaman.%A Bolsky, Morris I.
7162e49fc963SAndy Fiddaman.%A Korn, David G.
7163e49fc963SAndy Fiddaman.%B The New KornShell Command and Programming Language
7164e49fc963SAndy Fiddaman.%I Prentice Hall
7165e49fc963SAndy Fiddaman.%D 1995 .
7166e49fc963SAndy Fiddaman.Re
7167e49fc963SAndy Fiddaman.Rs
7168e49fc963SAndy Fiddaman.%B POSIX-Part 2: Shell and Utilities, IEEE Std 1003.2-1992, ISO/IEC 9945-2
7169e49fc963SAndy Fiddaman.%I IEEE
7170e49fc963SAndy Fiddaman.%D 1993 .
7171e49fc963SAndy Fiddaman.Re
7172e49fc963SAndy Fiddaman.Sh NOTES
7173e49fc963SAndy Fiddaman.Nm ksh93
7174e49fc963SAndy Fiddamanscripts should choose shell function names outside the namespace used by
7175e49fc963SAndy Fiddamanreserved keywords of the ISO C99, C++ and JAVA languages to avoid collisions
7176e49fc963SAndy Fiddamanwith future enhancements to
7177e49fc963SAndy Fiddaman.Nm ksh93 .
7178e49fc963SAndy Fiddaman.Pp
7179c10c16deSRichard LoweIf a command is executed, and then a command with the same name is installed in
7180c10c16deSRichard Lowea directory in the search path before the directory where the original command
7181e49fc963SAndy Fiddamanwas found, the shell continues to
7182e49fc963SAndy Fiddaman.Ic exec
7183e49fc963SAndy Fiddamanthe original command.
7184e49fc963SAndy FiddamanUse the
7185e49fc963SAndy Fiddaman.Fl t
7186e49fc963SAndy Fiddamanoption of the alias command to correct this situation.
7187e49fc963SAndy Fiddaman.Pp
7188e49fc963SAndy FiddamanSome very old shell scripts contain a caret
7189e49fc963SAndy Fiddaman.Pq Sy ^
7190e49fc963SAndy Fiddamanas a synonym for the pipe character
7191e49fc963SAndy Fiddaman.Pq Sy \&| .
7192e49fc963SAndy Fiddaman.Pp
7193e49fc963SAndy FiddamanUsing the
7194e49fc963SAndy Fiddaman.Ic hist
7195e49fc963SAndy Fiddamanbuilt-in command within a compound command causes the whole command to
7196e49fc963SAndy Fiddamandisappear from the history file.
7197e49fc963SAndy Fiddaman.Pp
7198e49fc963SAndy FiddamanThe built-in command
7199e49fc963SAndy Fiddaman.Ic \&. Ar file
7200e49fc963SAndy Fiddamanreads the whole file before any commands are executed.
7201e49fc963SAndy Fiddaman.Ic alias
7202e49fc963SAndy Fiddamanand
7203e49fc963SAndy Fiddaman.Ic unalias
7204e49fc963SAndy Fiddamancommands in the file do not apply to any commands defined in the file.
7205e49fc963SAndy Fiddaman.Pp
7206e49fc963SAndy FiddamanTraps are not processed while a job is waiting for a foreground process.
7207e49fc963SAndy FiddamanThus, a trap on
7208e49fc963SAndy Fiddaman.Sy CHLD
7209e49fc963SAndy Fiddamanis not executed until the foreground job terminates.
7210e49fc963SAndy Fiddaman.Pp
7211c10c16deSRichard LoweIt is a good idea to leave a space after the comma operator in arithmetic
7212c10c16deSRichard Loweexpressions to prevent the comma from being interpreted as the decimal point
7213c10c16deSRichard Lowecharacter in certain locales.
7214e49fc963SAndy Fiddaman.Pp
7215e49fc963SAndy FiddamanThere might be some restrictions on creating a
7216e49fc963SAndy Fiddaman.Pa \&.paths
7217e49fc963SAndy Fiddamanfile which is portable across other operating systems.
7218e49fc963SAndy Fiddaman.Pp
7219e49fc963SAndy FiddamanIf the system supports the 64-bit instruction set,
7220e49fc963SAndy Fiddaman.Pa /bin/ksh93
7221e49fc963SAndy Fiddamanexecutes the 64-bit version of
7222e49fc963SAndy Fiddaman.Nm ksh93 .
7223