338
343
cindex(sh, compatibility)
339
344
cindex(ksh, compatibility)
340
345
cindex(csh, compatibility)
341
item(tt(emulate) [ tt(-LR) ] {tt(zsh)|tt(sh)|tt(ksh)|tt(csh)})(
342
Set up zsh options to emulate the specified shell as much as possible.
346
item(tt(emulate) [ tt(-LR) ] [ {tt(zsh)|tt(sh)|tt(ksh)|tt(csh)} [ tt(-c) tt(arg) ] ])(
347
Without any argument print current emulation mode.
349
With single argument set up zsh options to emulate the specified shell
343
351
bf(csh) will never be fully emulated.
344
352
If the argument is not one of the shells listed above, tt(zsh)
345
353
will be used as a default; more precisely, the tests performed on the
352
360
noderef(Compatibility)
354
. If the tt(-R) option is given, all options
364
If the tt(-R) option is given, all options
355
365
are reset to their default value corresponding to the specified emulation
356
366
mode, except for certain options describing the interactive
357
367
environment; otherwise, only those options likely to cause portability
358
problems in scripts and functions are altered. If the tt(-L) option
359
is given, the options tt(LOCAL_OPTIONS) and tt(LOCAL_TRAPS) will be set as
368
problems in scripts and functions are altered. If the tt(-L) option is given,
369
the options tt(LOCAL_OPTIONS) and tt(LOCAL_TRAPS) will be set as
360
370
well, causing the effects of the tt(emulate) command and any tt(setopt) and
361
371
tt(trap) commands to be local to the immediately surrounding shell
362
372
function, if any; normally these options are turned off in all emulation
363
modes except tt(ksh).
373
modes except tt(ksh). The tt(-L) and tt(-c) are mutually exclusive.
375
If tt(-c) tt(arg) is given, evaluate tt(arg) while the requested
376
emulation is temporarily in effect. The emulation and all options will
377
be restored to their original values before tt(emulate) returns. The
378
tt(-R) flag may be used.
380
Use of tt(-c) enables `sticky' emulation mode for functions defined
381
within the evaluated expression: the emulation mode is associated
382
thereafter with the function so that whenever the function is executed
383
the emulation (respecting the tt(-R) flag, if present) and all
384
options are set before entry to the function, and restored after exit.
385
If the function is called when the sticky emulation is already in
386
effect, either within an `tt(emulate) var(shell) tt(-c)' expression or
387
within another function with the same sticky emulation, entry and exit
388
from the function do not cause options to be altered (except due to
389
standard processing such as the tt(LOCAL_OPTIONS) option).
393
example(emulate sh -c 'fni+LPAR()RPAR() { setopt cshnullglob; }
394
fno+LPAR()RPAR() { fni; }'
398
The two functions tt(fni) and tt(fno) are defined with sticky tt(sh)
399
emulation. tt(fno) is then executed, causing options associated
400
with emulations to be set to their values in tt(sh). tt(fni) then
401
calls tt(fno); because tt(fno) is also marked for sticky tt(sh)
402
emulation, no option changes take place on entry to or exit from it.
403
Hence the option tt(cshnullglob), turned off by tt(sh) emulation, will
404
be turned on within tt(fni) and remain on on return to tt(fno). On exit
405
from tt(fno), the emulation mode and all options will be restored to the
406
state they were in before entry to the temporary emulation.
408
The documentation above is typically sufficient for the intended
409
purpose of executing code designed for other shells in a suitable
410
environment. More detailed rules follow.
412
sitem(1.)(The sticky emulation environment provided by `tt(emulate)
413
var(shell) tt(-c)' is identical to that provided by entry to
414
a function marked for sticky emulation as a consequence of being
415
defined in such an environment. Hence, for example, the sticky
416
emulation is inherited by subfunctions defined within functions
417
with sticky emulation.)
418
sitem(2.)(No change of options takes place on entry to or exit from
419
functions that are not marked for sticky emulation, other than those
420
that would normally take place, even if those functions are called
421
within sticky emulation.)
422
sitem(3.)(No special handling is provided for functions marked for
423
tt(autoload) nor for functions present in wordcode created by
424
the tt(zcompile) command.)
425
sitem(4.)(The presence or absence of the tt(-R) flag to tt(emulate)
426
corresponds to different sticky emulation modes, so for example
427
`tt(emulate sh -c)', `tt(emulate -R sh -c)' and `tt(emulate csh -c)'
428
are treated as three distinct sticky emulations.)
366
432
cindex(enabling commands)
452
520
The flag tt(-r) reverses the order of the commands and the
453
521
flag tt(-n) suppresses command numbers when listing.
454
Also when listing, tt(-d) prints timestamps for each command, and
455
tt(-f) prints full time-date stamps. Adding the tt(-E) flag
456
causes the dates to be printed as `var(dd)tt(.)var(mm)tt(.)var(yyyy)',
457
instead of the default `var(mm)tt(/)var(dd)tt(/)var(yyyy)'.
458
Adding the tt(-i) flag causes the dates to be printed in ISO8601
459
`var(yyyy)tt(-)var(mm)tt(-)var(dd)' format.
460
With the tt(-D) flag, tt(fc) prints elapsed times.
525
sitem(tt(-d))(prints timestamps for each command)
526
sitem(tt(-f))(prints full time-date stamps in the US
527
`var(MM)tt(/)var(DD)tt(/)var(YY) var(hh):var(mm)' format)
528
sitem(tt(-E))(prints full time-date stamps in the European
529
`var(dd)tt(.)var(mm)tt(.)var(yyyy) var(hh):var(mm)' format)
530
sitem(tt(-i))(prints full time-date stamps in ISO8601
531
`var(yyyy)tt(-)var(mm)tt(-)var(dd) var(hh):var(mm)' format)
532
sitem(tt(-t) var(fmt))(prints time and date stamps in the given format;
533
var(fmt) is formatted with the strftime function with the zsh extensions
534
described for the tt(%D{)var(string)tt(}) prompt format in
535
ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\
536
ifnzman(noderef(Prompt Expansion)). The resulting formatted string must be
537
no more than 256 characters or will not be printed.
539
sitem(tt(-D))(prints elapsed times; may be combined with one of the
462
543
cindex(history, stack)
463
544
cindex(stack, history)