home *** CD-ROM | disk | FTP | other *** search
/ Danny Amor's Online Library / Danny Amor's Online Library - Volume 1.iso / html / faqs / faq / unix-faq / shell.zsh < prev    next >
Encoding:
Text File  |  1995-07-25  |  38.7 KB  |  851 lines

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