1set(1)                           User Commands                          set(1)
2
3
4

NAME

6       set,  unset,  setenv,  unsetenv,  export  - shell built-in functions to
7       determine the characteristics for environmental variables of  the  cur‐
8       rent shell and its descendents
9

SYNOPSIS

11   sh
12       set [--aefhkntuvx [argument]]...
13
14
15       unset [name]...
16
17
18       export [name]...
19
20
21   csh
22       set [var [= value]]
23
24
25       set var [n] = word
26
27
28       unset pattern
29
30
31       setenv [VAR [word]]
32
33
34       unsetenv variable
35
36
37   ksh
38       set [±abCefhkmnopstuvx] [±o option]... [±A name]
39            [arg]...
40
41
42       unset [-f] name...
43
44
45       **export [name [=value]]...
46
47
48       **export [-p]
49
50
51   ksh93
52       +set [±abCefGhkmnoprstuvx] [±o option]... [±A vname]
53            [arg]...
54
55
56       +unset [-fnv] vname...
57
58
59       ++export [-p] [name[=value]]...
60
61

DESCRIPTION

63   sh
64       The set built-in command has the following options:
65
66       --    Does  not  change any of the flags. This option is useful in set‐
67             ting $1 to .
68
69
70       -a    Marks variables which are modified or created for export.
71
72
73       -e    Exits immediately if a command exits with a non-zero exit status.
74
75
76       -f    Disables file name generation.
77
78
79       -h    Locates and remembers function commands as functions are defined.
80             Function  commands are normally located when the function is exe‐
81             cuted.
82
83
84       -k    All keyword arguments are placed in the environment  for  a  com‐
85             mand, not just those that precede the command name.
86
87
88       -n    Reads commands but does not execute them.
89
90
91       -t    Exits after reading and executing one command.
92
93
94       -u    Treats unset variables as an error when substituting.
95
96
97       -v    Prints shell input lines as they are read.
98
99
100       -x    Prints commands and their arguments as they are executed.
101
102
103
104       Using  + rather than causes these flags to be turned off. These flags
105       can also be used upon invocation of the shell. The current set of flags
106       can  be  found in $−. The remaining arguments are positional parameters
107       and are assigned, in order, to $1, $2, .... If no arguments are  speci‐
108       fied the values of all names are printed.
109
110
111       For  each  name,  unset  removes the corresponding variable or function
112       value. The variables PATH, PS1, PS2, MAILCHECK, and IF cannot be unset.
113
114
115       With the export built-in, the specified names are marked for  automatic
116       export  to  the  environment  of  subsequently executed commands. If no
117       arguments are specified, variable  names  that  have  been  marked  for
118       export  during the current shell's execution are listed. Function names
119       are not exported.
120
121   csh
122       With no arguments, set displays the values of all shell variables. Mul‐
123       tiword values are displayed as a parenthesized list. With the var argu‐
124       ment alone, set assigns an empty (null) value to the variable var. With
125       arguments of the form var = value set assigns value to var, where value
126       is one of:
127
128       word          A single word (or quoted string).
129
130
131       (wordlist)    A space-separated list of words enclosed in parentheses.
132
133
134
135       Values are command and filename expanded  before  being  assigned.  The
136       form  set  var[n]=word replaces the n'th word in a multiword value with
137       word.
138
139
140       unset removes variables whose names match (filename substitution)  pat‐
141       tern. All variables are removed by `unset *'.
142
143
144       With  no arguments, setenv displays all environment variables. With the
145       VAR argument, setenv sets the environment variable  VAR   to  an  empty
146       (null) value. (By convention, environment variables are normally speci‐
147       fied upper-case names.) With both VAR  and  word  arguments  specified,
148       setenv sets VAR to word, which must be either a single word or a quoted
149       string. The PATH variable can take multiple word  arguments,  separated
150       by colons (see EXAMPLES). The most commonly used environment variables,
151       USER, TERM, and PATH, are automatically imported to and  exported  from
152       the  csh  variables  user,  term,  and  path. Use setenv if you need to
153       change these variables. In addition, the shell sets the PWD environment
154       variable from the csh variable cwd whenever the latter changes.
155
156
157       The  environment  variables LC_CTYPE, LC_MESSAGES, LC_TIME, LC_COLLATE,
158       LC_NUMERIC, and LC_MONETARY take immediate effect when  changed  within
159       the C shell. See environ(5) for descriptions of these environment vari‐
160       ables.
161
162
163       unsetenv removes variable from the environment. As with unset,  pattern
164       matching is not performed.
165
166   ksh
167       The flags for the set built-in have meaning as follows:
168
169       -A           Array  assignment.  Unsets  the  variable name and assigns
170                    values sequentially from the list arg. If +A is used,  the
171                    variable name is not unset first.
172
173
174       -a           All  subsequent  variables  that are defined are automati‐
175                    cally exported.
176
177
178       -b           Causes the shell to  notify  the  user  asynchronously  of
179                    background job completions.
180
181
182       -C           Prevents  existing  files  from  being  overwritten by the
183                    shell's > redirection operator. The >| redirection  opera‐
184                    tor  overrides  this  noclobber  option  for an individual
185                    file.
186
187
188       -e           If a command has a non-zero exit status, executes the  ERR
189                    trap, if set, and exits. This mode is disabled while read‐
190                    ing profiles.
191
192
193       -f           Disables file name generation.
194
195
196       -h           Each command becomes a tracked alias  when  first  encoun‐
197                    tered.
198
199
200       -k           All  variable assignment arguments are placed in the envi‐
201                    ronment for a command, not just  those  that  precede  the
202                    command name.
203
204
205       -m           Background jobs run in a separate process group and a line
206                    prints upon completion. The exit status of background jobs
207                    is  reported  in a completion message. On systems with job
208                    control, this flag is turned on automatically for interac‐
209                    tive shells.
210
211
212       -n           Reads commands and checks them for syntax errors, but does
213                    not execute them. Ignored for interactive shells.
214
215
216       +o           Writes the current option stettings to standard output  in
217                    a format that is suitable for reinput to the shell as com‐
218                    mands that achieve the same option settings.
219
220
221       -o option    The option argument can be one  of  the  following  option
222                    names:
223
224                    allexport     Same as -a.
225
226
227                    errexit       Same as -e.
228
229
230                    bgnice        All  background jobs are run at a lower pri‐
231                                  ority. This is the default mode. emacs  Puts
232                                  you  in  an  emacs  style in-line editor for
233                                  command entry.
234
235
236                    gmacs         Puts you in a gmacs style in-line editor for
237                                  command entry.
238
239
240                    ignoreeof     The  shell does not exit on end-of-file. The
241                                  command exit must be used.
242
243
244                    keyword       Same as -k.
245
246
247                    markdirs      All directory names resulting from file name
248                                  generation have a trailing / appended.
249
250
251                    monitor       Same as -m.
252
253
254                    noclobber     Prevents  redirection  operator > from trun‐
255                                  cating existing files. Requires the >| oper‐
256                                  ator to truncate a file when turned on. Same
257                                  as -C.
258
259
260                    noexec        Same as -n.
261
262
263                    noglob        Same as -f.
264
265
266                    nolog         Does not save function definitions  in  his‐
267                                  tory file.
268
269
270                    notify        Same as -b.
271
272
273                    nounset       Same as -u.
274
275
276                    privileged    Same as -p.
277
278
279                    verbose       Same as -v.
280
281
282                    trackall      Same as -h.
283
284
285                    vi            Puts  you  in  insert mode of a vi style in-
286                                  line editor until you hit  escape  character
287                                  033. This puts you in control mode. A return
288                                  sends the line.
289
290
291                    viraw         Each character is processed as it  is  typed
292                                  in vi mode.
293
294
295                    xtrace        Same as -x.
296
297
298
299
300       If  no  option  name  is  supplied then the current option settings are
301       printed.
302
303       -p      Disables processing of the $HOME/.profile  file  and  uses  the
304               file /etc/suid_profile instead of the ENV file. This mode is on
305               whenever the effective uid is not equal to  the  real  uid,  or
306               when  the  effective  gid is not equal to the real gid. Turning
307               this off causes the effective uid and gid to be set to the real
308               uid and gid.
309
310
311       -s      Sorts the positional parameters lexicographically.
312
313
314       -t      Exits after reading and executing one command.
315
316
317       -u      Treats unset parameters as an error when substituting.
318
319
320       -v      Prints shell input lines as they are read.
321
322
323       -x      Prints commands and their arguments as they are executed.
324
325
326       Turns  off  -x  and  -v flags and stops examining arguments for
327               flags.
328
329
330       -       Does not change any of the flags. This option is useful in set‐
331               ting  $1  to  a  value beginning with . If no arguments follow
332               this flag then the positional parameters are unset.
333
334
335
336       Using + rather than causes these flags to be turned off. These  flags
337       can also be used upon invocation of the shell. The current set of flags
338       can be found in $−. Unless -A is specified, the remaining arguments are
339       positional  parameters  and are assigned, in order, to $1 $2 .... If no
340       arguments are specified then the names and values of all variables  are
341       printed on the standard output.
342
343
344       The  variables  specified by the list of names are unassigned, that is,
345       their values and attributes are erased. readonly  variables  cannot  be
346       unset.  If  the -f flag is set, then the names refer to function names.
347       Unsetting ERRNO, LINENO, MAILCHECK, OPTARG,  OPTIND,  RANDOM,  SECONDS,
348       TMOUT,  and  _  removes  their  special meaning even if they are subse‐
349       quently assigned.
350
351
352       When using unset, the variables specified by  the  list  of  names  are
353       unassigned,  i.e.,  their  values  and  attributes are erased. readonly
354       variables cannot be unset. If the -f, flag is set, then the names refer
355       to  function names. Unsetting ERRNO, LINENO, MAILCHECK, OPTARG, OPTIND,
356       RANDOM, SECONDS, TMOUT, and _ removes their  special  meaning  even  if
357       they are subsequently assigned.
358
359
360       With  the export built-in, the specified names are marked for automatic
361       export to the environment of subsequently-executed commands.
362
363
364       When -p is specified, export writes to the standard  output  the  names
365       and values of all exported variables in the following format:
366
367         "export %s=%s\n", name, value
368
369
370
371
372       if name is set, and:
373
374         "export %s\n", name
375
376
377
378
379       if name is unset.
380
381
382       The  shell  formats the output, including the proper use of quoting, so
383       that it is suitable for reinput to the shell as commands  that  achieve
384       the same exporting results, except for the following:
385
386           1.     Read-only variables with values cannot be reset.
387
388           2.     Variables  that  were unset at the time they were output are
389                  not reset to the unset state if a value is assigned  to  the
390                  variable  between  the time the state was saved and the time
391                  at which the saved output is reinput to the shell.
392
393
394       On this manual page, ksh(1) commands that are preceded by one or two  *
395       (asterisks) are treated specially in the following ways:
396
397           1.     Variable  assignment  lists  preceding the command remain in
398                  effect when the command completes.
399
400           2.     I/O redirections are processed after variable assignments.
401
402           3.     Errors cause a script that contains them to abort.
403
404           4.     Words, following a command preceded by ** that  are  in  the
405                  format  of a variable assignment, are expanded with the same
406                  rules as a variable assignment. This means that  tilde  sub‐
407                  stitution  is  performed after the = sign and word splitting
408                  and file name generation are not performed.
409
410   ksh93
411       set sets or unsets options and positional parameters. Options that  are
412       specified with a - cause the options to be set. Options that are speci‐
413       fied with a + cause the option to be unset.
414
415
416       set without any options or arguments displays the names and  values  of
417       all  shell variables in the order of the collation sequence in the cur‐
418       rent locale. The values are quoted so that they are suitable for  input
419       again to the shell.
420
421
422       If no arguments are specified, not even the end of options argument --,
423       the positional parameters  are  unchanged.  Otherwise,  unless  the  -A
424       option  has  been  specified, the positional parameters are replaced by
425       the list of arguments. A first argument of -- is ignored  when  setting
426       positional parameters.
427
428
429       For  backwards  compatibility, a set command without any options speci‐
430       fied, whose first argument is - turns off the -v and -x options. If any
431       additional arguments are specified, they replace the positional parame‐
432       ters.
433
434
435       The options for set in ksh93 are:
436
437       -a             Set the export attribute for each  variable  whose  name
438                      does not contain a . that you assign a value in the cur‐
439                      rent shell environment.
440
441
442       -A name        Assign the arguments sequentially to the array named  by
443                      name  starting  at  subscript 0 rather than to the posi‐
444                      tional parameters.
445
446
447       -b             The shell writes a message to standard error as soon  it
448                      detects  that  a  background  job  completes rather than
449                      waiting until the next prompt.
450
451
452       -B             Enable {...} group expansion. On by default.
453
454
455       -C             Prevents existing regular files from  being  overwritten
456                      using  the  >  redirection  operator. The >| redirection
457                      overrides this noclobber option.
458
459
460       -e             A simple command that has a non-zero exit status  causes
461                      the shell to exit unless the simple command is:
462
463                          o      contained in an && or || list
464
465                          o      the  command immediately following if, while,
466                                 or until
467
468                          o      contained in the pipeline following !
469
470
471       -f             Pathname expansion is disabled.
472
473
474       -G             Causes ** by itself to also  match  all  sub-directories
475                      during pathname expansion.
476
477
478       -h             Obsolete.  Causes each command whose name has the syntax
479                      of an alias to become a tracked alias when it  is  first
480                      encountered.
481
482
483       -H             Enable !-style history expansion similar to csh.
484
485
486       -k             This  is  obsolete. All arguments of the form name=value
487                      are removed and placed in the variable  assignment  list
488                      for  the  command. Ordinarily, variable assignments must
489                      precede command arguments.
490
491
492       -m             When enabled, the shell runs background jobs in a  sepa‐
493                      rate  process group and displays a line upon completion.
494                      This mode is enabled by default for  interactive  shells
495                      on systems that support job control.
496
497
498       -n             The  shell  reads commands and checks for syntax errors,
499                      but does not execute the command. Usually  specified  on
500                      command invocation.
501
502
503       -o [option]    If  option  is  not  specified,  the list of options and
504                      their current settings is written  to  standard  output.
505                      When  invoked with a + the options are written in a for‐
506                      mat that can be input again to the shell to restore  the
507                      settings.  This option can be repeated to enable or dis‐
508                      able multiple options.
509
510                      The value of option must be one of the following:
511
512                      allexport      Same as -a.
513
514
515                      bgnice         All background jobs are run at lower pri‐
516                                     orities.
517
518
519                      braceexpand    Same as -B.
520
521
522                      emacs          Enables or disables emacs editing mode.
523
524
525                      errexit        Same as -e.
526
527
528                      globstar       Equivalent to -G.
529
530
531                      gmacs          Enables  or disables gmacs. gmacs editing
532                                     mode is the same as emacs  editing  mode,
533                                     except for the handling of CTRL-T.
534
535
536                      histexpand     Same as -H.
537
538
539                      ignoreeof      The  interactive  shell  does not exit on
540                                     end-of-file.
541
542
543                      keyword        Same as -k.
544
545
546                      markdirs       All directory names resulting  from  file
547                                     name   generation   have   a  trailing  /
548                                     appended.
549
550
551                      monitor        Same as -m.
552
553
554                      multiline      Use multiple  lines  when  editing  lines
555                                     that are longer than the window width.
556
557
558                      noclobber      Same as -C.
559
560
561                      noexec         Same as -n.
562
563
564                      noglob         Same as -f.
565
566
567                      nolog          This  has  no  effect. It is provided for
568                                     backward compatibility.
569
570
571                      notify         Same as -b.
572
573
574                      nounset        Same as -u.
575
576
577                      pipefail       A pipeline does not  complete  until  all
578                                     components  of  the  pipeline  have  com‐
579                                     pleted, and the exit status of the  pipe‐
580                                     line  is the value of the last command to
581                                     exit with non-zero  exit  status,  or  is
582                                     zero  if  all  commands  return zero exit
583                                     status.
584
585
586                      privileged     Same as -p.
587
588
589                      showme         Simple  commands  preceded  by  a  ;  are
590                                     traced as if -x were enabled but not exe‐
591                                     cuted.
592
593
594                      trackall       Same as -h.
595
596
597                      verbose        Same as -v.
598
599
600                      vi             Enables or disables vi editing mode.
601
602
603                      viraw          Does not use canonical  input  mode  when
604                                     using vi edit mode
605
606
607                      xtrace         Same as -x.
608
609
610
611       -p             Privileged mode. Disabling -p sets the effective user id
612                      to the real user id, and the effective group id  to  the
613                      real  group  id. Enabling -p restores the effective user
614                      and group  ids  to  their  values  when  the  shell  was
615                      invoked.  The  -p  option  is  on  whenever the real and
616                      effective user id is not equal or the real and effective
617                      group  id  is not equal. User profiles are not processed
618                      when -p is enabled.
619
620
621       -r             Restricted. Enables restricted shell. This option cannot
622                      be unset once enabled.
623
624
625       -s             Sort the positional parameters
626
627
628       -t             Obsolete. The shell reads one command and then exits.
629
630
631       -u             If  enabled, the shell displays an error message when it
632                      tries to expand a variable that is unset.
633
634
635       -v             Verbose. The shell  displays  its  input  onto  standard
636                      error as it reads it.
637
638
639       -x             Execution  trace.  The shell displays each command after
640                      all expansion  and  before  execution  preceded  by  the
641                      expanded value of the PS4 parameter.
642
643
644
645       The following exit values are returned by set in ksh93:
646
647       0     Successful completion.
648
649
650       >0    An error occurred.
651
652
653
654       For  each  name specified, unset unsets the variable, or function if -f
655       is specified, from the current shell execution  environment.  Read-only
656       variables cannot be unset.
657
658
659       The options for unset in ksh93 are:
660
661       -f    Where  name refers to a function name, the shell unsets the func‐
662             tion definition.
663
664
665       -n    If name refers to variable that is a reference, the variable name
666             is  unset rather than the variable it references. Otherwise, this
667             option is equivalent to the -v option.
668
669
670       -v    Where name refers to a variable name, the  shell  unsets  it  and
671             removes it from the environment. This is the default behavior.
672
673
674
675       The following exit values are returned by unset in ksh93:
676
677       0     Successful completion. All names were successfully unset.
678
679
680       >0    An  error  occurred,  or  one  or more name operands could not be
681             unset
682
683
684
685       export sets the export attribute on each of the variables specified  by
686       name  which  causes  them to be in the environment of subsequently exe‐
687       cuted commands. If =value is specified, the variable  name  is  set  to
688       value.
689
690
691       If no name is specified, the names and values of all exported variables
692       are written to standard output.
693
694
695       export is built-in to the shell as a declaration command so that  field
696       splitting  and  pathname  expansion are not performed on the arguments.
697       Tilde expansion occurs on value.
698
699
700       The options for export in ksh93 are:
701
702       -p    Causes the output to be in the form of export commands  that  can
703             be used as input to the shell to recreate the current exports.
704
705
706
707       The following exit values are returned by export in ksh93:
708
709       0     Successful completion.
710
711
712       >0    An error occurred.
713
714
715
716       On  this manual page, ksh93(1) commands that are preceded by one or two
717       + are treated specially in the following ways:
718
719           1.     Variable assignment lists preceding the  command  remain  in
720                  effect when the command completes.
721
722           2.     I/O redirections are processed after variable assignments.
723
724           3.     Errors cause a script that contains them to abort.
725
726           4.     They are not valid function names.
727
728           5.     Words,  following  a  command preceded by ++ that are in the
729                  format of a variable assignment, are expanded with the  same
730                  rules  as  a variable assignment. This means that tilde sub‐
731                  stitution is performed after the = sign and field  splitting
732                  and file name generation are not performed.
733

EXAMPLES

735   csh
736       The following example sets the PATH variable to search for files in the
737       /bin, /usr/bin, /usr/sbin, and /usr/ucb/bin directories, in that order:
738
739         setenv PATH "/bin:/usr/bin:/usr/sbin:usr/ucb/bin"
740
741
742

ATTRIBUTES

744       See attributes(5) for descriptions of the following attributes:
745
746
747
748
749       ┌─────────────────────────────┬─────────────────────────────┐
750       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
751       ├─────────────────────────────┼─────────────────────────────┤
752       │Availability                 │SUNWcsu                      │
753       └─────────────────────────────┴─────────────────────────────┘
754

SEE ALSO

756       csh(1), ksh(1), ksh93(1), read(1),  sh(1),  typeset(1),  attributes(5),
757       environ(5)
758
759
760
761SunOS 5.11                        20 Nov 2007                           set(1)
Impressum