home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / unix-faq / shell / zsh < prev   
Encoding:
Internet Message Format  |  2002-08-26  |  97.6 KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!newsfeed.utk.edu!news-hog.berkeley.edu!ucberkeley!luth.se!skynet.be!skynet.be!newsfeed.esat.net!195.92.193.180.MISMATCH!nntp.theplanet.net!inewsm1.nntp.theplanet.net!news.theplanet.net!not-for-mail
  2. From: pws@pwstephenson.fsnet.co.uk (Peter Stephenson)
  3. Newsgroups: comp.unix.shell,comp.answers,news.answers
  4. Subject: Z-shell (zsh) Frequently-Asked Questions
  5. Supersedes: <m26608wfpl.fsf@pwstephenson.fsnet.co.uk>
  6. Followup-To: comp.unix.shell
  7. Date: 25 Aug 2002 17:43:04 +0100
  8. Organization: Chaotic
  9. Lines: 2172
  10. Approved: news-answers-request@MIT.Edu
  11. Distribution: world
  12. Expires: 24 September 2002 00:00:00 GMT
  13. Message-ID: <m2d6s6x52f.fsf@pwstephenson.fsnet.co.uk>
  14. NNTP-Posting-Host: modem-8.cirdan.dialup.pol.co.uk
  15. X-Trace: newsg3.svr.pol.co.uk 1030293496 24399 62.136.147.136 (25 Aug 2002 16:38:16 GMT)
  16. NNTP-Posting-Date: 25 Aug 2002 16:38:16 GMT
  17. X-Complaints-To: abuse@theplanet.net
  18. X-Newsreader: Gnus v5.7/Emacs 20.7
  19. Xref: senator-bedfellow.mit.edu comp.unix.shell:134226 comp.answers:51068 news.answers:236181
  20.  
  21. Archive-Name: unix-faq/shell/zsh
  22. Last-Modified: 2002/08/25
  23. Submitted-By: pws@pwstephenson.fsnet.co.uk (Peter Stephenson)
  24. Posting-Frequency: Monthly
  25. Copyright: (C) P.W. Stephenson, 1995--2001 (see end of document)
  26.  
  27. Changes since last issue posted:
  28.  
  29.   1.5 4.0.6 released.
  30.  
  31. This document contains a list of frequently-asked (or otherwise
  32. significant) questions concerning the Z-shell, a command interpreter
  33. for many UNIX systems which is freely available to anyone with FTP
  34. access.  Zsh is among the most powerful freely available Bourne-like
  35. shell for interactive use.
  36.  
  37. If you have never heard of `sh', `csh' or `ksh', then you are
  38. probably better off to start by reading a general introduction to UNIX
  39. rather than this document.
  40.  
  41. If you just want to know how to get your hands on the latest version,
  42. skip to question 1.6; if you want to know what to do with
  43. insoluble problems, go to 5.2.
  44.  
  45. Notation: Quotes `like this' are ordinary textual quotation
  46. marks.  Other uses of quotation marks are input to the shell.
  47.  
  48. Contents:
  49. Chapter 1:  Introducing zsh and how to install it
  50. 1.1. Sources of information
  51. 1.2. What is it?
  52. 1.3. What is it good at?
  53. 1.4. On what machines will it run?  (Plus important compilation notes)
  54. 1.5. What's the latest version?
  55. 1.6. Where do I get it?
  56. 1.7. I don't have root access: how do I make zsh my login shell?
  57.  
  58. Chapter 2:  How does zsh differ from...?
  59. 2.1. sh and ksh?
  60. 2.2. csh?
  61. 2.3. Why do my csh aliases not work?  (Plus other alias pitfalls.)
  62. 2.4. tcsh?
  63. 2.5. bash?
  64. 2.6. Shouldn't zsh be more/less like ksh/(t)csh?
  65.  
  66. Chapter 3:  How to get various things to work
  67. 3.1. Why does `$var' where `var="foo bar"' not do what I expect?
  68. 3.2. In which startup file do I put...?
  69. 3.3. What is the difference between `export' and the ALL_EXPORT option?
  70. 3.4. How do I turn off spelling correction/globbing for a single command?
  71. 3.5. How do I get the meta key to work on my xterm?
  72. 3.6. How do I automatically display the directory in my xterm title bar?
  73. 3.7. How do I make the completion list use eight bit characters?
  74. 3.8. Why do the cursor (arrow) keys not work?
  75. 3.9. Why does my terminal act funny in some way?
  76. 3.10. Why does zsh not work in an Emacs shell mode any more?
  77. 3.11. Why do my autoloaded functions not autoload [the first time]?
  78. 3.12. How does base arithmetic work?
  79. 3.13. How do I get a newline in my prompt?
  80. 3.14. Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  81. 3.15. Why can't I bind \C-s and \C-q any more?
  82. 3.16. How do I execute command `foo' within function `foo'?
  83. 3.17. Why do history substitutions with single bangs do something funny?
  84. 3.18. Why does zsh kill off all my background jobs when I logout?
  85. 3.19. How do I list all my history entries?
  86. 3.20. How does the alternative loop syntax, e.g. `while {...} {...}' work?
  87. 3.21. Why is my history not being saved?
  88. 3.22. How do I get a variable's value to be evaluated as another variable?
  89. 3.23. How do I prevent the prompt overwriting output when there is no newline?
  90. 3.24. What's wrong with cut and paste on my xterm?
  91. 3.25. How do I get coloured prompts on my colour xterm?
  92. 3.26. Why is my output duplicated with `foo 2>&1 >foo.out | bar'?
  93. 3.27. Why am I prompted to correct commands which are in my path?
  94.  
  95. Chapter 4:  The mysteries of completion
  96. 4.1. What is completion?
  97. 4.2. What sorts of things can be completed?
  98. 4.3. How does zsh deal with ambiguous completions?
  99. 4.4. How do I complete in the middle of words / just what's before the cursor?
  100. 4.5. How do I get started with programmable completion?
  101. 4.6. And if programmable completion isn't good enough?
  102.  
  103. Chapter 5:  The future of zsh
  104. 5.1. What bugs are currently known and unfixed? (Plus recent important changes)
  105. 5.2. Where do I report bugs, get more info / who's working on zsh?
  106. 5.3. What's on the wish-list?
  107. 5.4. Did zsh have problems in the year 2000?
  108.  
  109. Acknowledgments
  110.  
  111. Copyright
  112. --- End of Contents ---
  113.  
  114. Chapter 1: Introducing zsh and how to install it
  115.  
  116. 1.1: Sources of information
  117.  
  118.   Information on zsh is available via the World Wide Web.  The URL
  119.   is http://zsh.sunsite.dk/ .
  120.   The server provides this FAQ and much else and is
  121.   now maintained by Karsten Thygesen and others (mail zsh@sunsite.dk
  122.   with any related messages).  The FAQ is at http://zsh.sunsite.dk/FAQ/ .
  123.   The site also contains some contributed zsh scripts and functions;
  124.   we are delighted to add more, or simply links to your own collection.
  125.  
  126.   This document was originally written in YODL, allowing it to be converted
  127.   easily into various other formats.  The master source file lives at
  128.   http://zsh.sunsite.dk/FAQ/zshfaq.yo and the plain text version
  129.   can be found at http://zsh.sunsite.dk/FAQ/zshfaq.txt .
  130.  
  131.   Another useful source of information is the collection of FAQ articles
  132.   posted frequently to the Usenet news groups comp.unix.questions,
  133.   comp.unix.shells and comp.answers with answers to general questions
  134.   about UNIX.  The fifth of the seven articles deals with shells,
  135.   including zsh, with a brief description of differences.  There is
  136.   also a separate FAQ on shell differences and how to change your
  137.   shell.  Usenet FAQs are available via FTP from rtfm.mit.edu and
  138.   mirrors and also on the World Wide Web; see
  139.  
  140.     USA         http://www.cis.ohio-state.edu/hypertext/faq/usenet/top.html
  141.     UK          http://www.lib.ox.ac.uk/internet/news/faq/comp.unix.shell.html
  142.     Netherlands http://www.cs.uu.nl/wais/html/na-dir/unix-faq/shell/.html
  143.  
  144.   You can also get it via email by emailing mail-server@rtfm.mit.edu
  145.   with, in the body of the message, `send faqs/unix-faq/shell/zsh'.
  146.  
  147.   The latest version of this FAQ is also available directly from any
  148.   of the zsh archive sites listed in question 1.6.
  149.  
  150.   I have been putting together a user guide to complement the manual by
  151.   explaining the most useful features of zsh in a more easy to read way.
  152.   This is now more than half complete and includes a discussion of
  153.   the new form for command line completion, not described in the FAQ.
  154.   You can find it in various formats at:
  155.     http://zsh.sunsite.dk/Guide/
  156.  
  157.   (As a method of reading the following in Emacs, you can type \M-2
  158.   \C-x $ to make all the indented text vanish, then \M-0 \C-x $
  159.   when you are on the title you want.)
  160.  
  161.   For any more eclectic information, you should contact the mailing
  162.   list:  see question 5.2.
  163.  
  164. 1.2: What is it?
  165.  
  166.   Zsh is a UNIX command interpreter (shell) which of the standard
  167.   shells most resembles the Korn shell (ksh); its compatibility with
  168.   the 1988 Korn shell has been gradually increasing.  It includes
  169.   enhancements of many types, notably in the command-line editor,
  170.   options for customising its behaviour, filename globbing, features
  171.   to make C-shell (csh) users feel more at home and extra features
  172.   drawn from tcsh (another `custom' shell).
  173.  
  174.   It was written by Paul Falstad when a student at Princeton; however,
  175.   Paul doesn't maintain it any more and enquiries should be sent to
  176.   the mailing list (see question 5.2).  Zsh is distributed under a
  177.   standard Berkeley style copyright.
  178.  
  179.   For more information, the files Doc/intro.txt or Doc/intro.troff
  180.   included with the source distribution are highly recommended.  A list
  181.   of features is given in FEATURES, also with the source.
  182.  
  183. 1.3: What is it good at?
  184.  
  185.   Here are some things that zsh is particularly good at.  No claim of
  186.   exclusivity is made, especially as shells copy one another, though
  187.   in the areas of command line editing and globbing zsh is well ahead
  188.   of the competition.  I am not aware of a major interactive feature
  189.   in any other freely-available shell which zsh does not also have
  190.   (except smallness).
  191.  
  192.   o  Command line editing:
  193.  
  194.     o  programmable completion: incorporates the ability to use the
  195.        full power of zsh's globbing and shell programming features,
  196.     o  multi-line commands editable as a single buffer (even files!),
  197.     o  variable editing (vared),
  198.     o  command buffer stack,
  199.     o  print text straight into the buffer for immediate editing (print -z),
  200.     o  execution of unbound commands,
  201.     o  menu completion in two flavours,
  202.     o  variable, editing function and option name completion,
  203.     o  inline expansion of variables and history commands.  
  204.  
  205.   o  Globbing --- extremely powerful, including:
  206.  
  207.     o  recursive globbing (cf. find),
  208.     o  file attribute qualifiers (size, type, etc. also cf. find),
  209.     o  full alternation and negation of patterns.
  210.  
  211.   o  Handling of multiple redirections (simpler than tee).
  212.   o  Large number of options for tailoring.
  213.   o  Path expansion (=foo -> /usr/bin/foo).
  214.   o  Adaptable messages for spelling, watch, time as well as prompt
  215.      (including conditional expressions).
  216.   o  Named directories.
  217.   o  Comprehensive integer and floating point arithmetic.
  218.   o  Manipulation of arrays (including reverse subscripting).
  219.   o  Associative arrays (key-to-value hashes)
  220.   o  Spelling correction.
  221.  
  222. 1.4: On what machines will it run?
  223.  
  224.   From version 3.0, zsh uses GNU autoconf as the installation
  225.   mechanism.  This considerably increases flexibility over the old
  226.   `buildzsh' mechanism.  Consequently, zsh should compile and run on
  227.   any modern version of UNIX, and a great many not-so-modern versions
  228.   too.  The file Etc/MACHINES in the distribution has more details.
  229.  
  230.   There are also now separate ports for Windows and OS/2, see `Where
  231.   do I get it' below.
  232.  
  233.   If you need to change something to support a new machine, it would be
  234.   appreciated if you could add any necessary preprocessor code and
  235.   alter configure.in and acconfig.h to configure zsh automatically,
  236.   then send the required context diffs to the list (see question
  237.   5.2).  Please make sure you have the latest version first.
  238.  
  239.   To get it to work, retrieve the source distribution (see question
  240.   1.6), un-gzip it, un-tar it and read the INSTALL file in the top
  241.   directory.  Also read the Etc/MACHINES file for up-to-date
  242.   information on compilation on certain architectures.
  243.  
  244.   *Note for users of nawk* (The following information comes from Zoltan
  245.   Hidvegi): On some systems nawk is broken and produces an incorrect
  246.   signames.h file. This makes the signals code unusable. This often happens
  247.   on Ultrix, HP-UX, IRIX (?). Install gawk if you experience such problems.
  248.  
  249. 1.5: What's the latest version?
  250.  
  251.   Zsh 4.0.6 is the latest production version.  The major number 4.0
  252.   reflects major improvements to modularity and to improvements in
  253.   the editor, programmable completion and many other smaller features
  254.   over the 3.0 series.  (The previous widely available release was
  255.   4.0.4.)
  256.  
  257.   There will not be any further 3.0 releases now that 4.0 has become
  258.   the stable version.  However, a few patches to 3.0.8 are available from
  259.   the patch manager at Sourceforge, http://sourceforge.net/patch/?group_id=4068
  260.   Official patches are posted by Bart Schaefer (user name barts).
  261.  
  262.   A beta of the next version is often available.  Development of zsh is
  263.   patch by patch, with each intermediate version publicly available.  Note
  264.   that this `open' development system does mean bugs are sometimes
  265.   introduced into the most recent archived version.  These are usually
  266.   fixed quickly.  If you are really interested in getting the latest
  267.   improvements, and less worried about providing a stable environment,
  268.   development versions are uploaded quite frequently to the archive in the
  269.   development subdirectory.
  270.  
  271.   Note also that as the shell changes, it may become incompatible with
  272.   older versions; see the end of question 5.1 for a partial list.
  273.   Changes of this kind are almost always forced by an awkward or
  274.   unnecessary feature in the original design (as perceived by current
  275.   users), or to enhance compatibility with other Bourne shell
  276.   derivatives, or (mostly in the 3.0 series) to provide POSIX compliancy.
  277.  
  278. 1.6: Where do I get it?
  279.  
  280.   The coordinator of development is currently me; the alias
  281.   coordinator@zsh.org can be used to contact whoever is in the hot
  282.   seat.  The following are known mirrors (kept frequently up to date); the
  283.   first is the official archive site, currently in Australia.  All are
  284.   available by anonymous FTP.  The major sites keep test versions in the
  285.   `testing' subdirectory: such up-to-the-minute development versions should
  286.   only be retrieved if you actually plan to help test the latest version of
  287.   the shell.  The following list also appears on the WWW at
  288.   http://www.zsh.org .
  289.  
  290.     Home site ftp://ftp.zsh.org
  291.               http://www.zsh.org/pub/zsh/
  292.     Denmark   ftp://sunsite.dk/pub/unix/shells/zsh
  293.     Finland   ftp://ftp.funet.fi/pub/unix/shells/zsh/
  294.     Germany   ftp://ftp.fu-berlin.de/pub/unix/shells/zsh/
  295.     Hungary   ftp://ftp.cs.elte.hu/pub/zsh/
  296.               (also http://www.cs.elte.hu/pub/zsh/ )
  297.               ftp://ftp.kfki.hu/pub/packages/zsh/
  298.     Israel    ftp://ftp.math.technion.ac.il/pub/zsh/
  299.               (also http://www.math.technion.ac.il/pub/zsh/ )
  300.     Japan     ftp://ftp.win.ne.jp/pub/shell/zsh/
  301.               ftp://ftp.ayamura.org/pub/zsh/
  302.     Korea     ftp://linux.sarang.net/mirror/system/shell/zsh/
  303.     Netherlands ftp://ftp.demon.nl/pub/mirrors/zsh/
  304.     Norway    ftp://ftp.uit.no/pub/unix/shells/zsh/
  305.     Poland    ftp://sunsite.icm.edu.pl/pub/unix/shells/zsh/
  306.     Romania   ftp://ftp.roedu.net/pub/mirrors/ftp.zsh.org/pub/zsh/
  307.               ftp://ftp.kappa.ro/pub/mirrors/ftp.zsh.org/pub/zsh/
  308.     Slovenia  ftp://ftp.siol.net/mirrors/zsh/
  309.     Sweden    ftp://ftp.lysator.liu.se/pub/unix/zsh/
  310.     UK        ftp://ftp.net.lut.ac.uk/zsh/
  311.               (also by FSP at port 21)
  312.               ftp://sunsite.org.uk/packages/zsh/
  313.     USA       ftp://uiarchive.uiuc.edu/mirrors/ftp/ftp.zsh.org/pub/
  314.               ftp://ftp.rge.com/pub/shells/zsh/
  315.               http://zsh.disillusion.org/
  316.               http://foad.org/zsh/
  317.  
  318.   The Windows port mentioned above is maintained separately by Amol
  319.   Deshpande <amold@microsoft.com>; please mail Amol directly about any
  320.   Windows-specific problems.  This is based on 3.0.5, and probably will
  321.   not be developed further.  You can get it from:
  322.  
  323.             ftp://ftp.blarg.net/users/amol/zsh  
  324.  
  325.   There is no port of 4.0 for Windows, but newer releases compile under
  326.   Cygwin, a freely available UNIX-style environment for the Win32 API.  You
  327.   can find information about this at 
  328.   http://sourceware.cygnus.com/cygwin.
  329.  
  330.   Likewise the OS/2 port is available from TAMURA Kent
  331.   <kent@tril.ibm.co.jp> at
  332.  
  333.             http://www.haun.org/kent/tmp/
  334.  
  335.   Starting from mid-October 1997, there is an archive of patches sent
  336.   to the maintainers' mailing list.  Note that these may not all be
  337.   added to the shell, and some may already have been; you simply have
  338.   to search for something you might want which is not in the version
  339.   you have.  Also, there may be some prerequisites earlier in the
  340.   archive.  It can be found on the zsh WWW pages (as described in
  341.   1.1) at:
  342.  
  343.             http://zsh.sunsite.dk/Patches/
  344.  
  345. 1.7: I don't have root access: how do I make zsh my login shell?
  346.  
  347.   Unfortunately, on many machines you can't use `chsh' to change your
  348.   shell unless the name of the shell is contained in /etc/shells, so if
  349.   you have your own copy of zsh you need some sleight-of-hand to use it
  350.   when you log on.  (Simply typing `zsh' is not really a solution since
  351.   you still have your original login shell waiting for when you exit.)
  352.  
  353.   The basic idea is to use `exec <zsh-path>' to replace the current
  354.   shell with zsh.  Often you can do this in a login file such as .profile 
  355.   (if your shell is sh or ksh) or .login (if it's csh).  Make sure you
  356.   have some way of altering the file (e.g. via FTP) before you try this as
  357.   `exec' is often rather unforgiving. 
  358.  
  359.   If you have zsh in a subdirectory `bin' of your home directory,
  360.   put this in .profile:
  361.  
  362.     [ x$ZSH_VERSION = x -a -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
  363.  
  364.   --- the first test is a safeguard to avoid an infinite loop in case
  365.   your zsh is set up to source your .profile, which is quite a common
  366.   trick as you can save a lot of duplication that way.  If your login
  367.   shell is csh or tcsh, put this in .login:
  368.  
  369.     if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
  370.  
  371.   (in each case the `-l' tells zsh it is a login shell).
  372.  
  373.   If you want to check this works before committing yourself to it,
  374.   you can make the login shell ask whether to exec zsh.  The following
  375.   work for Bourne-like shells:
  376.  
  377.     [ -f $HOME/bin/zsh ] && {
  378.             echo "Type Y to run zsh: \c"
  379.             read line
  380.             [ "$line" = Y ] && exec $HOME/bin/zsh -l
  381.     }
  382.  
  383.   and for C-shell-like shells:
  384.  
  385.     if ( -f ~/bin/zsh ) then
  386.             echo -n "Type Y to run zsh: "
  387.             if ( "$<" == Y ) exec ~/bin/zsh -l
  388.     endif
  389.  
  390.   It's not a good idea to put this (even without the -l) into .cshrc,
  391.   at least without some tests on what the csh is supposed to be doing,
  392.   as that will cause _every_ instance of csh to turn into a zsh and
  393.   will cause csh scripts (yes, unfortunately some people write these)
  394.   which do not call `csh -f' to fail.  If you want to tell xterm to
  395.   run zsh, change the SHELL environment variable to the full path of
  396.   zsh at the same time as you exec zsh (in fact, this is sensible for
  397.   consistency even if you aren't using xterm).  If you have to exec
  398.   zsh from your .cshrc, a minimum safety check is `if ($?prompt) exec
  399.   zsh'.
  400.  
  401.   If you like your login shell to appear in the process list as `-zsh',
  402.   you can link `zsh' to `-zsh' (e.g. by `ln -s ~/bin/zsh 
  403.   ~/bin/-zsh') and change the exec to `exec -zsh'.  (Make sure
  404.   `-zsh' is in your path.) This has the same effect as the `-l'
  405.   option. 
  406.  
  407.   There was a thread on this topic on the zsh-workers mailing list,
  408.   starting from item 15747.  You can find this at http://www.zsh.org/mla/.
  409.  
  410.   Footnote: if you DO have root access, make sure zsh goes in
  411.   /etc/shells on all appropriate machines, including NIS clients, or you
  412.   may have problems with FTP to that machine.
  413.  
  414. Chapter 2: How does zsh differ from...?
  415.  
  416. As has already been mentioned, zsh is most similar to ksh, while many
  417. of the additions are to please csh users.  Here are some more detailed
  418. notes.  See also the article `UNIX shell differences and how to change
  419. your shell' posted frequently to the USENET group comp.unix.shell.
  420.  
  421. 2.1: Differences from sh and ksh
  422.  
  423.   (The following refers to shell options extensively.  To turn an
  424.   option on in zsh you use `setopt var(optionname)', and to turn
  425.   it off you use `unsetopt var(optionname)'.  The option name is
  426.   case insensitive and underscores are ignored.  If you are used to ksh,
  427.   that syntax works too.)
  428.  
  429.   Most features of ksh (and hence also of sh) are implemented in zsh;
  430.   problems can arise because the implementation is slightly different.
  431.   Note also that not all ksh's are the same either.  I have based this
  432.   on the 11/16/88f version of ksh; differences from ksh93 will be more
  433.   substantial.
  434.  
  435.   As a summary of the status:
  436.  
  437.   1) because of all the options it is not safe to assume a general
  438.      zsh run by a user will behave as if sh or ksh compatible;
  439.   2) invoking zsh as sh or ksh (or if either is a symbolic link to
  440.      zsh) sets appropriate options and improves compatibility (from
  441.      within zsh itself, calling `ARGV0=sh zsh' will also work);
  442.   3) from version 3.0 onward the degree of compatibility with sh
  443.      under these circumstances is very high:  zsh can now be used
  444.      with GNU configure or perl's Configure, for example;
  445.   4) the degree of compatibility with ksh is also high, but a few
  446.      things are missing:  for example the more sophisticated
  447.      pattern-matching expressions are different for versions before
  448.      3.1.3 --- see the detailed list below;
  449.   5) also from 3.0, the command `emulate' is available: `emulate
  450.      ksh' and `emulate sh' set various options as well as changing the
  451.      effect of single-letter option flags as if the shell had been
  452.      invoked with the appropriate name.  Including the command
  453.      `emulate sh; setopt localoptions' in a shell function will
  454.      turn on sh emulation for that function only.  In 4.0 (and in
  455.      3.0.6 through 8), this can be abbreviated as `emulate -L sh'.
  456.  
  457.   The classic difference is word splitting, discussed in question 3.1;
  458.   this catches out very many beginning zsh users.  As explained there,
  459.   this is actually a bug in every other shell.  The answer is to set
  460.   SH_WORD_SPLIT for backward compatibility.  The next most classic
  461.   difference is that unmatched glob patterns cause the command to abort;
  462.   set NO_NOMATCH for those.
  463.  
  464.   Here is a list of various options which will increase ksh
  465.   compatibility, though maybe decrease zsh's abilities: see the manual
  466.   entries for GLOB_SUBST, IGNORE_BRACES (though brace expansion occurs
  467.   in some versions of ksh), KSH_ARRAYS, KSH_GLOB, KSH_OPTION_PRINT,
  468.   LOCAL_OPTIONS, NO_BAD_PATTERN, NO_BANG_HIST, NO_EQUALS, NO_HUP,
  469.   NO_NOMATCH, NO_RCS, NO_SHORT_LOOPS, PROMPT_SUBST, RM_STAR_SILENT,
  470.   POSIX_BUILTINS, SH_FILE_EXPANSION, SH_GLOB, SH_OPTION_LETTERS,
  471.   SH_WORD_SPLIT (see question 3.1) and SINGLE_LINE_ZLE.
  472.   Note that you can also disable any built-in commands which get in
  473.   your way.  If invoked as `ksh', the shell will try to set suitable
  474.   options.
  475.  
  476.   Here are some differences from ksh which might prove significant for
  477.   ksh programmers, some of which may be interpreted as bugs; there
  478.   must be more.  Note that this list is deliberately rather full and
  479.   that most of the items are fairly minor.  Those marked `*' perform
  480.   in a ksh-like manner if the shell is invoked with the name `ksh', or
  481.   if `emulate ksh' is in effect.  Capitalised words with underlines
  482.   refer to shell options. 
  483.  
  484.   o  Syntax:
  485.  
  486.     o * Shell word splitting: see question 3.1.
  487.     o * Arrays are (by default) more csh-like than ksh-like:
  488.         subscripts start at 1, not 0; array[0] refers to array[1];
  489.         `$array' refers to the whole array, not $array[0];
  490.         braces are unnecessary: $a[1] == ${a[1]}, etc.
  491.         Set the KSH_ARRAYS option for compatibility.
  492.     o   Coprocesses are established by `coproc'; `|&' behaves like
  493.         csh.  Handling of coprocess file descriptors is also different.
  494.     o   In `cmd1 && cmd2 &', only `cmd2' instead of the whole
  495.         expression is run in the background in zsh.  The manual implies
  496.         this is a bug.  Use `{ cmd1 && cmd2 } &' as a workaround.
  497.  
  498.   o  Command line substitutions, globbing etc.:
  499.  
  500.     o * Failure to match a globbing pattern causes an error (use
  501.         NO_NOMATCH).
  502.     o * The results of parameter substitutions are treated as plain text:
  503.         `foo="*"; print $foo' prints all files in ksh but `*' in zsh
  504.         (uset GLOB_SUBST).
  505.     o * $PSn do not do parameter substitution by default (use PROMPT_SUBST).
  506.     o * Standard globbing does not allow ksh-style `pattern-lists'.
  507.         Equivalents:
  508.  
  509. ----------------------------------------------------------------------
  510.       ksh              zsh         Meaning
  511.      ------           ------       ---------
  512.      !(foo)            ^foo        Anything but foo.
  513.                 or   foo1~foo2     Anything matching foo1 but foo2[1].
  514. @(foo1|foo2|...)  (foo1|foo2|...)  One of foo1 or foo2 or ...
  515.      ?(foo)           (foo|)       Zero or one occurrences of foo.
  516.      *(foo)           (foo)#       Zero or more occurrences of foo.
  517.      +(foo)           (foo)##      One or more occurrences of foo.
  518. ----------------------------------------------------------------------
  519.  
  520.       The `^', `~' and `#' (but not `|')forms require EXTENDED_GLOB.
  521.       From version 3.1.3, the ksh forms are fully supported when the
  522.       option KSH_GLOB is in effect; for previous versions you
  523.       must use the table above.
  524.  
  525.       [1] Note that `~' is the only globbing operator to have a lower
  526.         precedence than `/'.  For example, `**/foo~*bar*' matches any
  527.         file in a subdirectory called `foo', except where `bar'
  528.         occurred somewhere in the path (e.g. `users/barstaff/foo' will
  529.         be excluded by the `~' operator).  As the `**' operator cannot
  530.         be grouped (inside parentheses it is treated as `*'), this is
  531.         the way to exclude some subdirectories from matching a `**'.
  532.     o   Unquoted assignments do file expansion after `:'s (intended for
  533.         PATHs). 
  534.     o   `integer' does not allow `-i'.
  535.     o   `typeset' and `integer' have special behaviour for
  536.         assignments in ksh, but not in zsh.  For example, this doesn't
  537.         work in zsh:
  538.  
  539.           integer k=$(wc -l ~/.zshrc)
  540.  
  541.         because the return value from wc includes leading
  542.         whitespace which causes wordsplitting.  Ksh handles the
  543.         assignment specially as a single word.
  544.  
  545.   o  Command execution:
  546.  
  547.     o * There is no $ENV variable (use /etc/zshrc, ~/.zshrc; 
  548.         note also $ZDOTDIR).
  549.     o   $PATH is not searched for commands specified
  550.         at invocation without -c.
  551.  
  552.   o  Aliases and functions:
  553.  
  554.     o   The order in which aliases and functions are defined is significant:
  555.         function definitions with () expand aliases -- see question 2.3.
  556.     o   Aliases and functions cannot be exported.
  557.     o   There are no tracked aliases: command hashing replaces these.
  558.     o   The use of aliases for key bindings is replaced by `bindkey'.
  559.     o * Options are not local to functions (use LOCAL_OPTIONS; note this
  560.         may always be unset locally to propagate options settings from a
  561.         function to the calling level).
  562.     o   Functions defined with `function funcname { body }' behave the
  563.         same way as those defined with `funcname () { body }'.  In ksh,
  564.         the former behave as if the body were read from a file with `.',
  565.         and only the latter behave as true functions.
  566.  
  567.     o  Traps and signals:
  568.  
  569.     o * Traps are not local to functions.  The option LOCAL_TRAPS is
  570.           available from 3.1.6.
  571.     o   TRAPERR has become TRAPZERR (this was forced by UNICOS which
  572.         has SIGERR).
  573.  
  574.   o  Editing:
  575.  
  576.     o   The options emacs, gmacs, viraw are not supported.
  577.         Use bindkey to change the editing behaviour: `set -o {emacs,vi}'
  578.         becomes `bindkey -{e,v}'; for gmacs, go to emacs mode and use
  579.         `bindkey \^t gosmacs-transpose-characters'.
  580.     o   The `keyword' option does not exist and `-k' is instead
  581.         interactivecomments.  (`keyword' will not be in the next ksh
  582.         release either.)
  583.     o * Management of histories in multiple shells is different:
  584.         the history list is not saved and restored after each command.
  585.         The option SHARE_HISTORY appeared in 3.1.6 and is set in ksh
  586.         compatibility mode to remedy this.
  587.     o   `\' does not escape editing chars (use `^V').
  588.     o   Not all ksh bindings are set (e.g. `<ESC>#'; try `<ESC>q').
  589.     o * `#' in an interactive shell is not treated as a comment by
  590.         default. 
  591.  
  592.   o  Built-in commands:
  593.  
  594.     o   Some built-ins (r, autoload, history, integer ...)
  595.         were aliases in ksh. 
  596.     o   There is no built-in command newgrp: use e.g. `alias
  597.         newgrp="exec newgrp"'
  598.     o   `jobs' has no `-n' flag.
  599.     o   `read' has no `-s' flag.
  600.  
  601.   o  Other idiosyncrasies:
  602.  
  603.     o   `select' always redisplays the list of selections on each loop.
  604.  
  605. 2.2: Similarities with csh
  606.  
  607.   Although certain features aim to ease the withdrawal symptoms of csh
  608.   (ab)users, the syntax is in general rather different and you should
  609.   certainly not try to run scripts without modification.  The c2z script
  610.   is provided with the source (in Misc/c2z) to help convert .cshrc
  611.   and .login files; see also the next question concerning aliases,
  612.   particularly those with arguments.
  613.  
  614.   Csh-compatibility additions include:
  615.  
  616.   o   logout, rehash, source, (un)limit built-in commands.
  617.   o   *rc file for interactive shells.
  618.   o   Directory stacks.
  619.   o   cshjunkie*, ignoreeof options.
  620.   o   The CSH_NULL_GLOB option.
  621.   o   >&, |& etc. redirection.
  622.       (Note that `>file 2>&1' is the standard Bourne shell command for
  623.       csh's `>&file'.)
  624.   o   foreach ... loops; alternative syntax for other loops.
  625.   o   Alternative syntax `if ( ... ) ...', though this still doesn't
  626.       work like csh: it expects a command in the parentheses.  Also
  627.       `for', `which'.
  628.   o   $PROMPT as well as $PS1, $status as well as $?,
  629.       $#argv as well as $#, .... 
  630.   o   Escape sequences via % for prompts.
  631.   o   Special array variables $PATH etc. are colon-separated, $path
  632.       are arrays.
  633.   o   !-type history (which may be turned off via `setopt
  634.       nobanghist').
  635.   o   Arrays have csh-like features (see under 2.1).
  636.  
  637. 2.3: Why do my csh aliases not work?  (Plus other alias pitfalls.)
  638.  
  639.   First of all, check you are using the syntax
  640.  
  641.     alias newcmd='list of commands'
  642.  
  643.   and not
  644.  
  645.     alias newcmd 'list of commands'
  646.  
  647.   which won't work. (It tells you if `newcmd' and `list of commands' are
  648.   already defined as aliases.)
  649.  
  650.   Otherwise, your aliases probably contain references to the command
  651.   line of the form `\!*', etc.  Zsh does not handle this behaviour as it
  652.   has shell functions which provide a way of solving this problem more
  653.   consistent with other forms of argument handling.  For example, the
  654.   csh alias
  655.  
  656.     alias cd 'cd \!*; echo $cwd'
  657.  
  658.   can be replaced by the zsh function,
  659.  
  660.     cd() { builtin cd "$@"; echo $PWD; }
  661.  
  662.   (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop)
  663.   or, perhaps better,
  664.  
  665.     cd() { builtin cd "$@"; print -D $PWD; }
  666.  
  667.   (which converts your home directory to a ~).  In fact, this problem is
  668.   better solved by defining the special function chpwd() (see the manual).
  669.   Note also that the `;' at the end of the function is optional in zsh,
  670.   but not in ksh or sh (for sh's where it exists).
  671.  
  672.   Here is Bart Schaefer's guide to converting csh aliases for zsh.
  673.  
  674.   1) If the csh alias references "parameters" (\!:1, \!* etc.),
  675.      then in zsh you need a function (referencing $1, $* etc.).
  676.      Otherwise, you can use a zsh alias.
  677.  
  678.   2) If you use a zsh function, you need to refer _at_least_ to
  679.      $* in the body (inside the { }).  Parameters don't magically
  680.      appear inside the { } the way they get appended to an alias.
  681.  
  682.   3) If the csh alias references its own name (alias rm "rm -i"),
  683.      then in a zsh function you need the "command" keyword
  684.      (function rm() { command rm -i "$@" }), but in a zsh alias
  685.      you don't (alias rm="rm -i").
  686.  
  687.   4) If you have aliases that refer to each other (alias ls "ls -C";
  688.      alias lf "ls -F" ==> lf == ls -C -F) then you must either:
  689.  
  690.         o  convert all of them to zsh functions; or
  691.         o  after converting, be sure your .zshrc defines all of your
  692.            aliases before it defines any of your functions.
  693.  
  694.      Those first four are all you really need, but here are four more for
  695.      heavy csh alias junkies:
  696.  
  697.   5) Mapping from csh alias "parameter referencing" into zsh function
  698.      (assuming SH_WORD_SPLIT and KSH_ARRAYS are NOT set in zsh):
  699.  
  700.       csh             zsh
  701.      =====         ==========
  702.      \!*           $*              (or $argv)
  703.      \!^           $1              (or $argv[1])
  704.      \!:1          $1
  705.      \!:2          $2              (or $argv[2], etc.)
  706.      \!$           $*[$#]          (or $argv[$#], or $*[-1])
  707.      \!:1-4        $*[1,4]
  708.      \!:1-         $*[1,$#-1]      (or $*[1,-2])
  709.      \!^-          $*[1,$#-1]
  710.      \!*:q         "$@"
  711.      \!*:x         $=*             ($*:x doesn't work (yet))
  712.  
  713.   6) Remember that it is NOT a syntax error in a zsh function to
  714.      refer to a position ($1, $2, etc.) greater than the number of
  715.      parameters. (E.g., in a csh alias, a reference to \!:5 will
  716.      cause an error if 4 or fewer arguments are given; in a zsh
  717.      function, $5 is the empty string if there are 4 or fewer
  718.      parameters.)
  719.  
  720.   7) To begin a zsh alias with a - (dash, hyphen) character, use
  721.      `alias --':
  722.  
  723.              csh                            zsh
  724.         ===============             ==================
  725.         alias - "fg %-"             alias -- -="fg %-"
  726.  
  727.   8) Stay away from `alias -g' in zsh until you REALLY know what
  728.      you're doing.
  729.  
  730.   There is one other serious problem with aliases: consider
  731.  
  732.     alias l='/bin/ls -F'
  733.     l() { /bin/ls -la "$@" | more }
  734.  
  735.   `l' in the function definition is in command position and is expanded
  736.   as an alias, defining `/bin/ls' and `-F' as functions which call
  737.   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  738.   `function' to define a function, which doesn't expand aliases.  It is
  739.   possible to argue for extra warnings somewhere in this mess.
  740.  
  741.   Earlier versions of the FAQ claimed `it is not possible to define
  742.   `function' as an alias'.  This turns out to be false; you can even
  743.   confuse yourself this way.  The point to remember is that aliases are
  744.   quite deliberately a way of subverting the shell's syntax for special
  745.   effects.  If you wish to be completely safe, you should stick with
  746.   functions.
  747.  
  748.   Bart Schaefer's rule is:  Define first those aliases you expect to
  749.   use in the body of a function, but define the function first if the
  750.   alias has the same name as the function.
  751.  
  752. 2.4: Similarities with tcsh
  753.  
  754.   (The sections on csh apply too, of course.)  Certain features have
  755.   been borrowed from tcsh, including $watch, run-help, $savehist,
  756.   periodic commands etc., extended prompts, sched and which built-ins.
  757.   Programmable completion was inspired by, but is entirely different to,
  758.   tcsh's `complete'.  (There is a perl script called lete2ctl in the
  759.   Misc directory of the source distribution to convert `complete' to `compctl'
  760.   statements.)  This list is not definitive: some features have gone in
  761.   the other direction.
  762.  
  763.   If you're missing the editor function run-fg-editor, try something
  764.   with `bindkey -s' (which binds a string to a keystroke), e.g.
  765.  
  766.     bindkey -s '^z' '\eqfg %$EDITOR:t\n'
  767.  
  768.   which pushes the current line onto the stack and tries to bring a job
  769.   with the basename of your editor into the foreground.  `bindkey -s'
  770.   allows limitless possibilities along these lines.  You can execute
  771.   any command in the middle of editing a line in the same way,
  772.   corresponding to tcsh's `-c' option:
  773.  
  774.     bindkey -s '^p' '\eqpwd\n'
  775.  
  776.   In both these examples, the `\eq' saves the current input line to
  777.   be restored after the command runs; a better effect with multiline
  778.   buffers is achieved if you also have
  779.  
  780.     bindkey '\eq' push-input
  781.  
  782.   to save the entire buffer.  In 4.0 and recent versions of zsh 3.1, you
  783.   have the following more sophisticated option,
  784.  
  785.     run-fg-editor() {
  786.       zle push-input
  787.       BUFFER="fg %$EDITOR:t"
  788.       zle accept-line
  789.     }
  790.     zle -N run-fg-editor
  791.  
  792.   and can now bind run-fg-editor just like any other editor function.
  793.  
  794. 2.5: Similarities with bash
  795.  
  796.   The Bourne-Again Shell, bash, is another enhanced Bourne-like shell;
  797.   the most obvious difference from zsh is that it does not attempt to
  798.   emulate the Korn shell.  Since both shells are under active
  799.   development it is probably not sensible to be too specific here.
  800.   Broadly, bash has paid more attention to standards compliancy
  801.   (i.e. POSIX) for longer, and has so far avoided the more abstruse
  802.   interactive features (programmable completion, etc.) that zsh has.
  803.  
  804.   In recent years there has been a certain amount of crossover in the
  805.   extensions, however.  Zsh (as of 3.1.6) has bash's `${var/old/new}'
  806.   feature for replacing the text old with the text new in the
  807.   parameter $var.  Note one difference here:  while both shells
  808.   implement the syntax `${var/#old/new}' and `${var/%old/new}' for
  809.   anchoring the match of old to the start or end of the parameter text,
  810.   respectively, in zsh you can't put the `#' or `%' inside a
  811.   parameter:  in other words `{var/$old/new}' where old begins with
  812.   a `#' treats that as an ordinary character in zsh, unlike bash.  To
  813.   do this sort of thing in zsh you can use (from 3.1.7) the new syntax
  814.   for anchors in any pattern, `(#s)' to match the start of a string,
  815.   and `(#e)' to match the end.  These require the option
  816.   EXTENDED_GLOB to be set.
  817.  
  818. 2.6: Shouldn't zsh be more/less like ksh/(t)csh?
  819.  
  820.   People often ask why zsh has all these `unnecessary' csh-like features,
  821.   or alternatively why zsh doesn't understand more csh syntax.  This is
  822.   far from a definitive answer and the debate will no doubt continue.
  823.  
  824.   Paul's object in writing zsh was to produce a ksh-like shell which
  825.   would have features familiar to csh users.  For a long time, csh was
  826.   the preferred interactive shell and there is a strong resistance to
  827.   changing to something unfamiliar, hence the additional syntax and
  828.   CSH_JUNKIE options.  This argument still holds.  On the other hand,
  829.   the arguments for having what is close to a plug-in replacement for ksh
  830.   are, if anything, even more powerful:  the deficiencies of csh as a
  831.   programming language are well known (look in any Usenet FAQ archive, e.g.
  832.     http://www.cis.ohio-state.edu/hypertext/faq/usenet/unix-faq/\ 
  833.         shell/csh-whynot/faq.html
  834.   if you are in any doubt) and zsh is able to run many standard
  835.   scripts such as /etc/rc.
  836.  
  837.   Of course, this makes zsh rather large and feature-ridden so that it
  838.   seems to appeal mainly to hackers.  The only answer, perhaps not
  839.   entirely satisfactory, is that you have to ignore the bits you don't
  840.   want.  The introduction of loadable in modules in version 3.1 should
  841.   help.
  842.  
  843. Chapter 3: How to get various things to work
  844.  
  845. 3.1: Why does `$var' where `var="foo bar"' not do what I expect?
  846.  
  847.   In most Bourne-shell derivatives, multiple-word variables such as
  848.  
  849.     var="foo bar"
  850.  
  851.   are split into words when passed to a command or used in a `for foo in
  852.   $var' loop.  By default, zsh does not have that behaviour: the
  853.   variable remains intact.  (This is not a bug!  See below.)  The option
  854.   SH_WORD_SPLIT exists to provide compatibility.
  855.  
  856.   For example, defining the function args to show the number of its
  857.   arguments:
  858.  
  859.     args() { echo $#; }
  860.  
  861.   and with our definition of `var',
  862.  
  863.     args $var
  864.  
  865.   produces the output `1'.  After
  866.  
  867.     setopt shwordsplit
  868.  
  869.   the same function produces the output `2', as with sh and ksh.
  870.  
  871.   Unless you need strict sh/ksh compatibility, you should ask yourself
  872.   whether you really want this behaviour, as it can produce unexpected
  873.   effects for variables with entirely innocuous embedded spaces.  This
  874.   can cause horrendous quoting problems when invoking scripts from
  875.   other shells.  The natural way to produce word-splitting behaviour
  876.   in zsh is via arrays.  For example,
  877.  
  878.     set -A array one two three twenty
  879.  
  880.   (or
  881.  
  882.     array=(one two three twenty)
  883.  
  884.   if you prefer), followed by
  885.  
  886.     args $array
  887.  
  888.   produces the output `4', regardless of the setting of SH_WORD_SPLIT.
  889.   Arrays are also much more versatile than single strings.  Probably
  890.   if this mechanism had always been available there would never have
  891.   been automatic word splitting in scalars, which is a sort of
  892.   uncontrollable poor man's array.
  893.  
  894.   Note that this happens regardless of the value of the internal field
  895.   separator, $IFS; in other words, with `IFS=:; foo=a:b; args $foo'
  896.   you get the answer 1.
  897.  
  898.   Other ways of causing word splitting include a judicious use of
  899.   `eval':
  900.  
  901.     sentence="Longtemps, je me suis couch\\'e de bonne heure."
  902.     eval "words=($sentence)"
  903.  
  904.   after which $words is an array with the words of $sentence (note
  905.   characters special to the shell, such as the `'' in this example,
  906.   must already be quoted), or, less standard but more reliable,
  907.   turning on SH_WORD_SPLIT for one variable only:
  908.  
  909.     args ${=sentence}
  910.  
  911.   always returns 8 with the above definition of `args'.  (In older
  912.   versions of zsh, ${=foo} toggled SH_WORD_SPLIT; now it forces it on.)
  913.  
  914.   Note also the "$@" method of word splitting is always available in zsh
  915.   functions and scripts (though strictly this does array splitting, not
  916.   word splitting).  This is more portable than the $*, since it
  917.   will work regardless of the SH_WORD_SPLIT setting; the other
  918.   difference is that $* removes empty arguments from the array.
  919.   You can fix the first half of that objection by using ${==*},
  920.   which turns off SH_WORD_SPLIT for the duration of the expansion.
  921.  
  922.   SH_WORD_SPLIT is set when zsh is invoked with the names `ksh' or `sh',
  923.   or (entirely equivalent) when `emulate ksh' or `emulate sh' is in
  924.   effect.
  925.  
  926.   There is one other effect of word splitting which differs between ksh
  927.   and zsh.  In ksh, the builtin commands that declare parameters such
  928.   as typeset and export force word-splitting not to take place
  929.   after on an assignment argument:
  930.  
  931.     typeset param=`echo foo bar`
  932.  
  933.   in ksh will create a parameter with value `foo bar', but in zsh will
  934.   create a parameter param with value foo and a parameter bar
  935.   whose value is empty.  Contrast this with a normal assignment (no
  936.   typeset or other command in front), which never causes a word split
  937.   unless you have GLOB_ASSIGN set.  From zsh version 4.0.2 the option
  938.   KSH_TYPESET, set automatically in compatibility mode, fixes this
  939.   problem.  Note that in bash this behaviour occurs with all arguments that
  940.   look like assignments, whatever the command name; to get this behaviour
  941.   in zsh you have to set the option MAGIC_EQUAL_SUBST.
  942.  
  943. 3.2: In which startup file do I put...?
  944.  
  945.   When zsh starts up, there are four files you can change which it will
  946.   run under various circumstances: .zshenv, .zprofile, .zshrc
  947.   and .zlogin.  They are usually in your home directory, but the
  948.   variable $ZDOTDIR may be set to alter that.  Here are a few simple
  949.   hints about how to use them.  There are also files which the system
  950.   administrator can set for all shells; you can avoid running all except
  951.   /etc/zshenv by starting zsh with the -f option --- for this
  952.   reason it is important for administrators to make sure /etc/zshenv
  953.   is as brief as possible.
  954.  
  955.   The order in which the four files are searched (none of them _need_
  956.   to exist) is the one just given.  However, .zprofile and .zlogin
  957.   are only run when the shell is a login shell --- when you first login,
  958.   of course, and whenever you start zsh with the -l option.  All
  959.   login shells are interactive.  The order is the only difference
  960.   between those; you should decide whether you need things set before or
  961.   after .zshrc.  These files are a good place to set environment
  962.   variables (i.e. `export' commands), since they are passed on to
  963.   all shells without you having to set them again, and also to check
  964.   that your terminal is set up properly (except that if you want to
  965.   change settings for terminal emulator windows like xterm you will
  966.   need to put those in .zshrc, since usually you do not get a login
  967.   shell here).  
  968.  
  969.   The only file you can alter which is started with every zsh (unless
  970.   you use the -f option) is .zshenv, so this is a good place to put
  971.   things you want even if the shell is non-interactive: options for
  972.   changing the syntax, like EXTENDED_GLOB, any changes to set with
  973.   `limit', any more variables you want to make sure are set as for
  974.   example $fpath to find functions.  You almost certainly do not
  975.   want .zshenv to produce any output.  Some people prefer not to
  976.   use .zshenv for setting options, as this affects scripts; but
  977.   making zsh scripts portable usually requires special handling anyway.
  978.  
  979.   Finally, .zshrc is run for every interactive shell; that includes
  980.   login shells, but also any other time you start up a shell, such as
  981.   simply by typing `zsh' or opening a new terminal emulator window.
  982.   This file is the place to change the editing behaviour via options or
  983.   `bindkey', control how your history is saved, set aliases unless
  984.   you want to use them in scripts too, and for any other clutter which
  985.   can't be exported but you only use when interacting directly with the
  986.   shell.  You probably don't want .zshrc to produce output, either,
  987.   since there are occasions when this can be a problem, such as when
  988.   using `rsh' from another host.  See 3.21 for what to put in .zshrc
  989.   to save your history.
  990.  
  991. 3.3: What is the difference between `export' and the ALL_EXPORT option?
  992.  
  993.   Normally, you would put a variable into the environment by using
  994.   `export var'.  The command `setopt allexport' causes all
  995.   variables which are subsequently set (N.B. not all the ones which
  996.   already exist) to be put into the environment.
  997.  
  998.   This may seem a useful shorthand, but in practice it can have
  999.   unhelpful side effects:
  1000.  
  1001.   1) Since every variable is in the environment as well as remembered
  1002.      by the shell, the memory for it needs to be allocated twice.
  1003.      This is bigger as well as slower.
  1004.   2) It really is *every* variable which is exported, even loop
  1005.      variables in `for' loops.  This is probably a waste.
  1006.   3) An arbitrary variable created by the user might have a special
  1007.      meaning to a command.  Since all shell variables are visible to
  1008.      commands, there is no protection against this.
  1009.  
  1010.   For these reasons it is usually best to avoid ALL_EXPORT unless you
  1011.   have a specific use for it.  One safe use is to set it before
  1012.   creating a list of variables in an initialisation file, then unset
  1013.   it immediately afterwards.  Only those variables will be automatically
  1014.   exported.
  1015.  
  1016. 3.4: How do I turn off spelling correction/globbing for a single command?
  1017.  
  1018.   In the first case, you presumably have `setopt correctall' in an
  1019.   initialisation file, so that zsh checks the spelling of each word in
  1020.   the command line.  You probably do not want this behaviour for
  1021.   commands which do not operate on existing files.
  1022.  
  1023.   The answer is to alias the offending command to itself with
  1024.   `nocorrect' stuck on the front, e.g.
  1025.  
  1026.     alias mkdir='nocorrect mkdir'
  1027.  
  1028.   To turn off globbing, the rationale is identical:
  1029.  
  1030.     alias mkdir='noglob mkdir'
  1031.  
  1032.   You can have both nocorrect and noglob, if you like, but the
  1033.   nocorrect must come first, since it is needed by the line editor,
  1034.   while noglob is only handled when the command is examined.
  1035.  
  1036.   Note also that a shell function won't work: the no... directives must
  1037.   be expanded before the rest of the command line is parsed.
  1038.  
  1039. 3.5: How do I get the meta key to work on my xterm?
  1040.  
  1041.   As stated in the manual, zsh needs to be told about the meta key by
  1042.   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the
  1043.   command line.  You probably also need to tell the terminal driver to
  1044.   allow the `meta' bit of the character through; `stty pass8' is the
  1045.   usual incantation.  Sample .zshrc entry:
  1046.  
  1047.     [[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
  1048.  
  1049.   or, on SYSVR4-ish systems without pass8,
  1050.  
  1051.     [[ $TERM = "xterm" ]] && stty -parenb -istrip cs8 && bindkey -me
  1052.  
  1053.   (disable parity detection, don't strip high bit, use 8-bit characters).
  1054.   Make sure this comes _before_ any bindkey entries in your .zshrc which
  1055.   redefine keys normally defined in the emacs/vi keymap.  You may also
  1056.   need to set the eightBitOutput resource in your ~/.Xdefaults
  1057.   file, although this is on by default and it's unlikely anybody will
  1058.   have tinkered with it.
  1059.  
  1060.   You don't need the `bindkey' to be able to define your own sequences
  1061.   with the meta key, though you still need the `stty'.
  1062.  
  1063. 3.6: How do I automatically display the directory in my xterm title bar?
  1064.  
  1065.   You should use the special function `chpwd', which is called when
  1066.   the directory changes.  The following checks that standard output is
  1067.   a terminal, then puts the directory in the title bar if the terminal
  1068.   is an xterm or some close relative, or a sun-cmd.
  1069.  
  1070.   chpwd() {
  1071.     [[ -t 1 ]] || return
  1072.     case $TERM in
  1073.       sun-cmd) print -Pn "\e]l%~\e\\"
  1074.         ;;
  1075.       *xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;%~\a"
  1076.         ;;
  1077.     esac
  1078.   }
  1079.  
  1080.   Change `%~' if you want the message to be different.  (The `-P'
  1081.   option interprets such sequences just like in prompts, in this case
  1082.   producing the current directory; you can of course use `$PWD' here,
  1083.   but that won't use the `~' notation which I find clearer.)  Note that
  1084.   when the xterm starts up you will probably want to call chpwd
  1085.   directly: just put `chpwd' in .zshrc after it is defined or autoloaded.
  1086.  
  1087. 3.7: How do I make the completion list use eight bit characters?
  1088.  
  1089.   If you are sure your terminal handles this, the easiest way from versions
  1090.   3.0.6 and 3.1 of the shell is to set the option PRINT_EIGHT_BIT.  In
  1091.   principle, this will work automatically if your computer uses the
  1092.   `locale' system and your locale variables are set properly, as zsh
  1093.   understands this.  However, it is quite complicated, so if it isn't
  1094.   already set up, trying the option is a lot easier.  For earlier versions
  1095.   of zsh 3, you are stuck with trying to understand locales, see the
  1096.   setlocale(3) and zshparam(1) manual pages: the simplest
  1097.   possibility may be to set LC_ALL=en_US.  For older versions of the
  1098.   shell, there is no easy way out.
  1099.  
  1100. 3.8: Why do the cursor (arrow) keys not work?
  1101.  
  1102.   The cursor keys send different codes depending on the terminal; zsh
  1103.   only binds the most well known versions.  If you see these problems,
  1104.   try putting the following in your .zshrc:
  1105.  
  1106.     bindkey "$(echotc kl)" backward-char
  1107.     bindkey "$(echotc kr)" forward-char
  1108.     bindkey "$(echotc ku)" up-line-or-history
  1109.     bindkey "$(echotc kd)" down-line-or-history
  1110.  
  1111.   If you use vi mode, use `vi-backward-char' and `vi-forward-char'
  1112.   where appropriate.  As of version 4.0.1, zsh attempts to look up these
  1113.   codes and to set the key bindings for you (both emacs and vi), but in
  1114.   some circumstances this may not work.
  1115.  
  1116.   Note, however, that up to version 3.0 binding arbitrary multiple key
  1117.   sequences can cause problems, so check that this works with your set
  1118.   up first.  Also, from version 3.1.3, more sequences are supported by
  1119.   default, namely those in the form `<ESC>O' followed by A,
  1120.   B, C or D, as well as the corresponding set beginning
  1121.   `<ESC>[', so this may be redundant.
  1122.  
  1123.   A particular problem which sometimes occurs is that there are two
  1124.   different modes for arrow keys, normal mode and keypad mode, which
  1125.   send different sequences.  Although this is largely a historical
  1126.   artifact, it sometimes happens that your terminal can be switched from
  1127.   one mode to the other, for example by a rogue programme that sends the
  1128.   sequence to switch one way, but not the sequence to switch back.  Thus
  1129.   you are stuck with the effects.  Luckily in this case the arrow key
  1130.   sequences are likely to be standard, and you can simply bind both sets.
  1131.   The following code does this.
  1132.  
  1133.     bindkey '\e[A'  up-line-or-history
  1134.     bindkey '\e[B'  down-line-or-history
  1135.     bindkey '\e[C'  forward-char
  1136.     bindkey '\e[D'  backward-char
  1137.     bindkey '\eOA'  up-line-or-history
  1138.     bindkey '\eOB'  down-line-or-history
  1139.     bindkey '\eOC'  forward-char
  1140.     bindkey '\eOD'  backward-char
  1141.  
  1142.   For most even vaguely VT100-compatible terminals, the above eight
  1143.   instructions are a fairly safe bet for your .zshrc.  Of course
  1144.   you can substitute variant functions for the second argument here too.
  1145.  
  1146. 3.9: Why does my terminal act funny in some way?
  1147.  
  1148.   If you are using an OpenWindows cmdtool as your terminal, any
  1149.   escape sequences (such as those produced by cursor keys) will be
  1150.   swallowed up and never reach zsh.  Either use shelltool or avoid
  1151.   commands with escape sequences.  You can also disable scrolling from
  1152.   the cmdtool pane menu (which effectively turns it into a shelltool).
  1153.   If you still want scrolling, try using an xterm with the scrollbar
  1154.   activated.
  1155.  
  1156.   If that's not the problem, and you are using stty to change some tty
  1157.   settings, make sure you haven't asked zsh to freeze the tty settings:
  1158.   type
  1159.  
  1160.     ttyctl -u
  1161.  
  1162.   before any stty commands you use.
  1163.  
  1164.   On the other hand, if you aren't using stty and have problems you may
  1165.   need the opposite:  `ttyctl -f' freezes the terminal to protect it
  1166.   from hiccups introduced by other programmes (kermit has been known to
  1167.   do this).
  1168.  
  1169.   A problem I have experienced myself (on an AIX 3.2 workstation with
  1170.   xterm) is that termcap deinitialization sequences sent by `less'
  1171.   were causing automargins to be turned off --- not actually a shell
  1172.   problem, but you might have thought it was.  The fix is to put `X'
  1173.   into the environment variable LESS to stop the sequences being sent.
  1174.   Other programs (though not zsh) may also send that sequence.
  1175.  
  1176.   If _that_'s not the problem, and you are having difficulties with
  1177.   external commands (not part of zsh), and you think some terminal
  1178.   setting is wrong (e.g. ^V is getting interpreted as `literal next
  1179.   character' when you don't want it to be), try
  1180.  
  1181.     ttyctl -u
  1182.     STTY='lnext "^-"' commandname
  1183.  
  1184.   (in this example).  Note that zsh doesn't reset the terminal completely
  1185.   afterwards: just the modes it uses itself and a number of special
  1186.   processing characters (see the stty(1) manual page).
  1187.  
  1188. 3.10: Why does zsh not work in an Emacs shell mode any more?
  1189.  
  1190.   (This information comes from Bart Schaefer and other zsh-workers.)
  1191.  
  1192.   Emacs 19.29 or thereabouts stopped using a terminal type of "emacs"
  1193.   in shell buffers, and instead sets it to "dumb".  Zsh only kicks in
  1194.   its special I'm-inside-emacs initialization when the terminal type
  1195.   is "emacs".
  1196.  
  1197.   Probably the most reliable way of dealing with this is to look for
  1198.   the environment variable `$EMACS', which is set to `t' in
  1199.   Emacs' shell mode.  Putting
  1200.  
  1201.     [[ $EMACS = t ]] && unsetopt zle
  1202.  
  1203.   in your .zshrc should be sufficient.
  1204.  
  1205.   Another method is to put
  1206.  
  1207.     #!/bin/sh
  1208.     TERM=emacs exec zsh
  1209.  
  1210.   into a file ~/bin/eshell, then `chmod +x ~/bin/eshell', and
  1211.   tell emacs to use that as the shell by adding
  1212.  
  1213.     (setenv "ESHELL" (expand-file-name "~/bin/eshell"))
  1214.  
  1215.   to ~/.emacs.
  1216.  
  1217. 3.11: Why do my autoloaded functions not autoload [the first time]?
  1218.  
  1219.   The problem is that there are two possible ways of autoloading a
  1220.   function (see the AUTOLOADING FUNCTIONS section of the zsh manual
  1221.   page zshmisc for more detailed information):
  1222.  
  1223.   1) The file contains just the body of the function, i.e.
  1224.      there should be no line at the beginning saying `function foo {'
  1225.      or `foo () {', and consequently no matching `}' at the end.
  1226.      This is the traditional zsh method.  The advantage is that the
  1227.      file is called exactly like a script, so can double as both.
  1228.      To define a function `xhead () { print -n "\033]2;$*\a"; }',
  1229.      the file would just contain `print -n "\033]2;$*\a"'.  
  1230.   2) The file contains the entire definition, and maybe even
  1231.      other code:  it is run when the function needs to be loaded, then
  1232.      the function itself is called up.  This is the method in ksh.
  1233.      To define the same function `xhead', the whole of the
  1234.      usual definition should be in the file.
  1235.  
  1236.   In old versions of zsh, before 3.0, only the first behaviour was
  1237.   allowed, so you had to make sure the file found for autoload just
  1238.   contained the function body.  You could still define other functions
  1239.   in the file with the standard form for definitions, though they
  1240.   would be redefined each time you called the main function.
  1241.  
  1242.   In version 3.0.x, the second behaviour is activated if the file
  1243.   defines the autoloaded function.  Unfortunately, this is
  1244.   incompatible with the old zsh behaviour which allowed you to
  1245.   redefine the function when you called it.
  1246.  
  1247.   From version 3.1, there is an option KSH_AUTOLOAD to allow full ksh
  1248.   compatiblity, i.e. the function _must_ be in the second form
  1249.   above.  If that is not set, zsh tries to guess which form you are
  1250.   using:  if the file contains only a complete definition of the
  1251.   function in the second form, and nothing else apart from comments
  1252.   and whitespace, it will use the function defined in the file;
  1253.   otherwise, it will assume the old behaviour.  The option is set
  1254.   if `emulate ksh' is in effect, of course.
  1255.  
  1256.   (A neat trick to autoload all functions in a given directory is to
  1257.   include a line like `autoload ~/fns/*(:t)' in .zshrc; the bit in
  1258.   parentheses removes the directory part of the filenames, leaving
  1259.   just the function names.)
  1260.  
  1261. 3.12: How does base arithmetic work?
  1262.  
  1263.   The ksh syntax is now understood, i.e.
  1264.  
  1265.     let 'foo = 16#ff'
  1266.  
  1267.   or equivalently
  1268.  
  1269.     (( foo = 16#ff ))
  1270.  
  1271.   or even
  1272.  
  1273.     foo=$((16#ff))
  1274.  
  1275.   The original syntax was
  1276.  
  1277.     (( foo = [16]ff ))
  1278.  
  1279.   --- this was based on a misunderstanding of the ksh manual page.  It
  1280.   still works but its use is deprecated.  Then
  1281.  
  1282.     echo $foo
  1283.  
  1284.   gives the answer `255'.  It is possible to declare variables explicitly
  1285.   to be integers, via
  1286.  
  1287.     typeset -i foo
  1288.  
  1289.   which has a different effect: namely the base used in the first
  1290.   assignment (hexadecimal in the example) is subsequently used whenever
  1291.   `foo' is displayed (although the internal representation is unchanged).
  1292.   To ensure foo is always displayed in decimal, declare it as
  1293.  
  1294.     typeset -i 10 foo
  1295.  
  1296.   which requests base 10 for output.  You can change the output base of an
  1297.   existing variable in this fashion.  Using the `$(( ... ))' method will
  1298.   always display in decimal, except that in 3.1.9 there is a new feature
  1299.   for selecting a base for displaying here:
  1300.  
  1301.     print $(( [#16] 255 ))
  1302.  
  1303. 3.13: How do I get a newline in my prompt?
  1304.  
  1305.   You can place a literal newline in quotes, i.e.
  1306.  
  1307.     PROMPT="Hi Joe,
  1308.     what now?%# "
  1309.  
  1310.   If you have the bad taste to set the option cshjunkiequotes, which
  1311.   inhibits such behaviour, you will have to bracket this with
  1312.   `unsetopt cshjunkiequotes' and `setopt cshjunkiequotes', or put it
  1313.   in your .zshrc before the option is set.
  1314.  
  1315.   In recent versions of zsh (not 3.0), there is a form of quoting which
  1316.   interprets print sequences like `\n' but otherwise acts like single
  1317.   quotes: surround the string with $'...'.  Hence:
  1318.  
  1319.     PROMPT=$'Hi Joe,\nwhat now?%# '
  1320.  
  1321.   is a neat way of doing what you want.  Note that it is the quotes, not
  1322.   the prompt expansion, which turns the `\n' into a newline.
  1323.  
  1324. 3.14: Why does `bindkey ^a command-name' or `stty intr ^-' do something funny?
  1325.  
  1326.   You probably have the extendedglob option set in which case ^ and #
  1327.   are metacharacters.  ^a matches any file except one called a, so the
  1328.   line is interpreted as bindkey followed by a list of files.  Quote the
  1329.   ^ with a backslash or put quotation marks around ^a.
  1330.  
  1331. 3.15: Why can't I bind \C-s and \C-q any more?
  1332.  
  1333.   The control-s and control-q keys now do flow control by default,
  1334.   unless you have turned this off with `stty -ixon' or redefined the
  1335.   keys which control it with `stty start' or `stty stop'.  (This is
  1336.   done by the system, not zsh; the shell simply respects these
  1337.   settings.)  In other words, \C-s stops all output to the terminal,
  1338.   while \C-q resumes it.
  1339.  
  1340.   There is an option NO_FLOW_CONTROL to stop zsh from allowing flow
  1341.   control and hence restoring the use of the keys: put `setopt
  1342.   noflowcontrol' in your .zshrc file.
  1343.  
  1344. 3.16: How do I execute command `foo' within function `foo'?
  1345.  
  1346.   The command `command foo' does just that.  You don't need this with
  1347.   aliases, but you do with functions.  Note that error messages like
  1348.  
  1349.     zsh: job table full or recursion limit exceeded
  1350.  
  1351.   are a good sign that you tried calling `foo' in function `foo' without
  1352.   using `command'.  If `foo' is a builtin rather than an external
  1353.   command, use `builtin foo' instead.
  1354.  
  1355. 3.17: Why do history substitutions with single bangs do something funny?
  1356.  
  1357.   If you have a command like "echo !-2:$ !$", the first history
  1358.   substitution then sets a default to which later history substitutions
  1359.   with single unqualified bangs refer, so that !$ becomes equivalent to
  1360.   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
  1361.   to the last command (`setopt cshjunkiehistory' to turn it on).
  1362.  
  1363. 3.18: Why does zsh kill off all my background jobs when I logout?
  1364.  
  1365.   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
  1366.   you the option of having background jobs killed or not: `setopt nohup'
  1367.   if you don't want them killed.  Note that you can always
  1368.   run programs with `nohup' in front of the pipeline whether or not the
  1369.   option is set, which will prevent that job from being killed on
  1370.   logout.  (`nohup' is actually an external command.)
  1371.  
  1372.   The `disown' builtin is very useful in this respect: if zsh informs
  1373.   you that you have background jobs when you try to logout, you can
  1374.   `disown' all the ones you don't want killed when you exit.  This is
  1375.   also a good way of making jobs you don't need the shell to know about
  1376.   (such as commands which create new windows) invisible to the shell.
  1377.   Likewise, you can start a background job with `&!' instead of just
  1378.   `&' at the end, which will automatically disown the job.
  1379.  
  1380. 3.19: How do I list all my history entries?
  1381.  
  1382.   Tell zsh to start from entry 1: `history 1'.  Those entries at the
  1383.   start which are no longer in memory will be silently omitted.
  1384.  
  1385. 3.20: How does the alternative loop syntax, e.g. `while {...} {...}' work?
  1386.  
  1387.   Zsh provides an alternative to the traditional sh-like forms with `do',
  1388.  
  1389.     while TEST; do COMMANDS; done
  1390.  
  1391.   allowing you to have the COMMANDS delimited with some other command
  1392.   structure, often `{...}'.  The rules are quite complicated and
  1393.   in most scripts it is probably safer --- and certainly more
  1394.   compatible --- to stick with the sh-like rules.  If you are
  1395.   wondering, the following is a rough guide.
  1396.  
  1397.   To make it work you must make sure the TEST itself is clearly
  1398.   delimited.  For example, this works:
  1399.  
  1400.     while (( i++ < 10 )) { echo i is $i; }
  1401.  
  1402.   but this does _not_:
  1403.  
  1404.     while let "i++ < 10"; { echo i is $i; }   # Wrong!
  1405.  
  1406.   The reason is that after `while', any sort of command list is valid.
  1407.   This includes the whole list `let "i++ < 10"; { echo i $i; }';
  1408.   the parser simply doesn't know when to stop.  Furthermore, it is
  1409.   wrong to miss out the semicolon, as this makes the `{...}' part
  1410.   of the argument to `let'.  A newline behaves the same as a
  1411.   semicolon, so you can't put the brace on the next line as in C.
  1412.  
  1413.   So when using this syntax, the test following the `while' must
  1414.   be wrapped up:  any of `((...))', `[[...]]', `{...}' or
  1415.   `(...)' will have this effect.  (They have their usual syntactic
  1416.   meanings too, of course; they are not interchangeable.)  Note that
  1417.   here too it is wrong to put in the semicolon, as then the case
  1418.   becomes identical to the preceding one:
  1419.  
  1420.     while (( i++ < 10 )); { echo i is $i; }   # Wrong!
  1421.  
  1422.   The same is true of the `if' and `until' constructs:
  1423.  
  1424.     if { true } { echo yes } else { echo no }
  1425.  
  1426.   but with `for', which only needs a list of words, you can get
  1427.   away with it:
  1428.  
  1429.     for foo in a b; { echo foo is $a; bar=$foo; }
  1430.  
  1431.   since the parser knows it only needs everything up to the first
  1432.   semicolon. For the same reason, there is no problem with the `repeat',
  1433.   `case' or `select' constructs; in fact, `repeat' doesn't even
  1434.   need the semicolon since it knows the repeat count is just one word.
  1435.  
  1436.   This is independent of the behaviour of the SHORTLOOPS option (see
  1437.   manual), which you are in any case encouraged even more strongly not
  1438.   to use in programs as it can be very confusing.
  1439.  
  1440. 3.21: Why is my history not being saved?
  1441.  
  1442.   In zsh, you need to set three variables to make sure your history is
  1443.   written out when the shell exits.  For example,
  1444.  
  1445.     HISTSIZE=200
  1446.     HISTFILE=~/.zsh_history
  1447.     SAVEHIST=200
  1448.  
  1449.   $HISTSIZE tells the shell how many lines to keep internally,
  1450.   $HISTFILE tells it where to write the history, and $SAVEHIST,
  1451.   the easiest one to forget, tells it how many to write out.  The
  1452.   simplest possibility is to set it to the same as $HISTSIZE as
  1453.   above.  There are also various options affecting history; see the
  1454.   manual.
  1455.  
  1456. 3.22: How do I get a variable's value to be evaluated as another variable?
  1457.  
  1458.   The problem is that you have a variable $E containing the string
  1459.   `EDITOR', and a variable $EDITOR containing the string `emacs',
  1460.   or something such.  How do you get from $E to emacs in one easy
  1461.   stage?
  1462.  
  1463.   There is no standard single-stage way of doing this.  However, there
  1464.   is a zsh idiom (available in all versions of zsh since 3.0) for this:
  1465.  
  1466.     print ${(e)E:+\$$E}
  1467.  
  1468.   Ignore the `(e)' for now.  The `:+' means: if the variable
  1469.   $E is set, substitute the following, i.e. `\$$E'.  This is
  1470.   expanded to `$EDITOR' by the normal rules.  Finally, the `(e)' means
  1471.   `evaluate the expression you just made'.  This gives `emacs'.
  1472.  
  1473.   For a standard shell way of doing this, you are stuck with `eval':
  1474.  
  1475.     eval echo \$$E
  1476.  
  1477.   produces the same result.
  1478.  
  1479.   Versions since 3.1.6 allow you to do this directly with a new flag;
  1480.   `${(P)E}'.
  1481.  
  1482.   As a slight aside, sometimes people note that the syntax `${${E}}'
  1483.   is valid and expect it to have this effect.  It probably ought to, but
  1484.   in the early days of zsh it was found convenient to have this way of
  1485.   producing different substitutions on the same parameter; for example,
  1486.   `${${file##**/}%.*}' removes everything up to the last slash in
  1487.   `$file', then everything from the last dot on, inclusive (try
  1488.   it, this works).  So in `${${E}}', the internal `${...}'
  1489.   actually does nothing.
  1490.  
  1491. 3.23: How do I prevent the prompt overwriting output when there is no newline?
  1492.  
  1493.   The problem is, for example,
  1494.  
  1495.     % echo -n foo
  1496.     % 
  1497.  
  1498.   and the foo has been overwritten by the prompt %.  The answer is
  1499.   simple:  put unsetopt promptcr in your .zshrc.  The option PROMPT_CR,
  1500.   to print a carriage return before a new prompt, is set by default because
  1501.   a prompt at the right hand side (`$RPROMPT', `$RPS1') will not appear
  1502.   in the right place, and multi-line editing will be confused about the line
  1503.   position, unless the line starts in the left hand column.  Apart from
  1504.   PROMPT_CR, you can force this to happen by putting a newline in the
  1505.   prompt (see question 3.13 for that).
  1506.  
  1507. 3.24: What's wrong with cut and paste on my xterm?
  1508.  
  1509.   On the majority of modern UNIX systems, cutting text from one window and
  1510.   pasting it into another should work fine.  On a few, however, there are
  1511.   problems due to issues about how the terminal is handled:  most programs
  1512.   expect the terminal to be in `canonical input mode', which means that the
  1513.   program is passed a whole line of input at a time, while for editing
  1514.   the shell needs a single character at a time and must be in
  1515.   `non-canonical input mode'.  On the systems in question, input can be
  1516.   lost or re-ordered when the mode changes.  There are actually two
  1517.   slightly different problems:
  1518.  
  1519.   1) When you paste something in while a programme is running, so that
  1520.      the shell only retrieves it later.  Traditionally, there was a test
  1521.      which was used only on systems where the problem was known to exist,
  1522.      so it is possible some other systems were not handled (for example,
  1523.      certain versions of IRIX, it appears); also, continuation lines were
  1524.      not handled properly.  A more reliable approach appears from versions
  1525.      3.0.6 and 3.1.6.
  1526.   2) When the shell is waiting for input, and you paste in a chunk of
  1527.      text consisting of more than one complete set of commands.
  1528.      Unfortunately, this is a much harder problem: the line editor is
  1529.      already active, and needs to be turned off when the first command is
  1530.      executed.  The shell doesn't even know if the remaining text is input
  1531.      to a command or for the shell, so there's simply nothing it can do.
  1532.      However, if you have problems you can trick it: type `{' on a line
  1533.      by itself, then paste the input, then type `}' on a line by
  1534.      itself.  The shell will not execute anything until the final brace is
  1535.      read; all input is read as continuation lines (this may require the
  1536.      fixes referred to above in order to be reliable).
  1537.  
  1538. 3.25: How do I get coloured prompts on my colour xterm?
  1539.  
  1540.   (Or `color xterm', if you're reading this in black and white.)  You need
  1541.   to find the sequences which generate the various colours from the manual
  1542.   for your terminal emulator; these are ANSI standard on those I know about
  1543.   which support colour.  With a recent (post 3.1.6) distribution of zsh,
  1544.   there is a theme system to handle this for you; even if you don't see that,
  1545.   the installed function ``colors'' (meaning `colours', if you're not
  1546.   reading this in black and white) gives the escape sequences.  You will end
  1547.   up with code looking like this (borrowed from Oliver Kiddle):
  1548.  
  1549.     PS1=$'%{\e[1;31m%}<the rest of your prompt here>%{\e[0m%}'
  1550.  
  1551.   The `$'' form of quoting turns the ``\e'' into a real escape
  1552.   character; this only works from about version 3.1.4, so if you're using
  1553.   3.0.x, you need to do something like
  1554.  
  1555.     PS1="$(print '%{\e[1;31m%}<the rest goes here>%{\e[0m%}')"
  1556.  
  1557.   The ``%{...%}'' is used in prompts for strings which will
  1558.   not appear as characters, so that the prompt code doesn't miscalculate the
  1559.   length of the prompt which would have a bad effect on editing.  The
  1560.   resulting ``<ESC>[1;31m'' makes the prompt red, and the
  1561.   ``<ESC>[0m'' puts printing back to normal so that the rest of the line
  1562.   is unchanged.
  1563.  
  1564. 3.26: Why is my output duplicated with `foo 2>&1 >foo.out | bar'?
  1565.  
  1566.   This is a slightly unexpected effect of the option MULTIOS, which is
  1567.   set by default.  Let's look more closely:
  1568.  
  1569.     foo 2>&1 >foo.out | bar
  1570.  
  1571.   What you're probably expecting is that the command `foo' sends its
  1572.   standard output to the pipe and so to the input of the command `bar',
  1573.   while it sends its standard error to the file `foo.out'.  What you
  1574.   actually see is that the output is going both to the pipe and into the
  1575.   file.  To be more explicit, here's the same example with real commands:
  1576.  
  1577.     % { print output; print error >&2 } 2>&1 >foo.out | sed 's/error/erratic'
  1578.     erratic
  1579.     output
  1580.     % cat foo.out
  1581.     output
  1582.  
  1583.   and you can see `output' appears twice.
  1584.  
  1585.   It becomes clearer what's going on if we write:
  1586.  
  1587.     % print output >foo1.out >foo2.out
  1588.     % cat foo1.out
  1589.     output
  1590.     % cat foo2.out
  1591.     output
  1592.  
  1593.   You might recognise this as a standard feature of zsh, called `multios'
  1594.   and controlled by the option of the same name, whereby output is copied
  1595.   to both files when the redirector appears twice.  What's going on in the
  1596.   first example is exactly the same, however the second redirector is
  1597.   disguised as a pipe.  So if you want to turn this effect off, you need
  1598.   to `unsetopt multios'.
  1599.  
  1600. 3.27: Why am I prompted to correct commands which are in my path?
  1601.  
  1602. (Or, if you know about the command hash table, the command isn't in the
  1603. table even though you know it works --- it's the same basic problem.)
  1604.  
  1605. It occasionally happens that a directory in your path is not readable,
  1606. although files in it have `execute' permission.  Then the system can
  1607. execute them, but the shell can't see them when it scans the path, since
  1608. it does that by trying to read the directory.  If this is the case, you
  1609. may find `which var(cmd)' does find the command, since then the
  1610. shell checks the path explicitly for that one command rather than
  1611. looking for all files in the directory.
  1612.  
  1613. Chapter 4: The mysteries of completion
  1614.  
  1615. Programmable completion using the `compctl' command is one of the most
  1616. powerful, and also potentially confusing, features of zsh; here I give
  1617. a short introduction.  There is a set of example completions supplied
  1618. with the source in Misc/compctl-examples; completion definitions for
  1619. many of the most obvious commands can be found there.
  1620.  
  1621. If this confuses you, you may like to know that there is a new, more
  1622. elegant completion system which appeared in version 3.1.6.  This is based
  1623. on functions called automatically for completion in particular contexts
  1624. (for example, there is a function called _cd to handle completion for
  1625. the cd command) and is installed automatically with the shell, so all
  1626. you need to do, in principal, is to arrange for this to be loaded.  Putting
  1627. `autoload -U compinit; compinit' in your .zshrc should be enough if
  1628. the system is installed properly.  The rest of this section talks about the
  1629. old completion system.
  1630.  
  1631. 4.1: What is completion?
  1632.  
  1633.   `Completion' is where you hit a particular command key (TAB is the
  1634.   standard one) and the shell tries to guess the word you are typing
  1635.   and finish it for you --- a godsend for long file names, in
  1636.   particular, but in zsh there are many, many more possibilities than
  1637.   that.
  1638.  
  1639.   There is also a related process, `expansion', where the shell sees
  1640.   you have typed something which would be turned by the shell into
  1641.   something else, such as a variable turning into its value ($PWD
  1642.   becomes /home/users/mydir) or a history reference (!! becomes
  1643.   everything on the last command line).  In zsh, when you hit TAB it
  1644.   will look to see if there is an expansion to be done; if there is,
  1645.   it does that, otherwise it tries to perform completion.  (You can
  1646.   see if the word would be expanded --- not completed --- by TAB by
  1647.   typing `\C-x g', which lists expansions.)  Expansion is generally
  1648.   fairly intuitive and not under user control; for the rest of the
  1649.   chapter I will discuss completion only.
  1650.  
  1651. 4.2: What sorts of things can be completed?
  1652.  
  1653.   The simplest sort is filename completion, mentioned above.  Unless
  1654.   you have made special arrangements, as described below, then after
  1655.   you type a command name, anything else you type is assumed by the
  1656.   completion system to be a filename.  If you type part of a word and
  1657.   hit TAB, zsh will see if it matches the first part a file name and
  1658.   if it does it will automatically insert the rest.
  1659.  
  1660.   The other simple type is command completion, which applies
  1661.   (naturally) to the first word on the line.  In this case, zsh
  1662.   assumes the word is some command to be executed lying in your $PATH
  1663.   (or something else you can execute, like a builtin command, a
  1664.   function or an alias) and tries to complete that.
  1665.  
  1666.   Other forms of completion have to be set up by special arrangement.
  1667.   See the manual entry for compctl for a list of all the flags:  you
  1668.   can make commands complete variable names, user names, job names,
  1669.   etc., etc.
  1670.  
  1671.   For example, one common use is that you have an array variable,
  1672.   $hosts, which contains names of other machines you use frequently on
  1673.   the network:
  1674.  
  1675.     hosts=(fred.ph.ku.ac.uk snuggles.floppy-bunnies.com here.there.edu)
  1676.  
  1677.   then you can tell zsh that when you use telnet (or ftp, or ...), the
  1678.   argument will be one of those names:
  1679.  
  1680.     compctl -k hosts telnet ftp ...
  1681.  
  1682.   so that if you type `telnet fr' and hit TAB, the rest of the name
  1683.   will appear by itself.
  1684.  
  1685.   An even more powerful option to compctl (-g) is to tell zsh that
  1686.   only certain sorts of filename are allowed.  The argument to -g is
  1687.   exactly like a glob pattern, with the usual wildcards `*', `?', etc.
  1688.   In the compctl statement it needs to be quoted to avoid it being
  1689.   turned into filenames straight away.  For example,
  1690.  
  1691.     compctl -g '*.(ps|eps)' ghostview
  1692.  
  1693.   tells zsh that if you type TAB on an argument after a ghostview
  1694.   command, only files ending in `.ps' or `.eps' should be considered
  1695.   for completion.
  1696.  
  1697.   A useful addition for zsh from version 3.1 is directory completion:
  1698.  
  1699.     compctl -/ cd
  1700.  
  1701.   Before, you had to use -g, but this is neater: it takes care of
  1702.   things like ignoring directories beginning with a dot unless you've
  1703.   typed the dot yourself, and whole directory paths are understood.
  1704.  
  1705.   Note that flags may be combined; if you have more than one, all the
  1706.   possible completions for all of them are put into the same list, all
  1707.   of them being possible completions.  So
  1708.  
  1709.     compctl -k hosts -f rcp
  1710.  
  1711.   tells zsh that rcp can have a hostname or a filename after it.  (You
  1712.   really need to be able to handle host:file, which is where
  1713.   programmable completion comes in, see 4.5.)  Also, from
  1714.   version 3.1 you can always handle directories at the same time as
  1715.   other files just by adding -/ to the list.
  1716.  
  1717. 4.3: How does zsh deal with ambiguous completions?
  1718.  
  1719.   Often there will be more than one possible completion: two files
  1720.   start with the same characters, for example.  Zsh has a lot of
  1721.   flexibility for what it does here via its options (use `setopt
  1722.   var(optioname)' to turn an option on).  The default is
  1723.   for it to beep and completion to stop until you type another
  1724.   character.  You can type \C-D to see all the possible completions.
  1725.   (That's assuming you're at the end of the line, otherwise \C-D will
  1726.   delete the next character and you have to use ESC-\C-D.)  This can be
  1727.   changed by the following options, among others:
  1728.  
  1729.    o  with NO_BEEP set, that annoying beep goes away
  1730.    o  with NO_LIST_BEEP, beeping is only turned off for ambiguous
  1731.       completions
  1732.    o  with AUTO_LIST set, when the completion is ambiguous you get a
  1733.       list without having to type \C-D
  1734.    o  with BASH_AUTO_LIST set, the list only happens the second
  1735.       time you hit tab on an ambiguous completion
  1736.    o  with LIST_AMBIGUOUS, this is modified so that nothing is listed if
  1737.       there is an unambiguous prefix or suffix to be inserted --- this
  1738.       can be combined with BASH_AUTO_LIST, so that where both are
  1739.       applicable you need to hit tab three times for a listing.
  1740.    o  with MENU_COMPLETE set, one completion is always inserted
  1741.       completely, then when you hit TAB it changes to the next, and so
  1742.       on until you get back to where you started
  1743.    o  with AUTO_MENU, you only get the menu behaviour when you hit TAB
  1744.       again on the ambiguous completion.
  1745.    o  Finally, although it affects all completion lists, including
  1746.       those explicitly requested, note also ALWAYS_LAST_PROMPT, which
  1747.       causes the cursor to return to the line you were editing after
  1748.       printing the list, provided that is short enough.
  1749.  
  1750.   Combinations of these are possible; for example, AUTO_LIST and
  1751.   AUTO_MENU together give an intuitive combination.  Note that
  1752.   from version 3.1 LIST_AMBIGUOUS is set by default; if you use
  1753.   autolist, you may well want to `unsetopt listambiguous'.
  1754.  
  1755. 4.4: How do I complete in the middle of words / just what's before the cursor?
  1756.  
  1757.   Sometimes you have a word on the command-line (let's stick to file
  1758.   names) which is incomplete in the middle.  Normally if you hit tab
  1759.   in zsh, it will simply go to the end of the word and try to complete
  1760.   there.  However, there are two ways of changing this.
  1761.  
  1762.   First, you can `setopt complete_in_word'.  This tries to fill in
  1763.   the word at the point of the cursor.  For example, if the current
  1764.   directory contains `foobar', then with the option set, you can
  1765.   complete `fbar' to `foobar' by moving the cursor to the
  1766.   `b' and hitting tab.
  1767.  
  1768.   That's not the full story, however.  Sometimes you just want the
  1769.   part of the word before the cursor completed.  For example, the word
  1770.   is `/usr/loc/b', which you want to complete to `/usr/local/bin'.
  1771.   Normally, zsh won't do this in one go because there are two bits
  1772.   missing (but see below!), so you need to complete the `/usr/loc'
  1773.   on its own first.  For this you need the function
  1774.   expand-or-complete-prefix: it works mostly like the usual
  1775.   function bound to tab, but it ignores anything on the right of the
  1776.   cursor.  If you always want this behaviour (some other shells do
  1777.   this), bind it to tab; otherwise put another binding, e.g. `^X
  1778.   TAB' in ~/.zshrc:
  1779.  
  1780.     bindkey "^X^I" expand-or-complete-prefix
  1781.  
  1782.   then in the example you can move to just after `/usr/loc', hit
  1783.   whatever key you've just bound, move to the end, and hit tab.
  1784.   (Note that AUTO_REMOVE_SLASH behaviour applies here, see the manual.)
  1785.  
  1786.   Even that doesn't exhaust the possibilities.  Included with the
  1787.   source distribution is the file Functions/multicomp, a function
  1788.   which you can bind as an alternative form of default completion (see
  1789.   below for a description of alternative completion), e.g.
  1790.  
  1791.     compctl -D -f + -U -Q -K multicomp
  1792.  
  1793.   and whole sequences of directories, like `/usr/loc/b' or even
  1794.   `/u/l/b' can be completed in one go.  It works best with
  1795.   menucompletion if the result is ambiguous.
  1796.  
  1797. 4.5: How do I get started with programmable completion?
  1798.  
  1799.   Finally, the hairiest part of completion.  It is possible to get zsh
  1800.   to consider different completions not only for different commands,
  1801.   but for different words of the same command, or even to look at
  1802.   other words on the command line (for example, if the last word was a
  1803.   particular flag) and decide then.
  1804.  
  1805.   There are really two sorts of things to worry about.  The simpler is
  1806.   alternative completion:  that just means zsh will try one
  1807.   alternative, and only if there are no possible completions try the
  1808.   next.  For example
  1809.  
  1810.     compctl -g '*.ps' + -f lpr
  1811.  
  1812.   says that after lpr you'd prefer to find only `.ps' files, so if
  1813.   there are any, only those are used, but if there aren't any, any
  1814.   old file is a possibility.  You can also have a + with no flags
  1815.   after it, which tells zsh that it's to treat the command like any
  1816.   other if nothing was found.  That's only really useful if your
  1817.   default completion is fancy, i.e. you have done something with
  1818.   `compctl -D' to tell zsh how commands which aren't specially handled
  1819.   are to have their arguments completed.
  1820.  
  1821.   The second sort is the hard one.  Following a `-x', zsh expects that
  1822.   the next thing will be some completion code, which is a single
  1823.   letter followed by an argument in square brackets.  For example
  1824.   `p[1]': `p' is for position, and the argument tells it to look at
  1825.   position 1; that says that this completion only applies to the word
  1826.   immediately after the command.  You can also say `p[1,3]' which says
  1827.   the completion only applies to the word if it's between the first
  1828.   and third words, inclusive, after the command, and so on.  See the
  1829.   list in the `compctl' manual entry for a list of these conditions:
  1830.   some conditions take one argument in the square brackets, some two.
  1831.   Usually, negative numeric arguments count backwards from the end
  1832.   (for example, `p[-1]' applies to the last word on the line).
  1833.  
  1834.   (Note the difference in the ways `+' and `-x' work.  A `+'
  1835.   completion will always try and find completions for what's before
  1836.   the `+' first; it will only produce a list for what's after if
  1837.   the first list was empty.  On the other hand, if a condition for a
  1838.   `-x' matches, the appropriate set of completions is always used,
  1839.   even if the list of completions produced is empty.)
  1840.  
  1841.   The condition is then followed by the flags as usual (as in 4.2),
  1842.   and possibly other condition/flag sets following a single -; the
  1843.   whole lot ends with a double -- before the command name.  In other
  1844.   words, each extended completion section looks like this:
  1845.  
  1846.     -x <pattern> <flags>... [ - <pattern> <flags>... ...] --
  1847.  
  1848.   Let's look at rcp again: this assumes you've set up $hosts as above.
  1849.   This uses the `n[<n>,<string>]' flag, which tells zsh to look for
  1850.   the <n>'th occurrence of <string> in the word, ignoring anything up
  1851.   to and including that.  We'll use it for completing the bits of
  1852.   rcp's `user@host:file' combination.  (Of course, the file name is on
  1853.   the local machine, not `host', but let's ignore that; it may still
  1854.   be useful.)
  1855.  
  1856.     compctl -k hosts -S ':' + -f -x 'n[1,:]' -f - \ 
  1857.           'n[1,@]' -k hosts -S ':' -- rcp
  1858.  
  1859.   This means: (1) try and complete a hostname (the bit before the
  1860.   `+'), if successful add a `:' (-S for suffix); (2) if that fails
  1861.   move on to try the code after the `+':  look and see if there is a
  1862.   `:' in a word (the `n[1,:]'); if there is, complete filenames
  1863.   (-f) after the first of them; (3) otherwise look for an `@' and
  1864.   complete hostnames after the first of them (the `n[1,@]'), adding a
  1865.   `:' if successful; (4) if all else fails use the `-f' before the
  1866.   `-x' and try to complete files.
  1867.  
  1868.   So the rules for order are (1) try anything before a `+' before
  1869.   anything after it (2) try the conditions after a -x in order until
  1870.   one succeeds (3) use the default flags before the -x if none of the
  1871.   conditions was true.
  1872.  
  1873.   Different conditions can also be combined.  There are three levels
  1874.   of this (in decreasing order of precedence):
  1875.  
  1876.    1) multiple square brackets after a single condition give
  1877.       alternatives:  for example, `s[foo][bar]' says apply the
  1878.       completion if the word begins with `foo' or `bar',
  1879.    2) spaces between conditions mean both must match:  for example,
  1880.       `p[1] s[-]' says this completion only applies for the first word
  1881.       after the command and only if it begins with a `-',
  1882.    3) commas between conditions mean either can match:  for example,
  1883.       `c[-1,-f], s[-f]' means either the previous word (-1 relative to
  1884.       the current one) is -f, or the current word begins with -f ---
  1885.       useful to use the same completion whether or not the -f has a
  1886.       space after it.
  1887.  
  1888.   You must be careful to put the whole expression inside quotation
  1889.   marks, so that it appears as a single argument to compctl.
  1890.  
  1891.   Here's a useless example just to show a general `-x' completion.
  1892.  
  1893.     compctl -f -x 'c[-1,-u][-1,-U] p[2], s[-u]' -u - \ 
  1894.       'c[-1,-j]' -P % -j -- foobar
  1895.  
  1896.   The way to read this is:  for command `foobar', look and see if (((the
  1897.   word before the current one is -u) or (the word before the current
  1898.   one is -U)) and (the current word is 2)) or (the current word begins
  1899.   with -u); if so, try to complete user names.  If the word before
  1900.   the current one is -j, insert the prefix `%' before the current word
  1901.   if it's not there already and complete job names.  Otherwise, just
  1902.   complete file names.
  1903.  
  1904. 4.6: And if programmable completion isn't good enough?
  1905.  
  1906.   ...then your last resort is to write a shell function to do it for
  1907.   you.  By combining the `-U' and `-K func' flags you can get
  1908.   almost unlimited power.  The `-U' tells zsh that whatever the
  1909.   completion produces is to be used, even if it doesn't fit what's
  1910.   there already (so that gets deleted when the completion is
  1911.   inserted).  The `-K func' tells zsh a function name.  The
  1912.   function is passed the part of the word already typed, and can read
  1913.   the rest of the line with `read -c'.  It can return a set of
  1914.   completions via the `reply' array, and this becomes the set of
  1915.   possible completions.  The best way to understand this is to look at
  1916.   `multicomp' and other functions supplied with the zsh
  1917.   distribution.  Almost certainly, however, you are better off using
  1918.   the new completion system for anything complicated.  No further
  1919.   upgrades are planned for the old system.
  1920.  
  1921. Chapter 5: The future of zsh
  1922.  
  1923. 5.1: What bugs are currently known and unfixed? (Plus recent important changes)
  1924.  
  1925.   Here are some of the more well-known ones, very roughly in
  1926.   decreasing order of significance.  Many of these can also be counted
  1927.   against differences from ksh in question 2.1; note that this applies
  1928.   to the latest beta version and that simple bugs are often fixed
  1929.   quite quickly.  There is a file Etc/BUGS in the source distribution
  1930.   with more detail.
  1931.  
  1932.   o  Parameter expansions using the ${param+word} and ${param-word}
  1933.     forms may fail to behave in Bourne-shell-compatible fashion when the
  1934.     SH_WORD_SPLIT option is set and the word contains spaces.
  1935.   o  `time' is ignored with builtins and can't be used with `{...}'.
  1936.   o  `set -x' (`setopt xtrace') still has a few glitches; these
  1937.      are mostly fixed in 3.1.6.
  1938.   o  Zsh's notion of the current line number (via $LINENO) is
  1939.      sometimes not well handled, particularly when using functions and traps.
  1940.      This should also work reliably from 3.0.6 and 3.1.6.
  1941.   o  In vi mode, `u' can go past the original modification point.
  1942.   o  The singlelinezle option has problems with prompts containing escapes.
  1943.   o  The `r' command does not work inside `$(...)' or ``...`'
  1944.      expansions.   This is fixed in 3.1.
  1945.   o  `typeset' handling is non-optimal, particularly with regard to
  1946.      flags, and is ksh-incompatible in unpredictable ways.  3.1.6 has
  1947.      been overhauled, but remaining glitches are to be expected.
  1948.   o  Nested closures in extended globbing and pattern matching, such as
  1949.  
  1950.       [[ fofo = (fo#)# ]]
  1951.  
  1952.      were once not correctly handled, and there were problems with
  1953.      complicated exclusions using `^' or `~'.  These are fixed
  1954.      since version 3.1.3.
  1955.  
  1956.   o  Handling of the `:q' and `:x' with parameter subsitutions is
  1957.     erratic: neither work in any 3.0 release, and :x doesn't work in
  1958.     any release so far.
  1959.  
  1960.   Note that a few recent changes introduce incompatibilities (these
  1961.   are not bugs):
  1962.  
  1963.   Changes after zsh 3.0:
  1964.  
  1965.   o  The options ALWAYS_LAST_PROMPT (return to the line you were
  1966.      editing after displaying completion lists) and LIST_AMBIGUOUS
  1967.      (don't do AUTO_LIST if there was an unambiguous prefix that could be
  1968.      inserted, i.e. only list if it is ambiguous what to insert next) are
  1969.      now set by default.  This is in response to complaints that too many
  1970.      zsh features are never noticed by many users.  To turn them off,
  1971.      just put `unsetopt alwayslastprompt listambiguous' in your
  1972.      .zshrc file.
  1973.   o  In 3.1.5, history-search-{forward,backward} only find previous
  1974.      lines where the first word is the same as the current one.  For
  1975.      example, 
  1976.  
  1977.       comp<ESC>p
  1978.  
  1979.      will find lines in the history like `comp -edit emacs', but not
  1980.      `compress file' any more.  For this reason, `\M-n' and
  1981.      `\M-p' use history-beginning-search-{forward,backward} which
  1982.      search for a line with the same prefix up to the cursor position.
  1983.      From 3.1.6, there is a different implementation which makes this
  1984.      closer (though not identical) to the old behaviour, and the
  1985.      traditional bindings have been restored.. The story for the 
  1986.      {up,down}-line-or-search commands is similar.
  1987.   o  In vi insert mode, the cursor keys no longer work.  The following
  1988.      will bind them:
  1989.  
  1990.        bindkey -M viins '^[[D' vi-backward-char '^[[C' vi-forward-char \ 
  1991.                       '^[[A' up-line-or-history '^[[B' down-line-or-history
  1992.  
  1993.      (unless your terminal requires `^[O' instead of `^[[').  The
  1994.      rationale is that the insert mode and command mode keymaps for
  1995.      keys with prefixes are now separate.
  1996.  
  1997.   Changes since zsh 2.5:
  1998.  
  1999.   o  The left hand of an assignment is no longer substituted.  Thus,
  2000.      `$1=$2' will not work.  You can use something like `eval
  2001.      "$1=\$2"', which should have the identical effect.
  2002.   o  Signal traps established with the `trap' builtin are now called with
  2003.      the environment of the caller, as in ksh, instead of as a new
  2004.      function level.  Traps established as functions (e.g. `TRAPINT()
  2005.      {...}') work as before.
  2006.   o  The NO_CLOBBER option is now -C and PRINT_EXIT_VALUE -1; they
  2007.      used to be the other way around.  (Use of names rather than letters is
  2008.      generally recommended.)
  2009.   o  `[[' is a reserved word, hence must be separated from
  2010.      other characters by whitespace; `{' and `}' are also reserved
  2011.      words if the IGNORE_BRACES option is set.
  2012.   o  The option CSH_JUNKIE_PAREN has been removed:  csh-like code now
  2013.      always does what it looks like it does, so `if ( ... ) ...'
  2014.      executes the code in parentheses in a subshell.  To make this
  2015.      useful, the syntax expected after an `if', etc., is less strict
  2016.      than in other shells.
  2017.   o  `foo=*' does not perform globbing immediately on the right
  2018.      hand side of the assignment; the old behaviour now requires the
  2019.      option GLOB_ASSIGN.  (`foo=(*)' is and has always been the
  2020.      consistent way of doing this.)
  2021.   o  <> performs redirection of input and output to the specified file.
  2022.      For numeric globs, you now need <->.
  2023.   o  The command line qualifiers exec, noglob, command, - are now
  2024.      treated more like builtin commands:  previously they were
  2025.      syntactically special.  This should make it easier to perform
  2026.      tricks with them (disabling, hiding in parameters, etc.).
  2027.   o  The pushd builtin has been rewritten for compatibility with other
  2028.      shells.  The old behavour can be achieved with a shell function.
  2029.   o  The current version now uses ~'s for directory stack substitution
  2030.      instead of ='s.  This is for consistency:  all other directory
  2031.      substitution (~user, ~name, ~+, ...) used a tilde, while
  2032.      =<number> caused problems with =program substitution.
  2033.   o  The HISTLIT option was broken in various ways and has been removed:
  2034.      the rewritten history mechanism doesn't alter history lines, making
  2035.      the option unnecessary.
  2036.   o  History expansion is disabled in single-quoted strings, like other
  2037.      forms of expansion -- hence exclamation marks there should not be
  2038.      backslashed.
  2039.   o  The `$HISTCHARS' variable is now `$histchars'.  Currently both
  2040.      are tied together for compatibility.
  2041.   o  The PROMPT_SUBST option now performs backquote expansion -- hence
  2042.      you should quote these in prompts.  (SPROMPT has changed as a result.)
  2043.   o  Quoting in prompts has changed: close parentheses inside ternary
  2044.      expressions should be quoted with a %; history is now %!, not
  2045.      !.  Backslashes are no longer special.
  2046.  
  2047. 5.2: Where do I report bugs, get more info / who's working on zsh?
  2048.  
  2049.   The shell is being maintained by various (entirely self-appointed)
  2050.   subscribers to the mailing list,
  2051.  
  2052.     zsh-workers@sunsite.dk
  2053.  
  2054.   so mail on any issues (bug reports, suggestions, complaints...)
  2055.   related to the development of the shell should be sent there.  If
  2056.   you want someone to mail you directly, say so.  Most patches to zsh
  2057.   appear there first.
  2058.  
  2059.   Note that this location has just changed (January 1999), and the
  2060.   instructions to go with it are slightly different --- in particular,
  2061.   if you are already subscribed, the instructions about how to
  2062.   unsubscribe are different.
  2063.  
  2064.   Please note when reporting bugs that many exist only on certain
  2065.   architectures, which the developers may not have access to.  In
  2066.   this case debugging information, as detailed as possible, is
  2067.   particularly welcome.
  2068.  
  2069.   Two progressively lower volume lists exist, one with messages
  2070.   concerning the use of zsh,
  2071.  
  2072.     zsh-users@sunsite.dk
  2073.  
  2074.   and one just containing announcements:  about releases, about major
  2075.   changes in the shell, or this FAQ, for example,
  2076.  
  2077.     zsh-announce@sunsite.dk
  2078.  
  2079.   (posting to the last one is currently restricted).
  2080.  
  2081.   Note that you should only join one of these lists:  people on
  2082.   zsh-workers receive all the lists, and people on zsh-users will
  2083.   also receive the announcements list.
  2084.  
  2085.   The lists are handled by an automated server.  The instructions for
  2086.   zsh-announce and zsh-users are the same as for zsh-workers: just
  2087.   change zsh-workers to whatever in the following.
  2088.  
  2089.   To join zsh-workers, send email to
  2090.  
  2091.     zsh-workers-subscribe@sunsite.dk
  2092.  
  2093.   (the actual content is unimportant).  Replace subscribe with
  2094.   unsubscribe to unsubscribe.  The mailing software (ezlm) has
  2095.   various bells and whistles: you can retrieve archived messages.
  2096.   Mail zsh-workers-help@sunsite.dk for detailed information.
  2097.   Adminstrative matters are best sent to
  2098.   zsh-workers-owner@sunsite.dk.  The list maintainer's
  2099.   real name is Karsten Thygesen <karthy@kom.auc.dk>.
  2100.  
  2101.   An archive of mailings for the last few years can be found at
  2102.     http://www.zsh.org/mla/
  2103.   at the main zsh archive in Australia.
  2104.  
  2105.   Of course, you can also post zsh queries to the Usenet group
  2106.   comp.unix.shell; if all else fails, you could even e-mail me.
  2107.  
  2108. 5.3: What's on the wish-list?
  2109.  
  2110.   With version 3, the code is much cleaner than before, but still
  2111.   bears the marks of the ages and many things could be done much
  2112.   better with a rewrite.  A more efficient set of code for
  2113.   lexing/parsing/execution might also be an advantage.  Volunteers are
  2114.   particularly welcome for these tasks.
  2115.  
  2116.   Here are the latest changes, which appeared in zsh 3.1.6.
  2117.  
  2118.   o  Even more powerful new completion system, based on shell functions,
  2119.      allowing much more detailed control both over generation of matches
  2120.      for completion and how they are inserted and displayed.  A set of
  2121.      functions which work `out of the box' will be available, including
  2122.      many functions for external commands:  files in tar archives can
  2123.      be listed for extraction as if they were real files; GNU commands
  2124.      which accept the `--help' option can generate completion lists for
  2125.      themselves on the fly, etc., etc.
  2126.      You can have old-style compctl-based completions for some commands,
  2127.      and new-style ones for others; you can bind particular completion
  2128.      commands of your own definition to key-strokes.
  2129.   o  Other completion enhancements:  matching control, allowing
  2130.      case-insensitive matching and wild card anchors, e.g. `z_t<TAB>'
  2131.      can allow a wildcard before the `_' so that this will expand
  2132.      to `zle_tricky.c' --- all under user control; completions can
  2133.      be grouped; a new completion command, menu-select, allows real menu
  2134.      selection --- you can move the cursor around to choose a completion.
  2135.   o  Case-insensitive and approximate matching in the globbing code:
  2136.      for example, `(#ia2)readme' matches the string `readme'
  2137.      case-insensitively with up to two errors, such as README,
  2138.      READ.ME, _README_, Read!Me!.  The new completion system
  2139.      knows about these, allowing correcting completion, e.g.
  2140.      `mkaef<TAB>' can be made to complete to `Makefile'.
  2141.   o  Associative arrays, declared with `typeset -A aname'; syntax
  2142.      for creating, accessing and deleting elements of these.
  2143.   o  Users can create their own foopath/FOOPATH array/path
  2144.      combinations, just like path and PATH.
  2145.   o  A dynamically loadable library for FTP, complete with a suite of
  2146.      functions to make it easy to use.  This allows you to use the shell's
  2147.      capabilities for scripting, line editing, completion, I/O redirection,
  2148.      directory management etc. within an FTP session.
  2149.  
  2150.   Other future possibilities which have been suggested:
  2151.  
  2152.   o  The parameter code could do with tidying up, maybe with more of the
  2153.      features made available in ksh93.
  2154.   o  Configuration files to enable zsh startup files to be created
  2155.      with the Dotfile Generator.
  2156.   o  Further improvements in integrating the line editor with shell
  2157.      functions.
  2158.   o  Ksh compatibility could be improved.
  2159.   o  Option for glob qualifiers to follow perl syntax (a traditional item).
  2160.  
  2161. 5.4: Did zsh have problems in the year 2000?
  2162.  
  2163.   Not that I heard of; it's up to you to be careful with two-digit dates,
  2164.   though, which are produced by the prompt escapes `%W' and `%D',
  2165.   and also by the command `print -P'.  Earlier versions of zsh may
  2166.   show problems here.
  2167.  
  2168. Acknowledgments:
  2169.  
  2170. Thanks to zsh-list, in particular Bart Schaefer, for suggestions
  2171. regarding this document.  Zsh has been in the hands of archivists Jim
  2172. Mattson, Bas de Bakker, Richard Coleman, Zoltan Hidvegi and Andrew
  2173. Main, and the mailing list has been run by Peter Gray, Rick Ohnemus,
  2174. Richard Coleman and Karsten Thygesen, all of whom deserve thanks.  The
  2175. world is eternally in the debt of Paul Falstad for inventing zsh in
  2176. the first place (though the wizzo extended completion is by Sven
  2177. Wischnowsky).
  2178.  
  2179. Copyright Information:
  2180.  
  2181. This document is copyright (C) P.W. Stephenson, 1995 -- 2001.
  2182. This text originates in the U.K. and the author asserts
  2183. his moral rights under the Copyrights, Designs and Patents Act, 1988.
  2184.  
  2185. Permission is hereby granted, without written agreement and without
  2186. license or royalty fees, to use, copy, modify, and distribute this
  2187. documentation for any purpose, provided that the above copyright
  2188. notice appears in all copies of this documentation.  Remember,
  2189. however, that this document changes monthly and it may be more useful
  2190. to provide a pointer to it rather than the entire text.  A suitable
  2191. pointer is "information on the Z-shell can be obtained on the World
  2192. Wide Web at URL http://zsh.sunsite.dk/".
  2193.