From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2018 invoked from network); 19 Dec 1998 14:14:31 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 19 Dec 1998 14:14:31 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id JAA17813; Sat, 19 Dec 1998 09:10:00 -0500 (EST) Resent-Date: Sat, 19 Dec 1998 08:45:42 -0500 (EST) Message-Id: <9812191328.AA46320@ibmth.df.unipi.it> To: zsh-announce@math.gatech.edu Subject: Z-Shell (zsh) FAQ changes this month Date: Sat, 19 Dec 1998 14:28:34 +0100 From: Peter Stephenson Resent-Message-ID: <"DRTOP1.0.164.PtwUs"@math> Resent-From: zsh-announce@math.gatech.edu X-Mailing-List: archive/latest/90 X-Loop: zsh-announce@math.gatech.edu X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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. Changes since issue posted November 1998: 1.1 Mention email FAQ server 2.3 Restore missing double quote in cd() function 3.1 Mention ${==*} to turn off SHWORDSPLIT 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. 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? 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@sunsite.auc.dk 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. (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 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@rtfm.mit.edu 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 --- 2.3: Why do my csh aliases not work? (Plus other alias pitfalls.) First of all, check you are using the syntax alias newcmd='list of commands' and not alias newcmd 'list of commands' which won't work. (It tells you if `newcmd' and `list of commands' are already defined as aliases.) Otherwise, your aliases probably contain references to the command line of the form `\!*', etc. Zsh does not handle this behaviour as it has shell functions which provide a way of solving this problem more consistent with other forms of argument handling. For example, the csh alias alias cd 'cd \!*; echo $cwd' can be replaced by the zsh function, cd() { builtin cd "$@"; echo $PWD; } (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop) or, perhaps better, cd() { builtin cd "$@"; print -D $PWD; } (which converts your home directory to a ~). In fact, this problem is better solved by defining the special function chpwd() (see the manual). Note also that the `;' at the end of the function is optional in zsh, but not in ksh or sh (for sh's where it exists). Here is Bart Schaefer's guide to converting csh aliases for zsh. 1) If the csh alias references "parameters" (\!:1, \!* etc.), then in zsh you need a function (referencing $1, $* etc.). Otherwise, you can use a zsh alias. 2) If you use a zsh function, you need to refer _at_least_ to $* in the body (inside the { }). Parameters don't magically appear inside the { } the way they get appended to an alias. 3) If the csh alias references its own name (alias rm "rm -i"), then in a zsh function you need the "command" keyword (function rm() { command rm -i "$@" }), but in a zsh alias you don't (alias rm="rm -i"). 4) If you have aliases that refer to each other (alias ls "ls -C"; alias lf "ls -F" ==> lf == ls -C -F) then you must either: o convert all of them to zsh functions; or o after converting, be sure your .zshrc defines all of your aliases before it defines any of your functions. Those first four are all you really need, but here are four more for heavy csh alias junkies: 5) Mapping from csh alias "parameter referencing" into zsh function (assuming shwordsplit and ksharrays are NOT set in zsh): csh zsh ===== ========== \!* $* (or $argv) \!^ $1 (or $argv[1]) \!:1 $1 \!:2 $2 (or $argv[2], etc.) \!$ $*[$#] (or $argv[$#], or $*[-1]) \!:1-4 $*[1,4] \!:1- $*[1,$#-1] (or $*[1,-2]) \!^- $*[1,$#-1] \!*:q "$@" ($*:q doesn't work (yet)) \!*:x $=* ($*:x doesn't work (yet)) 6) Remember that it is NOT a syntax error in a zsh function to refer to a position ($1, $2, etc.) greater than the number of parameters. (E.g., in a csh alias, a reference to \!:5 will cause an error if 4 or fewer arguments are given; in a zsh function, $5 is the empty string if there are 4 or fewer parameters.) 7) To begin a zsh alias with a - (dash, hyphen) character, use `alias --': csh zsh =============== ================== alias - "fg %-" alias -- -="fg %-" 8) Stay away from `alias -g' in zsh until you REALLY know what you're doing. There is one other serious problem with aliases: consider alias l='/bin/ls -F' l() { /bin/ls -la "$@" | more } `l' in the function definition is in command position and is expanded as an alias, defining `/bin/ls' and `-F' as functions which call `/bin/ls', which gets a bit recursive. This can be avoided if you use `function' to define a function, which doesn't expand aliases. It is possible to argue for extra warnings somewhere in this mess. Luckily, it is not possible to define `function' as an alias. Bart Schaefer's rule is: Define first those aliases you expect to use in the body of a function, but define the function first if the alias has the same name as the function. 3.1: Why does `$var' where `var="foo bar"' not do what I expect? In most Bourne-shell derivatives, multiple-word variables such as var="foo bar" are split into words when passed to a command or used in a `for foo in $var' loop. By default, zsh does not have that behaviour: the variable remains intact. (This is not a bug! See below.) An option (SHWORDSPLIT) exists to provide compatibility. For example, defining the function args to show the number of its arguments: args() { echo $#; } and with our definition of `var', args $var produces the output `1'. After setopt shwordsplit the same function produces the output `2', as with sh and ksh. Unless you need strict sh/ksh compatibility, you should ask yourself whether you really want this behaviour, as it can produce unexpected effects for variables with entirely innocuous embedded spaces. This can cause horrendous quoting problems when invoking scripts from other shells. The natural way to produce word-splitting behaviour in zsh is via arrays. For example, set -A array one two three twenty (or array=(one two three twenty) if you prefer), followed by args $array produces the output `4', regardless of the setting of SHWORDSPLIT. Arrays are also much more versatile than single strings. Probably if this mechanism had always been available there would never have been automatic word splitting in scalars, which is a sort of uncontrollable poor man's array. Note that this happens regardless of the value of the internal field separator, $IFS; in other words, with `IFS=:; foo=a:b; args $foo' you get the answer 1. Other ways of causing word splitting include a judicious use of `eval': sentence="Longtemps, je me suis couch\\'e de bonne heure." eval "words=($sentence)" after which $words is an array with the words of $sentence (note characters special to the shell, such as the `'' in this example, must already be quoted), or, less standard but more reliable, turning on SHWORDSPLIT for one variable only: args ${=sentence} always returns 8 with the above definition of `args'. (In older versions of zsh, ${=foo} toggled SHWORDSPLIT; now it forces it on.) Note also the "$@" method of word splitting is always available in zsh functions and scripts (though strictly this does array splitting, not word splitting). This is more portable than the $*, since it will work regardless of the SHWORDSPLIT setting; the other difference is that $* removes empty arguments from the array. You can fix the first half of that objection by using ${==*}, which turns off SHWORDSPLIT for the duration of the expansion. SHWORDSPLIT is set when zsh is invoked with the names `ksh' or `sh', or (entirely equivalent) when `emulate ksh' or `emulate sh' is in effect. --- 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.6 diff -c -r1.6 zshfaq.txt *** zshfaq.txt 1998/11/24 11:20:10 1.6 --- zshfaq.txt 1998/12/19 13:33:06 *************** *** 1,17 **** Archive-Name: unix-faq/shell/zsh ! Last-Modified: 1998/10/26 ! Submitted-By: pws@amtp.liv.ac.uk (Peter Stephenson) ! Version: $Id: faqpost.txt,v 1.1 1998/12/19 13:37:21 pws Exp $ Posting-Frequency: Monthly Copyright: (C) P.W. Stephenson, 1995, 1996, 1997, 1998 (see end of document) ! Changes since issue posted October 1998: ! 1.5 Latest beta is 3.1.5. ! 3.1 Another slight addition ("$@" vs. $*) in the ! perennial SHWORDSPLIT question. Changes in some ! functions which used $*. This document contains a list of frequently-asked (or otherwise significant) questions concerning the Z-shell, a command interpreter --- 1,16 ---- Archive-Name: unix-faq/shell/zsh ! Last-Modified: 1998/11/19 ! Submitted-By: pws@ibmth.df.unipi.it (Peter Stephenson) ! Version: $Id: faqpost.txt,v 1.1 1998/12/19 13:37:21 pws Exp $ Posting-Frequency: Monthly Copyright: (C) P.W. Stephenson, 1995, 1996, 1997, 1998 (see end of document) ! Changes since issue posted November 1998: ! 1.1 Mention email FAQ server ! 2.3 Restore missing double quote in cd() function ! 3.1 Mention ${==*} to turn of SHWORDSPLIT This document contains a list of frequently-asked (or otherwise significant) questions concerning the Z-shell, a command interpreter *************** *** 119,124 **** --- 118,126 ---- 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@rtfm.mit.edu + 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. *************** *** 600,606 **** can be replaced by the zsh function, ! cd() { builtin cd "$@; echo $PWD; } (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop) or, perhaps better, --- 602,608 ---- can be replaced by the zsh function, ! cd() { builtin cd "$@"; echo $PWD; } (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop) or, perhaps better, *************** *** 830,835 **** --- 832,839 ---- word splitting). This is more portable than the $*, since it will work regardless of the SHWORDSPLIT setting; the other difference is that $* removes empty arguments from the array. + You can fix the first half of that objection by using ${==*}, + which turns off SHWORDSPLIT for the duration of the expansion. SHWORDSPLIT is set when zsh is invoked with the names `ksh' or `sh', or (entirely equivalent) when `emulate ksh' or `emulate sh' is in -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy