home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / answers / unix-faq / shell / zsh < prev   
Encoding:
Text File  |  1993-12-21  |  36.5 KB  |  801 lines

  1. Newsgroups: comp.unix.shell,comp.answers,news.answers
  2. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!spool.mu.edu!howland.reston.ans.net!pipex!uknet!liv!amtp!pws
  3. From: pws@s-a.amtp.liv.ac.uk (Peter Stephenson)
  4. Subject: Z-shell Frequently-Asked Questions
  5. Message-ID: <PWS.93Dec21152225@suna.amtp.liv.ac.uk>
  6. Followup-To: comp.unix.shell
  7. Summary: Q's and A's about zsh, a powerful (and free) UNIX shell
  8. Sender: news@liverpool.ac.uk (News System)
  9. Supersedes: <PWS.93Nov26150931@suna.amtp.liv.ac.uk>
  10. Nntp-Posting-Host: suna.amtp.liv.ac.uk
  11. Reply-To: Peter Stephenson <pws@s-a.amtp.liv.ac.uk>
  12. Organization: DAMTP, University of Liverpool
  13. Date: Tue, 21 Dec 1993 15:22:24 GMT
  14. Approved: news-answers-request@MIT.Edu
  15. Expires: Mon, 24 Jan 1994 00:00:00 GMT
  16. Lines: 782
  17. Xref: senator-bedfellow.mit.edu comp.unix.shell:14213 comp.answers:3116 news.answers:16066
  18.  
  19. Archive-Name: unix-faq/shell/zsh
  20. Last-Modified: 1993/12/21
  21. Submitted-By: pws@s-a.amtp.liv.ac.uk (Peter Stephenson)
  22. Version: $Id: zsh.FAQ,v 1.20 1993/12/21 15:15:46 pws Exp pws $
  23. Frequency: Monthly
  24.  
  25. This document contains a list of frequently-asked (or otherwise
  26. significant) questions concerning the Z-shell, a command interpreter for
  27. many UNIX systems which is freely available to anyone with FTP access.
  28. Zsh is more powerful than every other common shell (sh, ksh, csh, tcsh
  29. and bash) put together.
  30.  
  31. If you have never heard of `sh', `csh' or `ksh', then you are probably
  32. better off to start by reading a general introduction to UNIX rather
  33. than this document.
  34.  
  35. Another useful source of information is the collection of FAQ articles
  36. posted frequently to the Usenet news groups comp.unix.questions,
  37. comp.unix.shells and comp.answers with answers to general questions
  38. about UNIX.  The fifth of the seven articles deals with shells,
  39. including zsh, with a brief description of differences.  (This article
  40. also talks about shell startup files which would otherwise rate a
  41. mention here.)
  42.  
  43. If you just want to know how to get your hands on the latest version,
  44. skip to question 4); if you want to know what to do with insoluble
  45. problems, go to 21).
  46.  
  47. To encourage you to read on, if you don't know about zsh but are
  48. familiar with other UNIX shells, here are some things that zsh is
  49. particularly good at.  No claim of exclusivity is made, especially as
  50. shells copy one another, though in the areas of command line editing and
  51. globbing zsh is well ahead of the competition.  I am not aware of a
  52. major feature in any other freely-available shell which zsh does not
  53. also have.
  54.   Command line editing:
  55.     programmable completion: incorporates the ability to use
  56.       the full power of zsh globbing (compctl -g),
  57.     multi-line commands editable as a single buffer (even files!),
  58.     variable editing (vared),
  59.     command buffer stack,
  60.     print text straight into the buffer for immediate editing (print -z),
  61.     execution of unbound commands,
  62.     menu completion,
  63.     variable, editing function and option name completion,
  64.     inline expansion of variables, history commands.
  65.   Globbing --- extremely powerful, including:
  66.     recursive globbing (cf. find),
  67.     file attribute qualifiers (size, type, etc. also cf. find),
  68.     full alternation and negation of patterns.
  69.   Handling of multiple redirections (simpler than tee).
  70.   Large number of options for tailoring.
  71.   Path expansion (=foo -> /usr/bin/foo).
  72.   Adaptable messages for spelling, watch, time as well as prompt
  73.     (now including conditional expressions).
  74.   Named directories.
  75.   Comprehensive integer arithmetic.
  76.   Manipulation of arrays (including reverse subscripting).
  77.   Spelling correction.
  78.  
  79.  
  80. Notation: Quotes `like this' are ordinary textual quotation
  81. marks.  Other uses of quotation marks are input to the shell.
  82.  
  83. Contents:
  84. 1) What is it?
  85. 2) On what machines will it run?
  86. 3) What's the latest version?
  87. 4) Where do I get it?
  88. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  89. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  90. 7) How do I turn off spelling correction for an indvidual command?
  91. 8) How do I get the meta key to work on my xterm?
  92. 9) Why does my terminal act funny in way x?
  93. 10) Why does `$var' where var="foo bar" not do what I expect?
  94. 11) My PATH, (MANPATH, ...) sometimes doesn't handle tildes.  What gives?
  95. 12) How does base arithmetic work?
  96. 13) How do I get a newline in my prompt?
  97. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  98. 15) How do I execute command `foo' within function `foo'?
  99. 16) Why can't I get zsh to work with SGI's `userenv'?
  100. 17) Why do history substitutions with single bangs do something funny?
  101. 18) Why does zsh kill off all my background jobs when I logout?
  102. 19) I don't have root access: how do I make zsh my login shell?
  103. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  104. 21) What bugs are currently known and unfixed?
  105. 22) Where do I report bugs, get more info / who's working on zsh?
  106. 23) What's on the wish-list?
  107. --- End of Contents ---
  108.  
  109.  
  110. 1) What is it?
  111.  
  112.   Zsh is a UNIX command interpreter (shell) which of the standard shells
  113.   most resembles the Korn shell (ksh), although it is not completely
  114.   compatible.  It includes enhancements of many types, notably in the
  115.   command-line editor, options for customising its behaviour, filename
  116.   globbing, features to make C-shell (csh) users feel more at home and
  117.   extra features drawn from tcsh (another `custom' shell).
  118.  
  119.   It was written by Paul Falstad <pf@z-code.com> when a student at
  120.   Princeton; however, Paul doesn't maintain it any more and enquiries
  121.   should be sent to the mailing list (see question 20).  It is freely
  122.   available to anyone under unrestrictive conditions.
  123.  
  124.   For more information, the files doc/intro.txt or doc/intro.troff
  125.   included with the source distribution are highly recommended.  A list
  126.   of features is given in FEATURES, also with the source.
  127.  
  128.  
  129. 2) On what machines will it run?
  130.  
  131.   Zsh was written for machines of the Berkeley UNIX family; most such
  132.   machines (and all the most popular) will run it without major surgery.
  133.   Modifications have been made so that it should work under SYSVR4-based
  134.   operating systems such as Solaris 2.x and OSF/1.  This best thing is
  135.   to suck it and see.  You may not have to change too much: if you do
  136.   change anything, arrange for the shell script `buildzsh' to set the
  137.   necessary #define's, etc., without human intervention.  Recent
  138.   additions include Convex, Unicos and Linux support; there is a project
  139.   to allow POSIX.1 compilation (but note that that zsh is not itself
  140.   particularly POSIX-compliant at the moment).  Success has been
  141.   obtained on older SYSVR3 systems, but you may need to modify the code.
  142.   
  143.   If you add support for a new machine, it would be appreciated if you
  144.   could alter buildzsh to configure zsh automatically and send the
  145.   required context diffs to the list (see question 20).
  146.  
  147.  
  148. 3) What's the latest version?
  149.   
  150.   The latest production version is 2.3.1.  The current beta version is
  151.   2.4.  New patches occur frequently and are added to the archive (next
  152.   question).  At the time of writing the latest patch level was 283.
  153.   Note that this `open' development system does mean bugs are sometimes
  154.   introduced into the most recent archived version.  These are usually
  155.   fixed quickly.
  156.  
  157.   The next production version will be 2.5 (2.4 will not be released, so
  158.   as to minimise confusion over version numbers).  It is expected that
  159.   no new features will be added before the release.
  160.  
  161.  
  162. 4) Where do I get it?
  163.  
  164.   Bas de Bakker (bas@phys.uva.nl) is in charge of the archive and the
  165.   latest version is available for users east of the Atlantic from:
  166.     carlo.phys.uva.nl(145.18.218.21):/pub/bas/zsh/zsh-2.4beta.tar.gz
  167.   The latest full release is in zsh-2.3.1.tar.gz in the same directory.
  168.   Note that this is in gzip format: you will need GNU gzip from your
  169.   nearest GNU archive to unpack it.  There is also a version under RCS
  170.   control which may be more suitable for source hackers.
  171.  
  172.   Rick Ohnemus has a reflector site in the USA:
  173.         ftp.sterling.com (192.124.9.1):/zsh
  174.  
  175.   The 2.3.1 distribution is also available from ftp.uu.net and mirrors
  176.   in the directory pub/shells/zsh.
  177.  
  178.  
  179. 5) How does zsh differ from sh, ksh, csh, tcsh, bash?
  180.  
  181.   As has already been mentioned, zsh is most similar to ksh, while many
  182.   of the additions are to please csh users.
  183.  
  184.   i) ksh:
  185.  
  186.   Most features of ksh (and hence also of sh) are implemented in zsh;
  187.   problems can arise because the implementation is slightly different.
  188.   Note also that not all ksh's are the same either.  I have based this
  189.   on the 11/16/88f version of ksh.
  190.  
  191.   Various options can be turned on which will increase ksh
  192.   compatibility, though decrease zsh's abilities: see the manual entries
  193.   for IGNORE_BRACES (though brace expansion occurs in some versions of
  194.   ksh), KSH_OPTION_PRINT, NO_BANG_HIST, NO_EQUALS, NO_HUP, NO_RCS,
  195.   NO_SHORT_LOOPS, PROMPT_SUBST, RM_STAR_SILENT, SH_WORD_SPLIT (see
  196.   question 14) and SINGLE_LINE_ZLE.  Note that you can also disable any
  197.   built-in commands which get in your way.  If invoked as `ksh', the
  198.   shell will try and set suitable options.
  199.  
  200.   Here are some differences from ksh which might prove significant for
  201.   ksh programmers, some of which may be interpreted as bugs; there must
  202.   be more.  Note that this list is deliberately rather full and that
  203.   most of the items are fairly minor.  Those marked `*' perform in a
  204.   ksh-like manner if the shell is invoked as ksh.
  205.   
  206.   Syntax:
  207.   * Shell word splitting: see question 9).  (This is particularly
  208.       frequently asked about.)
  209.     Arrays are more csh-like than ksh-like:
  210.       subscripts start at 1, not 0; array[0] refers to array[1];
  211.       `$array' refers to the whole array, not $array[0];
  212.       braces are unnecessary: $a[1] == ${a[1]}, etc.
  213.     Coprocesses are established by `coproc'; `|&' behaves like csh.
  214.   Command line substitutions, globbing etc.:
  215.     The results of parameter substitutions are treated as plain text:
  216.       `foo="*"; print $foo' prints all files in ksh but * in zsh.
  217.     The $((...)) version of numeric evaluation is not implemented; use $[...].
  218.     Treatment of backslashes within backquotes is different.
  219.     $PSn do not do parameter substitution by default (use promptsubst option).
  220.     Globbing does not allow ksh-style `pattern-lists'.  Equivalents:
  221.       -------------------------------------------------------------------
  222.              ksh             zsh          Meaning
  223.             -----           -----        ---------
  224.            !(foo)            ^foo        Anything but foo.
  225.                       or   foo1~foo2     Anything matching foo1 but foo2.
  226.       @(foo1|foo2|...)  (foo1|foo2|...)  One of foo1 or foo2 or ...
  227.            ?(foo)           (foo|)       Zero or one occurrences of foo.
  228.            *(foo)           (foo)#       Zero or more occurrences of foo.
  229.            +(foo)         foo(foo)#      One or more occurrences of foo.
  230.       -------------------------------------------------------------------
  231.       The last two (with `#') require the EXTENDED_GLOB option.
  232.     Unquoted assignments do file expansion after ':'s (intended for PATHs).
  233.     `integer' does not allow -i; integers in bases other than 10 do not
  234.       have "base#" prefixed to them when printed.
  235.   Command execution:
  236.     There is no ENV variable (use /etc/zshrc, ~/.zshrc; note also ZDOTDIR).
  237.     The PATH is not searched for commands specified at invocation without -c.
  238.   Aliases and functions:
  239.     The order in which aliases and functions are defined is significant
  240.       (function definitions with () expand aliases -- see question 6).
  241.     Aliases and functions cannot be exported.
  242.     There are no tracked aliases: command hashing replaces these.
  243.     The use of aliases for key bindings is replaced by `bindkey'.
  244.   Traps and signals:
  245.     By default, background jobs are killed when you log out:  see 17).
  246.     Traps and options are not local to functions; traps are not reset
  247.       automatically when called; traps are called as functions themselves
  248.       (this is a bug for the `trap "..." NAL' form of trap setting).
  249.     TRAPERR has become TRAPZERR (this was forced by UNICOS which has SIGERR).
  250.   Editing:
  251.     The options emacs, gmacs, privileged, trackall, viraw are not supported.
  252.       Use bindkey to change the editing behaviour: `set -o {emacs,vi}' 
  253.       become `bindkey -{e,v}'; for gmacs, go to emacs mode and use
  254.       `bindkey \^t gosmacs-transpose-characters'.  `Trackall' is replaced
  255.       by `hashcmds'.
  256.     The `keyword' option does not exist and -k is instead interactivecomments.
  257.       (`keyword' will not be in the next ksh release either.)
  258.     Management of histories in multiple shells is different:
  259.       the history list is not saved and restored after each command.
  260.     \ does not escape editing chars (use ^V).
  261.     Not all ksh bindings are set (e.g. `<ESC>#'; try <ESC>q).
  262.   * # in an interactive shell is not treated as a comment by default.
  263.   Built-in commands:
  264.     Some built-ins (r, autoload, history, integer ...) were aliases in ksh.
  265.     There is no built-in command newgrp: use a shell function, e.g.
  266.       newgrp () { ((SHLVL--)) ; exec command newgrp $* }
  267.     `jobs' has no `-n' flag.
  268.     `read' has no `-s' flag.
  269.     In `let "i = foo"', foo is evaluated as a number, not an expression
  270.       (although in `let "i = $foo"' it is treated as an expression).
  271.   Other idiosyncracies:
  272.     `select' always redisplays the list of selections on each loop.
  273.  
  274.   ii) csh:
  275.  
  276.   Although certain features aim to ease the withdrawal symptoms of csh
  277.   (ab)users, the syntax is in general rather different and you should
  278.   certainly not try to run scripts without modification.  The c2z script
  279.   is provided with the source (in scripts/c2z) to help convert .cshrc
  280.   and .login files; see also the next question concerning aliases,
  281.   particularly those with arguments.
  282.  
  283.   Csh-compatibility additions include:
  284.     Logout, rehash, source, (un)limit built-in commands.
  285.     *rc file for interactive shells.
  286.     Directory stacks.
  287.     Cshjunkie*, ignoreeof options.
  288.     The nonomatch option.
  289.     >&, |& etc. redirection.
  290.     foreach ... loops; alternate syntax for other loops.
  291.     $PROMPT as well as $PS1, $status as well as $?, $#argv as well as $#, ....
  292.     Escape sequences via % for prompts.
  293.     Special array variables $PATH etc. are colon-separated, $path are arrays.
  294.     !-type history (which may be turned off via `setopt nobanghist').
  295.     Arrays have csh-like features (see i)).
  296.  
  297.   iii) tcsh:
  298.  
  299.   (The previous section applies too, of course.)  Certain features have
  300.   been borrowed from tcsh, including $watch, run-help, $savehist,
  301.   $histlit, periodic commands etc., extended prompts, sched and
  302.   which/where built-ins.  Programmable completion was inspired by, but
  303.   is entirely different to, tcsh's `complete'. (There is a perl script
  304.   called lete2ctl in the scripts directory of the source distribution to
  305.   convert `complete' to `compctl' statements.)  This list is not
  306.   definitive: some features have gone in the other direction.
  307.  
  308.   If you're missing the editor function run-fg-editor, try something
  309.   with bindkey -s (which binds a string to a keystroke), e.g.
  310.     bindkey -s '^z' '\eqfg %$EDITOR:t\n'
  311.   which pushes the current line onto the stack and tries to bring a job
  312.   with the basename of your editor into the foreground.  Bindkey -s
  313.   allows limitless possibilities along these lines.
  314.  
  315.   iv) bash:
  316.   
  317.   Zsh has almost all the features that bash has (and much more); in
  318.   addition it is about twice as fast, though this is less impressive
  319.   than it sounds.  With the new malloc by Sven Wischnowsky (only used if
  320.   you arranged for USE_ZSH_MALLOC to be defined in config.h when
  321.   compiling zsh), zsh uses about the same amount of heap memory as bash,
  322.   which was previously the biggest gripe.  The only feature I am aware
  323.   of that zsh doesn't have is setting a numerical value for ignoreeof
  324.   --- it's always 10 --- but of course I don't use bash :-).
  325.  
  326.   However, zsh has no claims towards Posix compliancy and will not use
  327.   GNU readline (zle is more powerful).  In fact, bash is intended more
  328.   as an enhanced sh than a ksh work-alike; it doesn't handle [[ ... ]],
  329.   for example.
  330.  
  331.  
  332. 6) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  333.  
  334.   First of all, check you are using the syntax
  335.     alias newcmd='list of commands'
  336.   and not
  337.     alias newcmd 'list of commands'
  338.   which won't work. (It tells you if `newcmd' and `list of commands' are
  339.   already defined as aliases.)
  340.  
  341.   Otherwise, your aliases probably contain references to the command
  342.   line of the form `\!*', etc.  Zsh does not handle this behaviour as it
  343.   has shell functions which provide a way of solving this problem more
  344.   consistent with other forms of argument handling.  For example, the
  345.   csh alias
  346.     alias cd 'cd \!*; echo $cwd'
  347.   can be replaced by the zsh function,
  348.     cd() { builtin cd $*; echo $PWD; }
  349.   (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop)
  350.   or, perhaps better,
  351.     cd() { builtin cd $*; print -D $PWD; }
  352.   (which converts your home directory to a ~).  In fact, this problem is
  353.   better solved by defining the special function chpwd() (see the manual).
  354.   Note also that the `;' at the end of the function is optional in zsh,
  355.   but not in ksh or sh (for sh's where it exists).
  356.  
  357.   Here is Bart Schaefer's guide to converting csh aliases for zsh.
  358.  
  359.     1.  If the csh alias references "parameters" (\!:1 \!* etc.),
  360.         then in zsh you need a function (referencing $1 $* etc.).
  361.         Otherwise, you can use a zsh alias.
  362.  
  363.     2.  If you use a zsh function, you need to refer _at_least_ to
  364.         $* in the body (inside the { }).  Parameters don't magically
  365.         appear inside the { } the way they get appended to an alias.
  366.     
  367.     3.  If the csh alias references its own name (alias rm "rm -i"),
  368.         then in a zsh function you need the "command" keyword
  369.         (function rm() { command rm -i $* }), but in a zsh alias
  370.         you don't (alias rm="rm -i").
  371.  
  372.     4.  If you have aliases that refer to each other (alias ls "ls -C";
  373.         alias lf "ls -F" ==> lf == ls -C -F) then you must either:
  374.         a.  convert all of them to zsh functions; or
  375.         b.  after converting, be sure your .zshrc defines all of your
  376.             aliases before it defines any of your functions.
  377.  
  378.     Those first four are all you really need, but here are four more for
  379.     heavy csh alias junkies:
  380.  
  381.     5.  Mapping from csh alias "parameter referencing" into zsh function
  382.         (assuming shwordsplit is NOT set in zsh):
  383.              csh                   zsh
  384.             =====               ==========
  385.             \!*                 $*              (or $argv)
  386.             \!^                 $1              (or $argv[1])
  387.             \!:1                $1
  388.             \!:2                $2              (or $argv[2], etc.)
  389.             \!$                 $*[$#]          (or $argv[$#], or $*[-1])
  390.             \!:1-4              $*[1,4]
  391.             \!:1-               $*[1,$#-1]      (or $*[1,-2])
  392.             \!^-                $*[1,$#-1]
  393.             \!*:q               "$@"            ($*:q doesn't work (yet))
  394.             \!*:x               $=*             ($*:x doesn't work (yet))
  395.  
  396.     6.  Remember that it is NOT a syntax error in a zsh function to
  397.         refer to a position ($1, $2, etc.) greater than the number of
  398.         parameters. (E.g., in a csh alias, a reference to \!:5 will
  399.         cause an error if 4 or fewer arguments are given; in a zsh
  400.     function, $5 is the empty string if there are 4 or fewer
  401.     parameters.)
  402.  
  403.     7.  To begin a zsh alias with a - (dash, hyphen) character, use
  404.         "alias --":
  405.                  csh                            zsh
  406.             ===============             ==================
  407.             alias - "fg %-"             alias -- -="fg %-"
  408.  
  409.     8.  Stay away from "alias -g" in zsh until you REALLY know what
  410.         you're doing.
  411.  
  412.   There is one other serious problem with aliases: consider
  413.         alias l='/bin/ls -F'
  414.         l() { /bin/ls -la $* | more }
  415.   `l' in the function definition is in command position and is expanded
  416.   as an alias, defining `/bin/ls' and `-F' as functions which call
  417.   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  418.   `function' to define a function, which doesn't expand aliases.  It is
  419.   possible to argue for extra warnings somewhere in this mess.  Luckily,
  420.   it is not possible to define `function' as an alias.
  421.  
  422.  
  423. 7) How do I turn off spelling correction for an individual command?
  424.  
  425.   You presumably have `setopt correctall' in an initialisation file, so
  426.   that zsh checks the spelling of each word in the command line.  You
  427.   probably do not want this behaviour for commands which do not operate
  428.   on existing files.
  429.   
  430.   The answer is to alias the offending command to itself with
  431.   `nocorrect' stuck on the front, e.g.
  432.        alias mkdir='nocorrect mkdir'
  433.  
  434.  
  435. 8) How do I get the meta key to work on my xterm?
  436.  
  437.   As stated in the manual, zsh needs to be told about the meta key by
  438.   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the command
  439.   line.  You probably also need to tell the terminal driver to allow the
  440.   `meta' bit of the character through; `stty pass8' is the usual
  441.   incantation.  Sample .zshrc entry:
  442.     [[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
  443.   or, on SYSVR4-ish systems without pass8,
  444.     [[ $TERM = "xterm" ]] && stty -parenb -istrip cs8 && bindkey -me
  445.   (disable parity detection, don't strip high bit, use 8-bit characters).
  446.   Make sure this comes *before* any bindkey entries in your .zshrc which
  447.   redefine keys normally defined in the emacs/vi keymap.
  448.  
  449.  
  450. 9) Why does my terminal act funny in way x?
  451.  
  452.   If you are using an OpenWindows cmdtool as your terminal, any
  453.   escape sequences (such as those produced by cursor keys) will be
  454.   swallowed up and never reach zsh.  Either use shelltool or avoid
  455.   commands with escape sequences.  You can also disable scrolling from
  456.   the cmdtool pane menu (which effectively turns it into a shelltool).
  457.   If you still want scrolling, try using an xterm with the scrollbar
  458.   activated.
  459.  
  460.   If that's not the problem, and you are using stty to change some tty
  461.   settings, make sure you haven't asked zsh to freeze the tty settings:
  462.   type
  463.     ttyctl -u
  464.   before any stty commands you use.
  465.  
  466.   On the other hand, if you aren't using stty and have problems you may
  467.   need the opposite:  `ttyctl -f' freezes the terminal to protect it
  468.   from hiccups introduced by other programmes (kermit has been known to
  469.   do this).
  470.  
  471.   If _that's_ not the problem, and you are having difficulties with
  472.   external commands (not part of zsh), and you think some terminal
  473.   setting is wrong (e.g. ^V is getting interpreted as `literal next
  474.   character' when you don't want it to be), try
  475.     ttyctl -u
  476.     STTY='lnext "^-"' commandname
  477.   (in this example), or just export STTY for all commands to see.  Note
  478.   that zsh doesn't reset the terminal completely afterwards: just the
  479.   modes it uses itself and a number of special processing characters
  480.   (see the stty(1) manual page).
  481.  
  482.   After the release of version 2.5, there is likely to be an overhaul
  483.   which allows the terminal modes used by the shell to be modified
  484.   separately from those seen by external programmes.  This is partially
  485.   implemented already:  in 2.5, the shell will be less susceptible to
  486.   mode changes inherited from programmes.
  487.  
  488.  
  489. 10) Why does `$var' where var="foo bar" not do what I expect?
  490.  
  491.   In most Bourne-shell derivatives, multi-word variables such as
  492.     var="foo bar"
  493.   are split into words when passed to a command or used in a `for foo in
  494.   $var' loop.  By default, zsh does not have that behaviour: the
  495.   variable remains intact.  (This is not a bug!  See below.)  An option
  496.   (shwordsplit) exists to provide compatibility.
  497.   
  498.   For example, defining the function args to show the number of its
  499.   arguments:
  500.     args() { echo $#; }
  501.   and with our definition of vble,
  502.     args $vble
  503.   produces the output `1'.  After
  504.     setopt shwordsplit
  505.   the same function produces the output `2', as with sh and ksh.
  506.   
  507.   Unless you need strict sh/ksh compatibility, you should ask yourself
  508.   whether you really want this behaviour, as it can produce unexpected
  509.   effects for variables with entirely innocuous embedded spaces.  The
  510.   natural way to produce word-splitting behaviour in zsh is via arrays.
  511.   For example,
  512.     set -A array one two three twenty
  513.   (or
  514.         array=(one two three twenty)
  515.   if you prefer), followed by
  516.     args $array
  517.   produces the output `4', regardless of the setting of shwordsplit.
  518.   Arrays are also much more versatile than single strings.
  519.  
  520.   Note also the "$@" method of word splitting is always available in zsh
  521.   functions and scripts (though strictly this does array splitting, not
  522.   word splitting), also the substitution ${=foo} to toggle word
  523.   splitting on variable `foo'.
  524.  
  525.   Shwordsplit is set when zsh is invoked with the name `ksh'.
  526.  
  527.  
  528. 11) My PATH, (MANPATH, ...) sometimes doesn't handle tildes.  What gives?
  529.  
  530.   The code has recently been overhauled, so take a look at the latest
  531.   version of 2.4beta.  This guarantees that no ~user expansion (or
  532.   =command expansion, which takes place at the same time) will happen if
  533.   the tilde is quoted, and also rationalises PATH-type variables by
  534.   expanding all unquoted assignments as if they are colon-separated
  535.   lists (so you may need to add or subtract a few extra quotes, but the
  536.   results are more predictable).  In addition typeset, etc., now should
  537.   behave like ordinary assignments in this respect; previously tildes in
  538.   typeset assignments were unquotable.
  539.  
  540.  
  541. 12) How does base arithmetic work?
  542.  
  543.   The syntax (e.g. using the `let' builtin is)
  544.     let 'foo = [16]ff'
  545.   (note this is different from ksh, which uses `16#ff'), or equivalently
  546.     (( foo = [16]ff ))
  547.   Then
  548.     echo $foo
  549.   gives the answer `255'.  It is possible to declare variables explicitly
  550.   to be integers, via
  551.     typeset -i foo
  552.   which has a different effect: namely the base used in the first
  553.   assignment (hexadecimal in the example) is subsequently used whenever
  554.   `foo' is displayed (although the internal representation is unchanged).
  555.   To ensure foo is always displayed in decimal, declare it as
  556.     typeset -i 10 foo
  557.   which requests base 10 for output.  You can change the output base of an
  558.   existing variable in this fashion.  Using the `$[ ... ]' method will
  559.   always display in decimal.
  560.  
  561.  
  562. 13) How do I get a newline in my prompt?
  563.  
  564.   You can place a literal newline in quotes, i.e.
  565.     PROMPT="Hi Joe,
  566.     what now?%# "
  567.   If you have the bad taste to set the option cshjunkiequotes, which
  568.   inhibits such behaviour, you will have to bracket this with 
  569.   `unsetopt cshjunkiequotes' and `setopt cshjunkiequotes', or put it in
  570.   your .zshrc before the option is set.
  571.   
  572.   Arguably the prompt code should handle `print'-like escapes.  Feel
  573.   free to right this :-).
  574.  
  575.  
  576. 14) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  577.  
  578.   You probably have the extendedglob option set in which case ^ and #
  579.   are metacharacters.  ^a matches any file except one called a, so the
  580.   line is interpreted as bindkey followed by a list of files.  Quote the
  581.   ^ with a backslash or put quotation marks around ^a.
  582.  
  583.  
  584. 15) How do I execute command `foo' within function `foo'?
  585.  
  586.   The command `command foo' does just that.  You don't need this with
  587.   aliases, but you do with functions.  Note that error messages like
  588.         zsh: job table full or recursion limit exceeded
  589.   are a good sign that you tried calling `foo' in function `foo' without
  590.   using `command'.
  591.  
  592.  
  593. 16) Why can't I get zsh to work with SGI's `userenv'?
  594.  
  595.   It seems the Silicon Graphics `userenv' command interacts weirdly with
  596.   the line editor (zsh is not unique in this respect).  Add this line to
  597.   the top of your .zshenv file:
  598.         if [[ "${ENVONLY:-0}" -eq 1 ]]; then unsetopt zle; fi
  599.   --- which will turn the line editor off if it sees a `userenv' coming.
  600.   Don't turn zle back on with setopt until [[ $ENVONLY -ne 1 ]].
  601.  
  602.  
  603. 17) Why do history substitutions with single bangs do something funny?
  604.  
  605.   If you have a command like "echo !-2:$ !$", the first history
  606.   substitution then sets a default to which later history substitutions
  607.   with single unqualified bangs refer, so that !$ becomes equivalent to
  608.   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
  609.   to the last command.
  610.  
  611.  
  612. 18) Why does zsh kill off all my background jobs when I logout?
  613.  
  614.   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
  615.   you the option of having background jobs killed or not: the `nohup'
  616.   option exists if you don't want them killed.  Note that you can always
  617.   run programs with `nohup' in front of the pipeline whether or not the
  618.   option is set, which will prevent that job from being killed on
  619.   logout.  (Nohup is actually an external command.)
  620.  
  621.   The `disown' builtin is very useful in this respect: if zsh informs
  622.   you that you have background jobs when you try to logout, you can
  623.   `disown' all the ones you don't want killed when you exit.  This is
  624.   also a good way of making jobs you don't need the shell to know about
  625.   (such as commands which create new windows) invisible to the shell.
  626.  
  627.  
  628. 19) I don't have root access: how do I make zsh my login shell?
  629.  
  630.   Unfortunately, on many machines you can't use `chsh' to change your
  631.   shell unless the name of the shell is contained in /etc/shells, so if
  632.   you have your own copy of zsh you need some sleight-of-hand to use it
  633.   when you log on.  (Simply typing `zsh' is not really a solution since
  634.   you still have your original login shell waiting for when you exit.)
  635.   
  636.   The basic idea is to use `exec <zsh-path>' to replace the current
  637.   shell with zsh.  Often you can do this in a login file such as
  638.   .profile (if your shell is sh or ksh) or .login (if it's csh).  Make
  639.   sure you have some way of altering the file (e.g. via FTP) before you
  640.   try this as `exec' is often rather unforgiving.
  641.  
  642.   If you have zsh in a subdirectory `bin' of your home directory,
  643.   put this in .profile:
  644.     [ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
  645.   or if your login shell is csh or tcsh, put this in .login:
  646.     if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
  647.   (in each case the -l tells zsh it is a login shell).  
  648.  
  649.   It's not a good idea to put this (even without the -l) into .cshrc, at
  650.   least without some tests on what the csh is supposed to be doing, as
  651.   that will cause _every_ instance of csh to turn into a zsh and will
  652.   cause csh scripts (yes, unfortunately some people write these) which
  653.   do not call `csh -f' to fail.  If you want to tell xterm to run zsh,
  654.   change the SHELL environment variable to the full path of zsh at the
  655.   same time as you exec zsh.  If you have to exec zsh from your .cshrc,
  656.   a minimum safety check is `if ($?prompt) exec zsh'.
  657.  
  658.   If you like your login shell to appear in the process list as '-zsh',
  659.   you can link zsh to -zsh (e.g. by `ln -s ~/bin/zsh ~/bin/-zsh') and
  660.   change the exec to `exec -zsh'.  (Make sure -zsh is in your path.)
  661.   This has the same effect as the `-l' option.
  662.  
  663.   Footnote: if you DO have root access, make sure zsh goes in
  664.   /etc/shells on all appropriate machines, including NIS clients, or you
  665.   may have problems with FTP to that machine.
  666.  
  667.  
  668. 20) Shouldn't zsh be more/less like ksh/(t)csh?
  669.  
  670.   People often ask why zsh has all these `unnecesary' csh-like features,
  671.   or alternatively why zsh doesn't understand more csh syntax.  This is
  672.   far from a definitive answer and the debate will no doubt continue.
  673.  
  674.   Paul's object in writing zsh was to produce a ksh-like shell which
  675.   would have features familiar to csh users.  For a long time, csh was
  676.   the preferred interactive shell and there is a strong resistance to
  677.   changing to something unfamiliar, hence the additional syntax and
  678.   csh_junkie options.  This argument still holds.  On the other hand,
  679.   the arguments for having what is close to a plug-in replacement for ksh
  680.   are, if anything, even more powerful:  the deficiencies of csh as a
  681.   programming language are well known (FTP convex.com:pub/csh.whynot
  682.   if you are in any doubt) and zsh is able to run many standard scripts
  683.   such as /etc/rc.
  684.   
  685.   Of course, this makes zsh rather large and quite messy so that it
  686.   seems to appeal mainly to hackers.  The only answer, perhaps not
  687.   entirely satisfactory, is that you have to ignore the bits you don't
  688.   want.
  689.  
  690.  
  691. 21) What bugs are currently known and unfixed?
  692.  
  693.   Here are some of the more well-known ones, very roughly in decreasing
  694.   order of significance.  A fuller bug list is now maintained by Carlos
  695.   Carvalho <carlos@snfep1.if.usp.br>.  Many of these can also be counted
  696.   against differences from ksh in question 5); note that this applies to
  697.   the latest beta version and that simple bugs are often fixed quite
  698.   quickly.
  699.  
  700.   Pipelines ending in a while/until/for loop are uninterruptible.
  701.   Certain built-ins won't allow the `VAR=value command ...' assignment;
  702.     the ones that do don't unset VAR after use (may not really be a bug).
  703.     (N.B.: `exec foo=bar command' is a workaround for exec.)
  704.   The `histlit' option adds newlines to lines in the history
  705.     (and is broken in several other ways, e.g. !:x word selection;
  706.     it may be removed).
  707.   `time' is ignored with builtins and can't be used with {...} or (...);
  708.     in shells with no job control the command name is blank.
  709.   `set -x' (`setopt xtrace') doesn't show as much as it should.
  710.   The line number of errors inside control structures is always given
  711.     as the end of the structure (i.e. at `fi', `done', etc.).
  712.   $_ returns the last unexpanded word from the previous line (not command).
  713.   The :q modifier doesn't split words and -q and -x don't work for variables.
  714.   In vi mode, `u' can go past the original modification point.
  715.   Autocd won't use globbed filenames.
  716.   Linked directories can sometimes confuse zsh's idea of its cwd.
  717.   Still problems under SCO Unix (a patch exists but hasn't been merged yet).
  718.   The singlelinezle option has problems with prompts containing escapes.
  719.   SIGHUP cannot be trapped.
  720.  
  721.   Note that a few recent changes introduce incompatibilities (these are
  722.   not bugs): the -h option to compctl has been removed (use `-k hosts'
  723.   for the same effect); automatic handling of hosts after '@' has been
  724.   removed (use e.g. `compctl -u -x "n[-1,@]" -k hosts -- finger');
  725.   handling of backslashes in `echo' and `print' has changed.
  726.  
  727.   There is at least one common bug which is not due to zsh.  If you have
  728.   abnormal behaviour with file descriptor 4, it's because your password
  729.   database is being read from the Network Information System and
  730.   getpwent() left this fd open.
  731.  
  732.  
  733. 22) Where do I report bugs, get more info / who's working on zsh?
  734.  
  735.   The shell is being maintained by various (entirely self-appointed)
  736.   subscribers to the mailing list,
  737.     zsh-list@sterling.com so any suggestions, complaints,
  738.   questions and matters for discussion should be sent there.  If you
  739.   want someone to mail you directly, say so.  Most patches to zsh appear
  740.   there first.
  741.   
  742.   A lower-volume list,
  743.     zsh-announce@sterling.com
  744.   exists for announcements of new features and proposed changes
  745.   requiring some decisions.
  746.  
  747.   Both lists are handled by an automated server.  The instructions for
  748.   zsh-announce are the same as for zsh-list: just change zsh-list to
  749.   zsh-announce everywhere in the following.
  750.  
  751.   To join zsh-list, send email to
  752.     Majordomo@sterling.com
  753.   containing
  754.     subscribe zsh-list <optional-address>
  755.   where <optional-address> can be blank if you want to subscribe from
  756.   your current email address.  Send the message `help' to the same
  757.   address for help on the list server; `unsubscribe zsh-list' also
  758.   works. (Don't send this to the list!) The list manager, Rick Ohnemus,
  759.   can be reached at
  760.     owner-zsh-list@sterling.com
  761.   (or `rick' at the same adress).
  762.  
  763.   The list (everything since May 1992) is archived in
  764.     ftp.sterling.com:zsh/zsh-list/YY-MM
  765.   where YY-MM are the year and month in digits.
  766.  
  767.  
  768. 23) What's on the wish-list?
  769.  
  770.   Ksh/sh compatibility could be improved if required.  This would
  771.     be a useful long term goal.
  772.   Option for glob qualifiers to follow perl syntax.
  773.   Option to quote !-history lexically via '' but not "".
  774.   Binding of shell functions (or commands?) to key strokes --
  775.     requires some way of accessing the editing buffer from functions
  776.     and probably of executing zle functions as a command.
  777.   trap '...' FOO should be eval'd rather than called as a function.
  778.   `PATH=' should clear the PATH:  it inserts `.'; use `unset PATH' or
  779.     `path=()' for the time being.  This is not really a bug as the .
  780.     would be used internally in any case (cf. ksh).
  781.   Users should be able to create their own foopath/FOOPATH array/path
  782.     combinations.
  783.   The introduction to zsh (intro.*) could do with an update to reflect
  784.     extended completion (in particular) and other recent additions.
  785.  
  786.  
  787. Acknowledgments:
  788.  
  789. Thanks to zsh-list, in particular Bart Schaefer, for suggestions
  790. regarding this document; thanks to Jim Mattson and more recently Bas de
  791. Bakker for their hard work as archivists, and to Peter Gray for
  792. maintaining the mailing list, without which zsh might easily have died,
  793. and to the latest list maintainer, Rick Ohnemus.  The world is eternally
  794. in the debt of Paul Falstad for inventing zsh in the first place.
  795.  
  796. -- 
  797. Peter Stephenson <P.Stephenson@swan.ac.uk> or <PWS@UKACRL> (BITNET)
  798. Department of Physics, University College of Swansea
  799. Singleton Park, Swansea, SA2 8PP, U.K.
  800. Tel. +44 792 205678 extn. 4461
  801.