summaryrefslogtreecommitdiffstats
path: root/man-pages-posix-2013/man1p/set.1p
blob: 8db4db1e5403a7a83621410c1a3f882c6379e66e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
'\" et
.TH SET "1P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.

.SH NAME
set
\(em set or unset options and positional parameters
.SH SYNOPSIS
.LP
.nf
set \fB[\fR\(miabCefhmnuvx\fB] [\fR\(mio \fIoption\fB] [\fIargument\fR...\fB]\fR
.P
set \fB[\fR+abCefhmnuvx\fB] [\fR+o \fIoption\fB] [\fIargument\fR...\fB]\fR
.P
set \(mi\|\(mi\fB [\fIargument\fR...\fB]\fR
.P
set \(mio
.P
set +o
.fi
.SH DESCRIPTION
If no
.IR option s
or
.IR argument s
are specified,
.IR set
shall write the names and values of all shell variables in the collation
sequence of the current locale. Each
.IR name
shall start on a separate line, using the format:
.sp
.RS 4
.nf
\fB
"%s=%s\en", <\fIname\fR>, <\fIvalue\fR>
.fi \fR
.P
.RE
.P
The
.IR value
string shall be written with appropriate quoting; see the description
of shell quoting in
.IR "Section 2.2" ", " "Quoting".
The output shall be suitable for reinput to the shell, setting or
resetting, as far as possible, the variables that are currently set;
read-only variables cannot be reset.
.P
When options are specified, they shall set or unset attributes of the
shell, as described below. When
.IR argument s
are specified, they cause positional parameters to be set or unset, as
described below. Setting or unsetting attributes and positional
parameters are not necessarily related actions, but they can be
combined in a single invocation of
.IR set .
.P
The
.IR set
special built-in shall support the Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 12.2" ", " "Utility Syntax Guidelines"
except that options can be specified with either a leading
<hyphen>
(meaning enable the option) or
<plus-sign>
(meaning disable it) unless otherwise specified.
.P
Implementations shall support the options in the following list in both
their
<hyphen>
and
<plus-sign>
forms. These options can also be specified as options to
.IR sh .
.IP "\fB\(mia\fP" 6
When this option is on, the
.IR export
attribute shall be set for each variable to which an assignment is
performed; see the Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 4.22" ", " "Variable Assignment".
If the assignment precedes a utility name in a command, the
.IR export
attribute shall not persist in the current execution environment after
the utility completes, with the exception that preceding one of the
special built-in utilities causes the
.IR export
attribute to persist after the built-in has completed. If the
assignment does not precede a utility name in the command, or if the
assignment is a result of the operation of the
.IR getopts
or
.IR read
utilities, the
.IR export
attribute shall persist until the variable is unset.
.IP "\fB\(mib\fP" 6
This option shall be supported if the implementation supports the User
Portability Utilities option. It shall cause the shell to notify the
user asynchronously of background job completions. The following
message is written to standard error:
.RS 6 
.sp
.RS 4
.nf
\fB
"[%d]%c %s%s\en", <\fIjob-number\fR>, <\fIcurrent\fR>, <\fRstatus\fR>, <\fRjob-name\fR>
.fi \fR
.P
.RE
.P
where the fields shall be as follows:
.IP "<\fIcurrent\fR>" 12
The character
.BR '+' 
identifies the job that would be used as a default for the
.IR fg
or
.IR bg
utilities; this job can also be specified using the
.IR job_id
.BR \(dq%+\(dq 
or
.BR \(dq%%\(dq .
The character
.BR '\(mi' 
identifies the job that would become the
default if the current default job were to exit; this job can also be
specified using the
.IR job_id
.BR \(dq%\(mi\(dq .
For other jobs, this field is a
<space>.
At most one job can be identified with
.BR '+' 
and at most one job can be identified with
.BR '\(mi' .
If there is any suspended job, then the current job shall be a
suspended job. If there are at least two suspended jobs, then the
previous job also shall be a suspended job.
.IP "<\fIjob-number\fR>" 12
A number that can be used to identify the process group to the
.IR wait ,
.IR fg ,
.IR bg ,
and
.IR kill
utilities. Using these utilities, the job can be identified by
prefixing the job number with
.BR '%' .
.IP "<\fIstatus\fR>" 12
Unspecified.
.IP "<\fIjob-name\fR>" 12
Unspecified.
.P
When the shell notifies the user a job has been completed, it may
remove the job's process ID from the list of those known in the current
shell execution environment; see
.IR "Section 2.9.3.1" ", " "Examples".
Asynchronous notification shall not be enabled by default.
.RE
.IP "\fB\(miC\fP" 6
(Uppercase C.) Prevent existing files from being overwritten by the
shell's
.BR '>' 
redirection operator (see
.IR "Section 2.7.2" ", " "Redirecting Output");
the
.BR \(dq>|\(dq 
redirection operator shall override this
.IR noclobber
option for an individual file.
.IP "\fB\(mie\fP" 6
When this option is on, when any command fails (for any of the reasons
listed in
.IR "Section 2.8.1" ", " "Consequences of Shell Errors"
or by returning an exit status greater than zero), the shell immediately
shall exit with the following exceptions:
.RS 6 
.IP " 1." 4
The failure of any individual command in a multi-command pipeline shall
not cause the shell to exit. Only the failure of the pipeline itself
shall be considered.
.IP " 2." 4
The
.BR \(mie
setting shall be ignored when executing the compound list following the
.BR while ,
.BR until ,
.BR if ,
or
.BR elif
reserved word, a pipeline beginning with the
.BR !
reserved word, or any command of an AND-OR list other than the last.
.IP " 3." 4
If the exit status of a compound command other than a subshell command
was the result of a failure while
.BR \(mie
was being ignored, then
.BR \(mie
shall not apply to this command.
.P
This requirement applies to the shell environment and each subshell
environment separately. For example, in:
.sp
.RS 4
.nf
\fB
set -e; (false; echo one) | cat; echo two
.fi \fR
.P
.RE
.P
the
.IR false
command causes the subshell to exit without executing
.IR "echo one" ;
however,
.IR "echo two"
is executed because the exit status of the pipeline
.IR "(false; echo one) | cat"
is zero.
.RE
.IP "\fB\(mif\fP" 6
The shell shall disable pathname expansion.
.IP "\fB\(mih\fP" 6
Locate and remember utilities invoked by functions as those functions
are defined (the utilities are normally located when the function is
executed).
.IP "\fB\(mim\fP" 6
This option shall be supported if the implementation supports the User
Portability Utilities option. All jobs shall be run in their own
process groups. Immediately before the shell issues a prompt after
completion of the background job, a message reporting the exit status
of the background job shall be written to standard error. If a
foreground job stops, the shell shall write a message to standard error
to that effect, formatted as described by the
.IR jobs
utility. In addition, if a job changes status other than exiting (for
example, if it stops for input or output or is stopped by a SIGSTOP
signal), the shell shall write a similar message immediately prior to
writing the next prompt. This option is enabled by default for
interactive shells.
.IP "\fB\(min\fP" 6
The shell shall read commands but does not execute them; this can be
used to check for shell script syntax errors. An interactive shell may
ignore this option.
.IP "\fB\(mio\fP" 6
Write the current settings of the options to standard output in an
unspecified format.
.IP "\fB+o\fP" 6
Write the current option settings to standard output in a format that
is suitable for reinput to the shell as commands that achieve the same
options settings.
.IP "\fB\(mio\ \fIoption\fR" 6
.br
This option is supported if the system supports the User Portability
Utilities option. It shall set various options, many of which shall be
equivalent to the single option letters. The following values of
.IR option
shall be supported:
.RS 6 
.IP "\fIallexport\fR" 10
Equivalent to
.BR \(mia .
.IP "\fIerrexit\fR" 10
Equivalent to
.BR \(mie .
.IP "\fIignoreeof\fR" 10
Prevent an interactive shell from exiting on end-of-file. This setting
prevents accidental logouts when
<control>\(hyD
is entered. A user shall explicitly
.IR exit
to leave the interactive shell.
.IP "\fImonitor\fR" 10
Equivalent to
.BR \(mim .
This option is supported if the system supports the User Portability
Utilities option.
.IP "\fInoclobber\fR" 10
Equivalent to
.BR \(miC
(uppercase C).
.IP "\fInoglob\fR" 10
Equivalent to
.BR \(mif .
.IP "\fInoexec\fR" 10
Equivalent to
.BR \(min .
.IP "\fInolog\fR" 10
Prevent the entry of function definitions into the command history; see
.IR "Command History List".
.IP "\fInotify\fR" 10
Equivalent to
.BR \(mib .
.IP "\fInounset\fR" 10
Equivalent to
.BR \(miu .
.IP "\fIverbose\fR" 10
Equivalent to
.BR \(miv .
.IP "\fIvi\fR" 10
Allow shell command line editing using the built-in
.IR vi
editor. Enabling
.IR vi
mode shall disable any other command line editing mode provided as an
implementation extension.
.RS 10 
.P
It need not be possible to set
.IR vi
mode on for certain block-mode terminals.
.RE
.IP "\fIxtrace\fR" 10
Equivalent to
.BR \(mix .
.RE
.IP "\fB\(miu\fP" 6
When the shell tries to expand an unset parameter other than the
.BR '@' 
and
.BR '*' 
special parameters, it shall write a message to standard error and shall
not execute the command containing the expansion, but for the purposes
of setting the
.BR '?' 
special parameter and the exit status of the shell the command shall be
treated as having been executed and returned an exit status of between
1 and 125 inclusive. A non-interactive shell shall immediately exit. An
interactive shell shall not exit.
.IP "\fB\(miv\fP" 6
The shell shall write its input to standard error as it is read.
.IP "\fB\(mix\fP" 6
The shell shall write to standard error a trace for each command after
it expands the command and before it executes it. It is unspecified
whether the command that turns tracing off is traced.
.P
The default for all these options shall be off (unset) unless stated
otherwise in the description of the option or unless the shell was
invoked with them on; see
.IR sh .
.P
The remaining arguments shall be assigned in order to the positional
parameters. The special parameter
.BR '#' 
shall be set to reflect the number of positional parameters. All
positional parameters shall be unset before any new values are
assigned.
.P
If the first argument is
.BR '\(mi' ,
the results are unspecified.
.P
The special argument
.BR \(dq\(mi\|\(mi\(dq 
immediately following the
.IR set
command name can be used to delimit the arguments if the first argument
begins with
.BR '+' 
or
.BR '\(mi' ,
or to prevent inadvertent listing of all shell variables when there are
no arguments. The command
.IR set
.BR \(mi\|\(mi
without
.IR argument
shall unset all positional parameters and set the special parameter
.BR '#' 
to zero.
.SH OPTIONS
See the DESCRIPTION.
.SH OPERANDS
See the DESCRIPTION.
.SH STDIN
Not used.
.SH "INPUT FILES"
None.
.SH "ENVIRONMENT VARIABLES"
None.
.SH "ASYNCHRONOUS EVENTS"
Default.
.SH STDOUT
See the DESCRIPTION.
.SH STDERR
The standard error shall be used only for diagnostic messages.
.SH "OUTPUT FILES"
None.
.SH "EXTENDED DESCRIPTION"
None.
.SH "EXIT STATUS"
Zero.
.SH "CONSEQUENCES OF ERRORS"
Default.
.LP
.IR "The following sections are informative."
.SH "APPLICATION USAGE"
Application writers should avoid relying on
.IR set
.BR \(mie
within functions. For example, in the following script:
.sp
.RS 4
.nf
\fB
set -e
start() {
    some_server
    echo some_server started successfully
}
start || echo >&2 some_server failed
.fi \fR
.P
.RE
.P
the
.BR \(mie
setting is ignored within the function body (because the function is a
command in an AND-OR list other than the last). Therefore, if
.IR some_server
fails, the function carries on to echo
.BR \(dqsome_server started successfully\(dq ,
and the exit status of the function is zero (which means
.BR \(dqsome_server failed\(dq 
is not output).
.SH EXAMPLES
Write out all variables and their values:
.sp
.RS 4
.nf
\fB
set
.fi \fR
.P
.RE
.P
Set $1, $2, and $3 and set
.BR \(dq$#\(dq 
to 3:
.sp
.RS 4
.nf
\fB
set c a b
.fi \fR
.P
.RE
.P
Turn on the
.BR \(mix
and
.BR \(miv
options:
.sp
.RS 4
.nf
\fB
set \(mixv
.fi \fR
.P
.RE
.P
Unset all positional parameters:
.sp
.RS 4
.nf
\fB
set \(mi\|\(mi
.fi \fR
.P
.RE
.P
Set $1 to the value of
.IR x ,
even if it begins with
.BR '\(mi' 
or
.BR '+' :
.sp
.RS 4
.nf
\fB
set \(mi\|\(mi "$x"
.fi \fR
.P
.RE
.P
Set the positional parameters to the expansion of
.IR x ,
even if
.IR x
expands with a leading
.BR '\(mi' 
or
.BR '+' :
.sp
.RS 4
.nf
\fB
set \(mi\|\(mi $x
.fi \fR
.P
.RE
.SH "RATIONALE"
The
.IR set
\(mi\|\(mi form is listed specifically in the SYNOPSIS even though this
usage is implied by the Utility Syntax Guidelines. The explanation of
this feature removes any ambiguity about whether the
.IR set
\(mi\|\(mi form might be misinterpreted as being equivalent to
.IR set
without any options or arguments. The functionality of this form has
been adopted from the KornShell. In System V,
.IR set
\(mi\|\(mi only unsets parameters if there is at least one argument;
the only way to unset all parameters is to use
.IR shift .
Using the KornShell version should not affect System V scripts because
there should be no reason to issue it without arguments deliberately;
if it were issued as, for example:
.sp
.RS 4
.nf
\fB
set \(mi\|\(mi "$@"
.fi \fR
.P
.RE
.P
and there were in fact no arguments resulting from
.BR \(dq$@\(dq ,
unsetting the parameters would have no result.
.P
The
.IR set
+ form in early proposals was omitted as being an unnecessary
duplication of
.IR set
alone and not widespread historical practice.
.P
The
.IR noclobber
option was changed to allow
.IR set
.BR \(miC
as well as the
.IR set
.BR \(mio
.IR noclobber
option. The single-letter version was added so that the historical
.BR \(dq$\(mi\(dq 
paradigm would not be broken; see
.IR "Section 2.5.2" ", " "Special Parameters".
.P
The description of the
.BR \(mie
option is intended to match the behavior of the 1988 version of the
KornShell.
.P
The
.BR \(mih
flag is related to command name hashing. See
.IR "\fIhash\fR\^".
.P
The following
.IR set
flags were omitted intentionally with the following rationale:
.IP "\fB\(mik\fP" 6
The
.BR \(mik
flag was originally added by the author of the Bourne shell to make it
easier for users of pre-release versions of the shell. In early
versions of the Bourne shell the construct
.IR set
.IR name =\c
.IR value
had to be used to assign values to shell variables. The problem with
.BR \(mik
is that the behavior affects parsing, virtually precluding writing any
compilers. To explain the behavior of
.BR \(mik ,
it is necessary to describe the parsing algorithm, which is
implementation-defined. For example:
.RS 6 
.sp
.RS 4
.nf
\fB
set \(mik; echo \fIname\fR=\fIvalue\fR
.fi \fR
.P
.RE
.P
and:
.sp
.RS 4
.nf
\fB
set \(mik
echo \fIname\fP=\fIvalue\fR
.fi \fR
.P
.RE
.P
behave differently. The interaction with functions is even more
complex. What is more, the
.BR \(mik
flag is never needed, since the command line could have been
reordered.
.RE
.IP "\fB\(mit\fP" 6
The
.BR \(mit
flag is hard to specify and almost never used. The only known use could
be done with here-documents. Moreover, the behavior with
.IR ksh
and
.IR sh
differs. The reference page says that it exits after reading and
executing one command. What is one command? If the input is
.IR date ;\c
.IR date ,
.IR sh
executes both
.IR date
commands while
.IR ksh
does only the first.
.P
Consideration was given to rewriting
.IR set
to simplify its confusing syntax. A specific suggestion was that the
.IR unset
utility should be used to unset options instead of using the non-\c
\fIgetopt\fR()\c
-able +\c
.IR option
syntax. However, the conclusion was reached that the historical
practice of using +\c
.IR option
was satisfactory and that there was no compelling reason to modify such
widespread historical practice.
.P
The
.BR \(mio
option was adopted from the KornShell to address user needs. In
addition to its generally friendly interface,
.BR \(mio
is needed to provide the
.IR vi
command line editing mode, for which historical practice yields no
single-letter option name. (Although it might have been possible to
invent such a letter, it was recognized that other editing modes would
be developed and
.BR \(mio
provides ample name space for describing such extensions.)
.P
Historical implementations are inconsistent in the format used for
.BR \(mio
option status reporting. The
.BR +o
format without an option-argument was added to allow portable access to
the options that can be saved and then later restored using, for
instance, a dot script.
.P
Historically,
.IR sh
did trace the command
.IR set
.BR +x ,
but
.IR ksh
did not.
.P
The
.IR ignoreeof
setting prevents accidental logouts when the end-of-file character
(typically
<control>\(hyD)
is entered. A user shall explicitly
.IR exit
to leave the interactive shell.
.P
The
.IR set
.BR \(mim
option was added to apply only to the UPE because it applies primarily
to interactive use, not shell script applications.
.P
The ability to do asynchronous notification became available in the
1988 version of the KornShell. To have it occur, the user had to issue
the command:
.sp
.RS 4
.nf
\fB
trap "jobs \(min" CLD
.fi \fR
.P
.RE
.P
The C shell provides two different levels of an asynchronous
notification capability. The environment variable
.IR notify
is analogous to what is done in
.IR set
.BR \(mib
or
.IR set
.BR \(mio
.IR notify .
When set, it notifies the user immediately of background job
completions. When unset, this capability is turned off.
.P
The other notification ability comes through the built-in utility
.IR notify .
The syntax is:
.sp
.RS 4
.nf
\fB
notify \fB[\fR%job ... \fB]\fR
.fi \fR
.P
.RE
.P
By issuing
.IR notify
with no operands, it causes the C shell to notify the user
asynchronously when the state of the current job changes. If given
operands,
.IR notify
asynchronously informs the user of changes in the states of the
specified jobs.
.P
To add asynchronous notification to the POSIX shell, neither the
KornShell extensions to
.IR trap ,
nor the C shell
.IR notify
environment variable seemed appropriate (\c
.IR notify
is not a proper POSIX environment variable name).
.P
The
.IR set
.BR \(mib
option was selected as a compromise.
.P
The
.IR notify
built-in was considered to have more functionality than was required
for simple asynchronous notification.
.P
Historically, some shells applied the
.BR \(miu
option to all parameters including
.IR $@
and
.IR $* .
The standard developers felt that this was a misfeature since it is
normal and common for
.IR $@
and
.IR $*
to be used in shell scripts regardless of whether they were passed any
arguments. Treating these uses as an error when no arguments are passed
reduces the value of
.BR \(miu
for its intended purpose of finding spelling mistakes in variable names
and uses of unset positional parameters.
.SH "FUTURE DIRECTIONS"
None.
.SH "SEE ALSO"
.IR "Section 2.14" ", " "Special Built-In Utilities",
.IR "\fIhash\fR\^"
.P
The Base Definitions volume of POSIX.1\(hy2008,
.IR "Section 4.22" ", " "Variable Assignment",
.IR "Section 12.2" ", " "Utility Syntax Guidelines"
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group.
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.unix.org/online.html .

Any typographical or formatting errors that appear
in this page are most likely
to have been introduced during the conversion of the source files to
man page format. To report such errors, see
https://www.kernel.org/doc/man-pages/reporting_bugs.html .