emulate [ -lLR ] [ {zsh|sh|ksh|csh} [ flags ... ] ]
       Without any argument print current emulation mode.

       With  single  argument  set  up zsh options to emulate the specified
       shell as much as possible.  csh will never be  fully  emulated.   If
       the argument is not one of the shells listed above, zsh will be used
       as  a  default;  more precisely, the tests performed on the argument
       are the same as those used to determine  the  emulation  at  startup
       based  on  the shell name, see the section COMPATIBILITY in zsh(1) .
       In addition to setting shell options, the command also restores  the
       pristine  state  of pattern enables, as if all patterns had been en-
       abled using enable -p.

       If the emulate command occurs inside a function that has been marked
       for execution tracing with functions -t then the xtrace option  will
       be  turned  on  regardless of emulation mode or other options.  Note
       that code executed inside the function by the  .,  source,  or  eval
       commands is not considered to be running directly from the function,
       hence does not provoke this behaviour.

       If  the  -R switch is given, all settable options are reset to their
       default value corresponding to the specified emulation mode,  except
       for  certain  options describing the interactive environment; other-
       wise, only those options likely to  cause  portability  problems  in
       scripts  and  functions are altered.  If the -L switch is given, the
       options LOCAL_OPTIONS, LOCAL_PATTERNS and LOCAL_TRAPS will be set as
       well, causing the effects of the emulate  command  and  any  setopt,
       disable  -p or enable -p, and trap commands to be local to the imme-
       diately surrounding shell function, if any; normally  these  options
       are  turned  off in all emulation modes except ksh. The -L switch is
       mutually exclusive with the use of -c in flags.

       If there is a single argument and the -l switch is  given,  the  op-
       tions that would be set or unset (the latter indicated with the pre-
       fix `no') are listed.  -l can be combined with -L or -R and the list
       will be modified in the appropriate way.  Note the list does not de-
       pend on the current setting of options, i.e. it includes all options
       that  may  in  principle  change, not just those that would actually
       change.

       The flags may be any of the invocation-time flags described  in  the
       section INVOCATION in zsh(1), except that `-o EMACS' and `-o VI' may
       not  be  used.  Flags such as `+r'/`+o RESTRICTED' may be prohibited
       in some circumstances.

       If -c arg appears in flags, arg is evaluated while the requested em-
       ulation is temporarily in effect.  In this case the  emulation  mode
       and all options are restored to their previous values before emulate
       returns.   The  -R  switch may precede the name of the shell to emu-
       late; note this has a meaning distinct from including -R in flags.

       Use of -c enables `sticky'  emulation  mode  for  functions  defined
       within  the  evaluated expression:  the emulation mode is associated
       thereafter with the function so that whenever the function  is  exe-
       cuted  the  emulation (respecting the -R switch, if present) and all
       options are set (and pattern disables cleared) before entry  to  the
       function,  and the state is restored after exit.  If the function is
       called when the sticky emulation is already in effect, either within
       an `emulate shell -c' expression or within another function with the
       same sticky emulation, entry and exit from the function do not cause
       options to be altered (except due to standard processing such as the
       LOCAL_OPTIONS option).  This also applies to  functions  marked  for
       autoload within the sticky emulation; the appropriate set of options
       will  be applied at the point the function is loaded as well as when
       it is run.

       For example:

              emulate sh -c 'fni() { setopt cshnullglob; }
              fno() { fni; }'
              fno

       The two functions fni and fno are defined with sticky sh  emulation.
       fno  is then executed, causing options associated with emulations to
       be set to their values in sh.  fno then calls fni;  because  fni  is
       also marked for sticky sh emulation, no option changes take place on
       entry  to or exit from it.  Hence the option cshnullglob, turned off
       by sh emulation, will be turned on within fni and remain  on  return
       to  fno.   On exit from fno, the emulation mode and all options will
       be restored to the state they were in before entry to the  temporary
       emulation.

       The  documentation  above  is  typically sufficient for the intended
       purpose of executing code designed for other shells  in  a  suitable
       environment.  More detailed rules follow.
       1.     The  sticky  emulation environment provided by `emulate shell
              -c' is identical to that provided  by  entry  to  a  function
              marked for sticky emulation as a consequence of being defined
              in  such an environment.  Hence, for example, the sticky emu-
              lation is inherited by subfunctions defined within  functions
              with sticky emulation.
       2.     No  change  of  options  takes place on entry to or exit from
              functions that are not marked  for  sticky  emulation,  other
              than  those  that  would  normally  take place, even if those
              functions are called within sticky emulation.
       3.     No special handling is provided for functions marked for  au-
              toload  nor  for functions present in wordcode created by the
              zcompile command.
       4.     The presence or absence of the -R switch  to  emulate  corre-
              sponds  to  different  sticky emulation modes, so for example
              `emulate sh -c', `emulate -R sh -c' and `emulate csh -c'  are
              treated as three distinct sticky emulations.
       5.     Difference in shell options supplied in addition to the basic
              emulation  also  mean the sticky emulations are different, so
              for example `emulate zsh -c' and `emulate zsh -o  cbases  -c'
              are treated as distinct sticky emulations.
