Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Z-Shell (zsh) FAQ changes this month



This file contains general information on how to find out about zsh,
(the first part of the FAQ up to item 1.1), then any other items which
have changed since last month's posting, then the differences in the
text version of the FAQ.  If you would like a complete individual
copy, email me and I will add you to the list.

The diff this time is quite large because of numbering changes; questions
which only have changed numbers are not included in full.


Changes since issue posted January 1999:

1.1  deleted the bit saying startup files are not mentioned.
3.2  New: about startup files.
3.7  we just found the PRINT_EIGHT_BIT option again...
3.22 New: about ${(e)...} and ${${...}}.
5.2  (In wishlist): patch exists for 3.1 to handle tying
     texinputs/TEXINPUTS etc.

This document contains a list of frequently-asked (or otherwise
significant) questions concerning the Z-shell, a command interpreter
for many UNIX systems which is freely available to anyone with FTP
access.  Zsh is among the most powerful freely available Bourne-like
shell for interactive use.

If you have never heard of `sh', `csh' or `ksh', then you are
probably better off to start by reading a general introduction to UNIX
rather than this document.

If you just want to know how to get your hands on the latest version,
skip to question 1.6; if you want to know what to do with
insoluble problems, go to 5.2.

Notation: Quotes `like this' are ordinary textual quotation
marks.  Other uses of quotation marks are input to the shell.

Contents:
Chapter 1:  Introducing zsh and how to install it
1.1. Sources of information
1.2. What is it?
1.3. What is it good at?
1.4. On what machines will it run?  (Plus important compilation notes)
1.5. What's the latest version?
1.6. Where do I get it?
1.7. I don't have root access: how do I make zsh my login shell?

Chapter 2:  How does zsh differ from...?
2.1. sh and ksh?
2.2. csh?
2.3. Why do my csh aliases not work?  (Plus other alias pitfalls.)
2.4. tcsh?
2.5. bash?
2.6. Shouldn't zsh be more/less like ksh/(t)csh?

Chapter 3:  How to get various things to work
3.1. Why does `$var' where `var="foo bar"' not do what I expect?
3.2. In which startup file do I put...?
3.3. What is the difference between `export' and the ALL_EXPORT option?
3.4. How do I turn off spelling correction/globbing for a single command?
3.5. How do I get the meta key to work on my xterm?
3.6. How do I automatically display the directory in my xterm title bar?
3.7. How do I make the completion list use eight bit characters?
3.8. Why do the cursor (arrow) keys not work?
3.9. Why does my terminal act funny in some way?
3.10. Why does zsh not work in an Emacs shell mode any more?
3.11. Why do my autoloaded functions not autoload [the first time]?
3.12. How does base arithmetic work?
3.13. How do I get a newline in my prompt?
3.14. Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
3.15. Why can't I bind \C-s and \C-q any more?
3.16. How do I execute command `foo' within function `foo'?
3.17. Why do history substitutions with single bangs do something funny?
3.18. Why does zsh kill off all my background jobs when I logout?
3.19. How do I list all my history entries?
3.20. How does the alternative loop syntax, e.g. `while {...} {...}' work?
3.21. Why is my history not being saved?
3.22. How do I get a variable's value to be evaluated as another variable?

Chapter 4:  The mysteries of completion
4.1. What is completion?
4.2. What sorts of things can be completed?
4.3. How does zsh deal with ambiguous completions?
4.4. How do I complete in the middle of words / just what's before the cursor?
4.5. How do I get started with programmable completion?
4.6. And if programmable completion isn't good enough?

Chapter 5:  The future of zsh
5.1. What bugs are currently known and unfixed? (Plus recent important changes)
5.2. Where do I report bugs, get more info / who's working on zsh?
5.3. What's on the wish-list?
5.4. Will zsh have problems in the year 2000?

Acknowledgments

Copyright
--- End of Contents ---

Chapter 1: Introducing zsh and how to install it

1.1: Sources of information

  Information on zsh is available via the World Wide Web.  The URL
  is http://sunsite.auc.dk/zsh/ (note the change of address from the
  end of April 1998).  The server provides this FAQ and much else and is
  now maintained by Karsten Thygesen and others (mail zsh@xxxxxxxxxxxxxx
  with any related messages).  The FAQ is at http://sunsite.auc.dk/zsh/FAQ/ .
  The site also contains some contributed zsh scripts and functions;
  we are delighted to add more, or simply links to your own collection.

  This document was originally written in YODL, allowing it to be
  converted easily into various other formats.  The master source
  file lives at http://sunsite.auc.dk/zsh/FAQ/zshfaq.yo .

  Another useful source of information is the collection of FAQ articles
  posted frequently to the Usenet news groups comp.unix.questions,
  comp.unix.shells and comp.answers with answers to general questions
  about UNIX.  The fifth of the seven articles deals with shells,
  including zsh, with a brief description of differences.  There is
  also a separate FAQ on shell differences and how to change your
  shell.  Usenet FAQs are available via FTP from rtfm.mit.edu and
  mirrors and also on the World Wide Web; see

    USA         http://www.cis.ohio-state.edu/hypertext/faq/usenet/top.html
    UK          http://www.lib.ox.ac.uk/internet/news/faq/comp.unix.shell.html
    Netherlands http://www.cs.uu.nl/wais/html/na-dir/unix-faq/shell/.html

  You can also get it via email by emailing mail-server@xxxxxxxxxxxx
  with, in the body of the message, `send faqs/unix-faq/shell/zsh'.

  The latest version of this FAQ is also available directly from any
  of the zsh archive sites listed in question 1.6.

  There is now a preliminary version of a reference card for
  zsh 3.0, which you can find (while it's being developed) at
    http://www.ifh.de/~pws/computing/refcard.ps
  This is optimised for A4 paper. The LaTeX source is in the
  same place with the extension .tex.  It is not a good place
  from which to learn zsh for the first time.

  (As a method of reading the following in Emacs, you can type \M-2
  \C-x $ to make all the indented text vanish, then \M-0 \C-x $
  when you are on the title you want.)

  For any more eclectic information, you should contact the mailing
  list:  see question 5.2.

--- End of general information, changed items follow in full ---

3.2: In which startup file do I put...?

  When zsh starts up, there are four files you can change which it will
  run under various circumstances: .zshenv, .zprofile, .zshrc
  and .zlogin.  They are usually in your home directory, but the
  variable $ZDOTDIR may be set to alter that.  Here are a few simple
  hints about how to use them.  There are also files which the system
  administrator can set for all shells; you can avoid running all except
  /etc/zshenv by starting zsh with the -f option --- for this
  reason it is important for administrators to make sure /etc/zshenv
  is as brief as possible.

  The order in which the four files are searched (none of them _need_
  to exist) is the one just given.  However, .zprofile and .zlogin
  are only run when the shell is a login shell --- when you first login,
  of course, and whenever you start zsh with the -l option.  All
  login shells are interactive.  The order is the only difference
  between those; you should decide whether you need things set before or
  after .zshrc.  These files are a good place to set environment
  variables (i.e. `export' commands), since they are passed on to
  all shells without you having to set them again, and also to check
  that your terminal is set up properly (except that if you want to
  change settings for terminal emulator windows like xterm you will
  need to put those in .zshrc, since usually you do not get a login
  shell here).  

  The only file you can alter which is started with every zsh (unless
  you use the -f option) is .zshenv, so this is a good place to put
  things you want even if the shell is non-interactive: options for
  changing the the syntax, like EXTENDED_GLOB, any changes to set with
  `limit', any more variables you want to make sure are set as for
  example $fpath to find functions.  You almost certainly do not
  want .zshenv to produce any output.  Some people prefer not to
  use .zshenv for setting options, as this affects scripts; but
  making zsh scripts portable usually requires special handling anyway.

  Finally, .zshrc is run for every interactive shell; that includes
  login shells, but also any other time you start up a shell, such as
  simply by typing `zsh' or opening a new terminal emulator window.
  This file is the place to change the editing behaviour via options or
  `bindkey', control how your history is saved, set aliases unless
  you want to use them in scripts too, and for any other clutter which
  can't be exported but you only use when interacting directly with the
  shell.  You probably don't want .zshrc to produce output, either,
  since there are occasions when this can be a problem, such as when
  using `rsh' from another host.  See 3.21 for what to put in .zshrc
  to save your history.

3.7: How do I make the completion list use eight bit characters?

  If you are sure your terminal handles this, the easiest way is to
  set the option PRINT_EIGHT_BIT.  In principle, this will work
  automatically if your computer uses the `locale' system and your
  locale variables are set properly, as zsh understands this.
  However, it is quite complicated, so if it isn't already set up,
  trying the option is a lot easier.

3.22: How do I get a variable's value to be evaluated as another variable?

  The problem is that you have a variable $E containing the string
  `EDITOR', and a variable $EDITOR containing the string `emacs',
  or something such.  How do you get from $E to emacs in one easy
  stage?

  There is no standard single-stage way of doing this.  However, there
  is a zsh idiom (available in all versions of zsh since 5.0) for this:

    print ${(e)E:+\$$E}

  Ignore the `(e)' for now.  The `:+' means: if the variable
  $E is set, substitute the following, i.e. `\$$E'.  This is
  expanded to `$EDITOR' by the normal rules.  Finally, the `(e)' means:
  evaluate the expression you just made.  This gives `emacs'.

  For a standard shell way of doing this, you are stuck with `eval':

    eval echo \$$E

  produces the same result.

  Future versions of zsh will probably allow you to do this directly,
  with a new flag; `${(P)E}'.

  As a slight aside, sometimes people note that the syntax `${${E}}'
  is valid and expect it to have this effect.  It probably ought to, but
  in the early days of zsh it was found convenient to have this way of
  producing different substitutions on the same parameter; for example,
  `${${file##**/}%.*}' removes everything up to the last slash in
  `$file', then everything from the last dot on, inclusive (try
  it, this works).  So in `${${E}}', the internal `${...}'
  actually does nothing.

5.3: What's on the wish-list?

  With version 3, the code is much cleaner than before, but still
  bears the marks of the ages and many things could be done much
  better with a rewrite.  A more efficient set of code for
  lexing/parsing/execution might also be an advantage.  Volunteers are
  particularly welcome for these tasks.

  An improved line editor, with user-definable functions and binding
  of multiple functions to keystrokes, is being developed.

  o  Loadable module support (will be in 3.1 but much work still needs
     doing).
  o  Ksh compatibility could be improved.
  o  Option for glob qualifiers to follow perl syntax (a traditional item).
  o  Binding of shell functions to key strokes, accessing editing
     buffer from functions, executing zle functions as a command:  now
     under development for 3.1. 
  o  Users should be able to create their own foopath/FOOPATH array/path
     combinations (now exists as a patch for 3.1).

--- End of changed items, diff from previous version follows ---
Index: zshfaq.txt
===================================================================
RCS file: /pack/anoncvs/zsh/www/FAQ/zshfaq.txt,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- zshfaq.txt	1999/01/25 09:27:49	1.9
+++ zshfaq.txt	1999/02/25 10:03:06	1.10
@@ -1,16 +1,19 @@
 
 Archive-Name: unix-faq/shell/zsh
-Last-Modified: 1999/01/25
+Last-Modified: 1999/02/05
 Submitted-By: pws@xxxxxxxxxxxxxxxxx (Peter Stephenson)
-Version: $Id: zshfaq.txt,v 1.9 1999/01/25 09:27:49 pws Exp $
+Version: $Id: zshfaq.txt,v 1.10 1999/02/25 10:03:06 pws Exp $
 Posting-Frequency: Monthly
-Copyright: (C) P.W. Stephenson, 1995, 1996, 1997, 1998, 1999 (see end of document)
+Copyright: (C) P.W. Stephenson, 1995--1999 (see end of document)
 
-Changes since issue posted December 1998:
+Changes since issue posted January 1999:
 
-2.1  Finally point out function definitions are not local to
-     functions (they never were).
-5.2  Mailing list location has changed.
+1.1  deleted the bit saying startup files are not mentioned.
+3.2  New: about startup files.
+3.7  we just found the PRINT_EIGHT_BIT option again...
+3.22 New: about ${(e)...} and ${${...}}.
+5.2  (In wishlist): patch exists for 3.1 to handle tying
+     texinputs/TEXINPUTS etc.
 
 This document contains a list of frequently-asked (or otherwise
 significant) questions concerning the Z-shell, a command interpreter
@@ -49,25 +52,27 @@
 
 Chapter 3:  How to get various things to work
 3.1. Why does `$var' where `var="foo bar"' not do what I expect?
-3.2. What is the difference between `export' and the ALL_EXPORT option?
-3.3. How do I turn off spelling correction/globbing for a single command?
-3.4. How do I get the meta key to work on my xterm?
-3.5. How do I automatically display the directory in my xterm title bar?
-3.6. How do I make the completion list use eight bit characters?
-3.7. Why do the cursor (arrow) keys not work?
-3.8. Why does my terminal act funny in some way?
-3.9. Why does zsh not work in an Emacs shell mode any more?
-3.10. Why do my autoloaded functions not autoload [the first time]?
-3.11. How does base arithmetic work?
-3.12. How do I get a newline in my prompt?
-3.13. Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
-3.14. Why can't I bind \C-s and \C-q any more?
-3.15. How do I execute command `foo' within function `foo'?
-3.16. Why do history substitutions with single bangs do something funny?
-3.17. Why does zsh kill off all my background jobs when I logout?
-3.18. How do I list all my history entries?
-3.19. How does the alternative loop syntax, e.g. `while {...} {...}' work?
-3.20. Why is my history not being saved?
+3.2. In which startup file do I put...?
+3.3. What is the difference between `export' and the ALL_EXPORT option?
+3.4. How do I turn off spelling correction/globbing for a single command?
+3.5. How do I get the meta key to work on my xterm?
+3.6. How do I automatically display the directory in my xterm title bar?
+3.7. How do I make the completion list use eight bit characters?
+3.8. Why do the cursor (arrow) keys not work?
+3.9. Why does my terminal act funny in some way?
+3.10. Why does zsh not work in an Emacs shell mode any more?
+3.11. Why do my autoloaded functions not autoload [the first time]?
+3.12. How does base arithmetic work?
+3.13. How do I get a newline in my prompt?
+3.14. Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
+3.15. Why can't I bind \C-s and \C-q any more?
+3.16. How do I execute command `foo' within function `foo'?
+3.17. Why do history substitutions with single bangs do something funny?
+3.18. Why does zsh kill off all my background jobs when I logout?
+3.19. How do I list all my history entries?
+3.20. How does the alternative loop syntax, e.g. `while {...} {...}' work?
+3.21. Why is my history not being saved?
+3.22. How do I get a variable's value to be evaluated as another variable?
 
 Chapter 4:  The mysteries of completion
 4.1. What is completion?
@@ -108,11 +113,10 @@
   posted frequently to the Usenet news groups comp.unix.questions,
   comp.unix.shells and comp.answers with answers to general questions
   about UNIX.  The fifth of the seven articles deals with shells,
-  including zsh, with a brief description of differences.  (This article
-  also talks about shell startup files which would otherwise rate a
-  mention here.)  There is also a separate FAQ on shell differences
-  and how to change your shell.  Usenet FAQs are available via FTP
-  from rtfm.mit.edu and mirrors and also on the World Wide Web; see
+  including zsh, with a brief description of differences.  There is
+  also a separate FAQ on shell differences and how to change your
+  shell.  Usenet FAQs are available via FTP from rtfm.mit.edu and
+  mirrors and also on the World Wide Web; see
 
     USA         http://www.cis.ohio-state.edu/hypertext/faq/usenet/top.html
     UK          http://www.lib.ox.ac.uk/internet/news/faq/comp.unix.shell.html
@@ -270,6 +274,7 @@
               http://www.math.technion.ac.il/mirror/ftp.zsh.org/pub/zsh/
     Japan     ftp://ftp.tohoku.ac.jp/mirror/zsh/
               ftp://ftp.nis.co.jp/pub/shells/zsh/
+              ftp://ftp.win.ne.jp/pub/shell/zsh/
     Norway    ftp://ftp.uit.no/pub/unix/shells/zsh/
     Romania   ftp://ftp.roedu.net/pub/mirrors/ftp.zsh.org/pub/zsh/
     Slovenia  ftp://ftp.siol.net/pub/unix/shells/zsh/
@@ -840,8 +845,56 @@
   or (entirely equivalent) when `emulate ksh' or `emulate sh' is in
   effect.
 
-3.2: What is the difference between `export' and the ALL_EXPORT option?
+3.2: In which startup file do I put...?
 
+  When zsh starts up, there are four files you can change which it will
+  run under various circumstances: .zshenv, .zprofile, .zshrc
+  and .zlogin.  They are usually in your home directory, but the
+  variable $ZDOTDIR may be set to alter that.  Here are a few simple
+  hints about how to use them.  There are also files which the system
+  administrator can set for all shells; you can avoid running all except
+  /etc/zshenv by starting zsh with the -f option --- for this
+  reason it is important for administrators to make sure /etc/zshenv
+  is as brief as possible.
+
+  The order in which the four files are searched (none of them _need_
+  to exist) is the one just given.  However, .zprofile and .zlogin
+  are only run when the shell is a login shell --- when you first login,
+  of course, and whenever you start zsh with the -l option.  All
+  login shells are interactive.  The order is the only difference
+  between those; you should decide whether you need things set before or
+  after .zshrc.  These files are a good place to set environment
+  variables (i.e. `export' commands), since they are passed on to
+  all shells without you having to set them again, and also to check
+  that your terminal is set up properly (except that if you want to
+  change settings for terminal emulator windows like xterm you will
+  need to put those in .zshrc, since usually you do not get a login
+  shell here).  
+
+  The only file you can alter which is started with every zsh (unless
+  you use the -f option) is .zshenv, so this is a good place to put
+  things you want even if the shell is non-interactive: options for
+  changing the the syntax, like EXTENDED_GLOB, any changes to set with
+  `limit', any more variables you want to make sure are set as for
+  example $fpath to find functions.  You almost certainly do not
+  want .zshenv to produce any output.  Some people prefer not to
+  use .zshenv for setting options, as this affects scripts; but
+  making zsh scripts portable usually requires special handling anyway.
+
+  Finally, .zshrc is run for every interactive shell; that includes
+  login shells, but also any other time you start up a shell, such as
+  simply by typing `zsh' or opening a new terminal emulator window.
+  This file is the place to change the editing behaviour via options or
+  `bindkey', control how your history is saved, set aliases unless
+  you want to use them in scripts too, and for any other clutter which
+  can't be exported but you only use when interacting directly with the
+  shell.  You probably don't want .zshrc to produce output, either,
+  since there are occasions when this can be a problem, such as when
+  using `rsh' from another host.  See 3.21 for what to put in .zshrc
+  to save your history.
+
+3.3: What is the difference between `export' and the ALL_EXPORT option?
+
   Normally, you would put a variable into the environment by using
   `export var'.  The command `setopt allexport' causes all
   variables which are subsequently set (N.B. not all the ones which
@@ -865,7 +918,7 @@
   it immediately afterwards.  Only those variables will be automatically
   exported.
 
-3.3: How do I turn off spelling correction/globbing for a single command?
+3.4: How do I turn off spelling correction/globbing for a single command?
 
   In the first case, you presumably have `setopt correctall' in an
   initialisation file, so that zsh checks the spelling of each word in
@@ -888,7 +941,7 @@
   Note also that a shell function won't work: the no... directives must
   be expanded before the rest of the command line is parsed.
 
-3.4: How do I get the meta key to work on my xterm?
+3.5: How do I get the meta key to work on my xterm?
 
   As stated in the manual, zsh needs to be told about the meta key by
   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the
@@ -909,7 +962,7 @@
   You don't need the `bindkey' to be able to define your own sequences
   with the meta key, though you still need the `stty'.
 
-3.5: How do I automatically display the directory in my xterm title bar?
+3.6: How do I automatically display the directory in my xterm title bar?
 
   You should use the special function `chpwd', which is called when
   the directory changes.  The following checks that standard output is
@@ -933,38 +986,16 @@
   when the xterm starts up you will probably want to call chpwd
   directly: just put `chpwd' in .zshrc after it is defined or autoloaded.
 
-3.6: How do I make the completion list use eight bit characters?
+3.7: How do I make the completion list use eight bit characters?
 
-  A traditional UNIX environment (character terminal and ASCII
-  character sets) is not sufficient to be able to handle non-ASCII
-  characters, and there are so many possible enhancements that in
-  general this is hard.  However, if you have something like an xterm
-  using a standard character set like ISO-8859-1 (which is often the
-  default for xterm), read on.  You should also note question
-  3.4 on the subject of eight bit characters.
-
-  You are probably creating files with names including non-ASCII
-  accented characters, and find they show up in the completion list as
-  \M-i or something such.  This is because the library routines
-  (not zsh itself) which test whether a character is printable have
-  replied that it is not; zsh has simply found a way to show them
-  anyway.
-
-  The answer, under a modern POSIXy operating system, is to find a
-  locale where these are treated as printable characters.  Zsh has
-  handling for locales built in and will recognise when you set a
-  relevant variable. You need to look in /usr/lib/locale to find one
-  which suits you; the subdirectories correspond to the locale names.
-  The simplest possibility is likely to be en_US, so that the simplest
-  answer to your problem is to set
-
-    LC_CTYPE=en_US
-
-  when your terminal is capable of showing eight bit characters.  If
-  you only have a default domain (called C), you may need to have some
-  additional files installed on your system.
+  If you are sure your terminal handles this, the easiest way is to
+  set the option PRINT_EIGHT_BIT.  In principle, this will work
+  automatically if your computer uses the `locale' system and your
+  locale variables are set properly, as zsh understands this.
+  However, it is quite complicated, so if it isn't already set up,
+  trying the option is a lot easier.
 
-3.7: Why do the cursor (arrow) keys not work?
+3.8: Why do the cursor (arrow) keys not work?
 
   The cursor keys send different codes depending on the terminal; zsh
   only binds the most well known versions.  If you see these problems,
@@ -985,7 +1016,7 @@
   B, C or D, as well as the corresponding set beginning
   `<ESC>[', so this may be redundant.
 
-3.8: Why does my terminal act funny in some way?
+3.9: Why does my terminal act funny in some way?
 
   If you are using an OpenWindows cmdtool as your terminal, any
   escape sequences (such as those produced by cursor keys) will be
@@ -1027,7 +1058,7 @@
   the shell is less susceptible to mode changes inherited from
   programmes than it used to be.
 
-3.9: Why does zsh not work in an Emacs shell mode any more?
+3.10: Why does zsh not work in an Emacs shell mode any more?
 
   (This information comes from Bart Schaefer and other zsh-workers.)
 
@@ -1056,7 +1087,7 @@
 
   to ~/.emacs.
 
-3.10: Why do my autoloaded functions not autoload [the first time]?
+3.11: Why do my autoloaded functions not autoload [the first time]?
 
   The problem is that there are two possible ways of autoloading a
   function (see the AUTOLOADING FUNCTIONS section of the zsh manual
@@ -1100,7 +1131,7 @@
   parentheses removes the directory part of the filenames, leaving
   just the function names.)
 
-3.11: How does base arithmetic work?
+3.12: How does base arithmetic work?
 
   The ksh syntax is now understood, i.e.
 
@@ -1139,7 +1170,7 @@
   existing variable in this fashion.  Using the `$(( ... ))' method will
   always display in decimal.
 
-3.12: How do I get a newline in my prompt?
+3.13: How do I get a newline in my prompt?
 
   You can place a literal newline in quotes, i.e.
 
@@ -1158,14 +1189,14 @@
 
   in your initialisation file.
 
-3.13: Why does `bindkey ^a command-name' or `stty intr ^-' do something funny?
+3.14: Why does `bindkey ^a command-name' or `stty intr ^-' do something funny?
 
   You probably have the extendedglob option set in which case ^ and #
   are metacharacters.  ^a matches any file except one called a, so the
   line is interpreted as bindkey followed by a list of files.  Quote the
   ^ with a backslash or put quotation marks around ^a.
 
-3.14: Why can't I bind \C-s and \C-q any more?
+3.15: Why can't I bind \C-s and \C-q any more?
 
   The control-s and control-q keys now do flow control by default,
   unless you have turned this off with `stty -ixon' or redefined the
@@ -1178,7 +1209,7 @@
   control and hence restoring the use of the keys: put `setopt
   noflowcontrol' in your .zshrc file.
 
-3.15: How do I execute command `foo' within function `foo'?
+3.16: How do I execute command `foo' within function `foo'?
 
   The command `command foo' does just that.  You don't need this with
   aliases, but you do with functions.  Note that error messages like
@@ -1189,7 +1220,7 @@
   using `command'.  If `foo' is a builtin rather than an external
   command, use `builtin foo' instead.
 
-3.16: Why do history substitutions with single bangs do something funny?
+3.17: Why do history substitutions with single bangs do something funny?
 
   If you have a command like "echo !-2:$ !$", the first history
   substitution then sets a default to which later history substitutions
@@ -1197,7 +1228,7 @@
   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
   to the last command.
 
-3.17: Why does zsh kill off all my background jobs when I logout?
+3.18: Why does zsh kill off all my background jobs when I logout?
 
   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
   you the option of having background jobs killed or not: the `nohup'
@@ -1214,12 +1245,12 @@
   Likewise, you can start a background job with `&!' instead of just
   `&' at the end, which will automatically disown the job.
 
-3.18: How do I list all my history entries?
+3.19: How do I list all my history entries?
 
   Tell zsh to start from entry 1: `history 1'.  Those entries at the
   start which are no longer in memory will be silently omitted.
 
-3.19: How does the alternative loop syntax, e.g. `while {...} {...}' work?
+3.20: How does the alternative loop syntax, e.g. `while {...} {...}' work?
 
   Zsh provides an alternative to the traditional sh-like forms with `do',
 
@@ -1274,7 +1305,7 @@
   manual), which you are in any case encouraged even more strongly not
   to use in programs as it can be very confusing.
 
-3.20: Why is my history not being saved?
+3.21: Why is my history not being saved?
 
   In zsh, you need to set three variables to make sure your history is
   written out when the shell exits.  For example,
@@ -1290,6 +1321,41 @@
   above.  There are also various options affecting history; see the
   manual.
 
+3.22: How do I get a variable's value to be evaluated as another variable?
+
+  The problem is that you have a variable $E containing the string
+  `EDITOR', and a variable $EDITOR containing the string `emacs',
+  or something such.  How do you get from $E to emacs in one easy
+  stage?
+
+  There is no standard single-stage way of doing this.  However, there
+  is a zsh idiom (available in all versions of zsh since 5.0) for this:
+
+    print ${(e)E:+\$$E}
+
+  Ignore the `(e)' for now.  The `:+' means: if the variable
+  $E is set, substitute the following, i.e. `\$$E'.  This is
+  expanded to `$EDITOR' by the normal rules.  Finally, the `(e)' means:
+  evaluate the expression you just made.  This gives `emacs'.
+
+  For a standard shell way of doing this, you are stuck with `eval':
+
+    eval echo \$$E
+
+  produces the same result.
+
+  Future versions of zsh will probably allow you to do this directly,
+  with a new flag; `${(P)E}'.
+
+  As a slight aside, sometimes people note that the syntax `${${E}}'
+  is valid and expect it to have this effect.  It probably ought to, but
+  in the early days of zsh it was found convenient to have this way of
+  producing different substitutions on the same parameter; for example,
+  `${${file##**/}%.*}' removes everything up to the last slash in
+  `$file', then everything from the last dot on, inclusive (try
+  it, this works).  So in `${${E}}', the internal `${...}'
+  actually does nothing.
+
 Chapter 4: The mysteries of completion
 
 Programmable completion using the `compctl' command is one of the most
@@ -1768,14 +1834,15 @@
   An improved line editor, with user-definable functions and binding
   of multiple functions to keystrokes, is being developed.
 
-  o  Loadable module support (will be in 3.1 but much work still needs doing).
+  o  Loadable module support (will be in 3.1 but much work still needs
+     doing).
   o  Ksh compatibility could be improved.
   o  Option for glob qualifiers to follow perl syntax (a traditional item).
   o  Binding of shell functions to key strokes, accessing editing
      buffer from functions, executing zle functions as a command:  now
      under development for 3.1. 
   o  Users should be able to create their own foopath/FOOPATH array/path
-     combinations.
+     combinations (now exists as a patch for 3.1).
 
 5.4: Will zsh have problems in the year 2000?
 



Messages sorted by: Reverse Date, Date, Thread, Author