1emulate [ -LR ] [ {zsh|sh|ksh|csh} [ flags ... ] ]
2       Without any argument print current emulation mode.
3
4       With single argument set up zsh options to emulate the specified
5       shell  as  much  as possible.  csh will never be fully emulated.
6       If the argument is not one of the shells listed above, zsh  will
7       be used as a default; more precisely, the tests performed on the
8       argument are the same as those used to determine  the  emulation
9       at  startup based on the shell name, see the section COMPATIBIL-
10       ITY in zsh(1) .  In addition to setting shell options, the  com-
11       mand  also restores the pristine state of pattern enables, as if
12       all patterns had been enabled using enable -p.
13
14       If the emulate command occurs inside a function  that  has  been
15       marked  for  execution tracing with functions -t then the xtrace
16       option will be turned on regardless of emulation mode  or  other
17       options.   Note that code executed inside the function by the .,
18       source, or  eval  commands  is  not  considered  to  be  running
19       directly  from  the function, hence does not provoke this behav-
20       iour.
21
22       If the -R switch is given, all settable  options  are  reset  to
23       their  default  value  corresponding  to the specified emulation
24       mode, except for  certain  options  describing  the  interactive
25       environment;  otherwise,  only  those  options  likely  to cause
26       portability problems in scripts and functions are  altered.   If
27       the  -L  switch  is given, the options LOCAL OPTIONS, LOCAL PAT-
28                                                   -              -
29       TERNS and LOCAL TRAPS will be set as well, causing  the  effects
30                      -
31       of  the emulate command and any setopt, disable -p or enable -p,
32       and trap commands to be local  to  the  immediately  surrounding
33       shell function, if any; normally these options are turned off in
34       all emulation modes except ksh. The -L switch is mutually exclu-
35       sive with the use of -c in flags.
36
37       The  flags  may be any of the invocation-time flags described in
38       the section INVOCATION in zsh(1), except that `-o EMACS' and `-o
39       VI'  may not be used.  Flags such as `+r'/`+o RESTRICTED' may be
40       prohibited in some circumstances.
41
42       If -c arg appears in flags, arg is evaluated while the requested
43       emulation  is temporarily in effect.  In this case the emulation
44       mode and all options  are  restored  to  their  previous  values
45       before  emulate  returns.  The -R switch may precede the name of
46       the shell to emulate; note this  has  a  meaning  distinct  from
47       including -R in flags.
48
49       Use  of -c enables `sticky' emulation mode for functions defined
50       within the evaluated expression:  the emulation mode is  associ-
51       ated  thereafter with the function so that whenever the function
52       is executed the emulation (respecting the -R switch, if present)
53       and  all  options  are set (and pattern disables cleared) before
54       entry to the function, and the state is restored after exit.  If
55       the  function  is called when the sticky emulation is already in
56       effect, either within an `emulate shell -c' expression or within
57       another  function with the same sticky emulation, entry and exit
58       from the function do not cause options to be altered (except due
59       to  standard processing such as the LOCAL OPTIONS option).  This
60                                                -
61       also applies to functions marked for autoload within the  sticky
62       emulation; the appropriate set of options will be applied at the
63       point the function is loaded as well as when it is run.
64
65       For example:
66
67              emulate sh -c 'fni() { setopt cshnullglob; }
68              fno() { fni; }'
69              fno
70
71       The two functions fni and fno are defined with sticky sh  emula-
72       tion.   fno  is  then  executed, causing options associated with
73       emulations to be set to their values in sh.  fni then calls fno;
74       because  fno  is  also marked for sticky sh emulation, no option
75       changes take place on entry to  or  exit  from  it.   Hence  the
76       option  cshnullglob,  turned off by sh emulation, will be turned
77       on within fni and remain on on return to fno.  On exit from fno,
78       the emulation mode and all options will be restored to the state
79       they were in before entry to the temporary emulation.
80
81       The documentation above is typically sufficient for the intended
82       purpose  of  executing code designed for other shells in a suit-
83       able environment.  More detailed rules follow.
84       1.     The sticky emulation  environment  provided  by  `emulate
85              shell  -c'  is  identical  to that provided by entry to a
86              function marked for sticky emulation as a consequence  of
87              being  defined  in such an environment.  Hence, for exam-
88              ple, the sticky emulation is  inherited  by  subfunctions
89              defined within functions with sticky emulation.
90       2.     No change of options takes place on entry to or exit from
91              functions that are not marked for sticky emulation, other
92              than  those that would normally take place, even if those
93              functions are called within sticky emulation.
94       3.     No special handling is provided for functions marked  for
95              autoload nor for functions present in wordcode created by
96              the zcompile command.
97       4.     The presence or absence of the -R switch to emulate  cor-
98              responds  to  different  sticky  emulation  modes, so for
99              example `emulate sh -c', `emulate -R sh -c' and  `emulate
100              csh -c' are treated as three distinct sticky emulations.
101       5.     Difference  in  shell options supplied in addition to the
102              basic emulation also mean the sticky emulations are  dif-
103              ferent,  so for example `emulate zsh -c' and `emulate zsh
104              -o cbases -c' are treated as distinct sticky emulations.
105