26763: fix problem on failed cd -s to relative path
[zsh.git] / Doc / intro.ms
blobf4f7062d0dea2c91d9d6023b151911a666463d3a
1 .nr PI 0
2 .nr LL 6.5i
3 .if \n(.g \{\
4 .if "\*(.T"ascii" .ftr C R
5 .if "\*(.T"latin1" .ftr C R
6 .nr De \n[.ss]
7 .\}
8 .de Ds
9 .DS I .5i
10 .ft C
11 .ps 9
12 .vs 11
13 .ss 11
15 .de De
16 .DE
17 .ft R
18 .ps
19 .vs
20 .ie \n(.g .ss \n(De
21 .el .ss
23 .de Sh
24 .SH
25 \\$1
26 .XS
27 \\$1
28 .XE
30 .nr HM 4i
31 .ce 99
32 .ps 18
33 .vs 20
34 .ss 20
35 \f3An Introduction to the Z Shell\fP
37 .ps 14
38 .vs 16
39 .ss 16
40 \f2Paul Falstad
41 pf@software.com
43 Bas de Bakker
44 bas@phys.uva.nl\fP
45 .ce 0
46 .nr HM 1i
47 .pn 1
48 .bp
49 .\" This blank page on the reverse of the cover.
50 .sv |1i
51 .pn 1
52 .bp
53 .TL
54 An Introduction to the Z Shell
55 .AU
56 Paul Falstad
57 pf@software.com
58 .AU
59 Bas de Bakker
60 bas@phys.uva.nl
61 .PP
62 .Sh "Introduction"
63 .PP
64 \fBzsh\fP is a shell designed for interactive use, although it is also
65 a powerful scripting language.  Many of the useful features of bash,
66 ksh, and tcsh were incorporated into \fBzsh\fP; many original features were
67 added.  This document details some of the unique features of \fBzsh\fP.  It
68 assumes basic knowledge of the standard UNIX shells; the intent is to
69 show a reader already familiar with one of the other major shells what
70 makes \fBzsh\fP more useful or more powerful.  This document is not at all
71 comprehensive; read the manual entry for a description of the shell
72 that is complete and concise, although somewhat overwhelming and
73 devoid of examples.
74 .PP
75 The text will frequently mention options that you can set to change
76 the behaviour of \fBzsh\fP.  You can set these options with the
77 command
78 .Ds
79 %\0setopt\0\fIoptionname\fC
80 .De
81 and unset them again with
82 .Ds
83 %\0unsetopt\0\fIoptionname\fC
84 .De
85 Case is ignored in option names, as are embedded underscores.
86 .Sh "Filename Generation"
87 .PP
88 Otherwise known as \fIglobbing\fP, filename generation
89 is quite extensive in \fBzsh\fP.  Of course, it has all the
90 basics:
91 .Ds
92 %\0ls
93 Makefile\0\0\0file.pro\0\0\0foo.o\0\0\0\0\0\0main.o\0\0\0\0\0q.c\0\0\0\0\0\0\0\0run234\0\0\0\0\0stuff
94 bar.o\0\0\0\0\0\0foo\0\0\0\0\0\0\0\0link\0\0\0\0\0\0\0morestuff\0\0run123\0\0\0\0\0run240\0\0\0\0\0sub
95 file.h\0\0\0\0\0foo.c\0\0\0\0\0\0main.h\0\0\0\0\0pipe\0\0\0\0\0\0\0run2\0\0\0\0\0\0\0run303
96 %\0ls\0*.c
97 foo.c\0\0q.c
98 %\0ls\0*.[co]
99 bar.o\0\0\0foo.c\0\0\0foo.o\0\0\0main.o\0\0q.c
100 %\0ls\0foo.?
101 foo.c\0\0foo.o
102 %\0ls\0*.[^c]
103 bar.o\0\0\0file.h\0\0foo.o\0\0\0main.h\0\0main.o
104 %\0ls\0*.[^oh]
105 foo.c\0\0q.c
107 Also, if the \fIEXTENDEDGLOB\fP option is set,
108 some new features are activated.
109 For example, the \fC^\fP character negates the pattern following it:
111 %\0setopt\0extendedglob
112 %\0ls\0-d\0^*.c
113 Makefile\0\0\0file.pro\0\0\0link\0\0\0\0\0\0\0morestuff\0\0run2\0\0\0\0\0\0\0run303
114 bar.o\0\0\0\0\0\0foo\0\0\0\0\0\0\0\0main.h\0\0\0\0\0pipe\0\0\0\0\0\0\0run234\0\0\0\0\0stuff
115 file.h\0\0\0\0\0foo.o\0\0\0\0\0\0main.o\0\0\0\0\0run123\0\0\0\0\0run240\0\0\0\0\0sub
116 %\0ls\0-d\0^*.*
117 Makefile\0\0\0link\0\0\0\0\0\0\0pipe\0\0\0\0\0\0\0run2\0\0\0\0\0\0\0run240\0\0\0\0\0stuff
118 foo\0\0\0\0\0\0\0\0morestuff\0\0run123\0\0\0\0\0run234\0\0\0\0\0run303\0\0\0\0\0sub
119 %\0ls\0-d\0^Makefile
120 bar.o\0\0\0\0\0\0foo\0\0\0\0\0\0\0\0link\0\0\0\0\0\0\0morestuff\0\0run123\0\0\0\0\0run240\0\0\0\0\0sub
121 file.h\0\0\0\0\0foo.c\0\0\0\0\0\0main.h\0\0\0\0\0pipe\0\0\0\0\0\0\0run2\0\0\0\0\0\0\0run303
122 file.pro\0\0\0foo.o\0\0\0\0\0\0main.o\0\0\0\0\0q.c\0\0\0\0\0\0\0\0run234\0\0\0\0\0stuff
123 %\0ls\0-d\0*.^c
124 \&.rhosts\0\0\0bar.o\0\0\0\0\0file.h\0\0\0\0file.pro\0\0foo.o\0\0\0\0\0main.h\0\0\0\0main.o
126 An expression of the form
127 \fC<\fIx\fR\-\fIy\fC>\fR
128 matches a range of integers:
130 %\0ls\0run<200-300>
131 run234\0\0run240
132 %\0ls\0run<300-400>
133 run303
134 %\0ls\0run<-200>
135 run123\0\0run2
136 %\0ls\0run<300->
137 run303
138 %\0ls\0run<>
139 run123\0\0run2\0\0\0\0run234\0\0run240\0\0run303
141 The \fINUMERICGLOBSORT\fP option will sort files with numbers
142 according to the number.  This will not work with \fCls\fP as it
143 resorts its arguments:
145 %\0setopt\0numericglobsort
146 %\0echo\0run<>
147 run2\0run123\0run234\0run240\0run303
149 Grouping is possible:
151 %\0ls\0(foo|bar).*
152 bar.o\0\0foo.c\0\0foo.o
153 %\0ls\0*.(c|o|pro)
154 bar.o\0\0\0\0\0file.pro\0\0foo.c\0\0\0\0\0foo.o\0\0\0\0\0main.o\0\0\0\0q.c
156 Also, the string \fC**/\fP forces a recursive search of
157 subdirectories:
159 %\0ls\0-R
160 Makefile\0\0\0file.pro\0\0\0foo.o\0\0\0\0\0\0main.o\0\0\0\0\0q.c\0\0\0\0\0\0\0\0run234\0\0\0\0\0stuff
161 bar.o\0\0\0\0\0\0foo\0\0\0\0\0\0\0\0link\0\0\0\0\0\0\0morestuff\0\0run123\0\0\0\0\0run240\0\0\0\0\0sub
162 file.h\0\0\0\0\0foo.c\0\0\0\0\0\0main.h\0\0\0\0\0pipe\0\0\0\0\0\0\0run2\0\0\0\0\0\0\0run303
164 morestuff:
166 stuff:
167 file\0\0xxx\0\0\0yyy
169 stuff/xxx:
170 foobar
172 stuff/yyy:
173 frobar
174 %\0ls\0**/*bar
175 stuff/xxx/foobar\0\0stuff/yyy/frobar
176 %\0ls\0**/f*
177 file.h\0\0\0\0\0\0\0\0\0\0\0\0foo\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0foo.o\0\0\0\0\0\0\0\0\0\0\0\0\0stuff/xxx/foobar
178 file.pro\0\0\0\0\0\0\0\0\0\0foo.c\0\0\0\0\0\0\0\0\0\0\0\0\0stuff/file\0\0\0\0\0\0\0\0stuff/yyy/frobar
179 %\0ls\0*bar*
180 bar.o
181 %\0ls\0**/*bar*
182 bar.o\0\0\0\0\0\0\0\0\0\0\0\0\0stuff/xxx/foobar\0\0stuff/yyy/frobar
183 %\0ls\0stuff/**/*bar*
184 stuff/xxx/foobar\0\0stuff/yyy/frobar
187 It is possible to exclude certain files from the patterns using
188 the ~ character.  A pattern of the form \fC*.c~bar.c\fP lists all
189 files matching \fC*.c\fP, except for the file \fCbar.c\fP.
191 %\0ls\0*.c
192 foo.c\0\0\0\0foob.c\0\0\0\0bar.c
193 %\0ls\0*.c~bar.c
194 foo.c\0\0\0\0foob.c
195 %\0ls\0*.c~f*
196 bar.c
199 One can add a number of \fIqualifiers\fP to the end of
200 any of these patterns, to restrict matches to certain
201 file types.  A qualified pattern is of the form
203 \fIpattern\fC(\fR...\fC)\fR
205 with single-character qualifiers inside the parentheses.
207 %\0alias\0l='ls\0-dF'
208 %\0l\0*
209 Makefile\0\0\0\0foo*\0\0\0\0\0\0\0\0main.h\0\0\0\0\0\0q.c\0\0\0\0\0\0\0\0\0run240
210 bar.o\0\0\0\0\0\0\0foo.c\0\0\0\0\0\0\0main.o\0\0\0\0\0\0run123\0\0\0\0\0\0run303
211 file.h\0\0\0\0\0\0foo.o\0\0\0\0\0\0\0morestuff/\0\0run2\0\0\0\0\0\0\0\0stuff/
212 file.pro\0\0\0\0link@\0\0\0\0\0\0\0pipe\0\0\0\0\0\0\0\0run234\0\0\0\0\0\0sub
213 %\0l\0*(/)
214 morestuff/\0\0stuff/
215 %\0l\0*(@)
216 link@
217 %\0l\0*(*)
218 foo*\0\0\0\0\0\0\0\0link@\0\0\0\0\0\0\0morestuff/\0\0stuff/
219 %\0l\0*(x)
220 foo*\0\0\0\0\0\0\0\0link@\0\0\0\0\0\0\0morestuff/\0\0stuff/
221 %\0l\0*(X)
222 foo*\0\0\0\0\0\0\0\0link@\0\0\0\0\0\0\0morestuff/\0\0stuff/
223 %\0l\0*(R)
224 bar.o\0\0\0\0\0\0\0foo*\0\0\0\0\0\0\0\0link@\0\0\0\0\0\0\0morestuff/\0\0run123\0\0\0\0\0\0run240
225 file.h\0\0\0\0\0\0foo.c\0\0\0\0\0\0\0main.h\0\0\0\0\0\0pipe\0\0\0\0\0\0\0\0run2\0\0\0\0\0\0\0\0run303
226 file.pro\0\0\0\0foo.o\0\0\0\0\0\0\0main.o\0\0\0\0\0\0q.c\0\0\0\0\0\0\0\0\0run234\0\0\0\0\0\0stuff/
228 Note that \fC*(x)\fP and \fC*(*)\fP both match executables.
229 \fC*(X)\fP matches files executable by others, as opposed to
230 \fC*(x)\fP, which matches files executable by the owner.
231 \fC*(R)\fP and \fC*(r)\fP match readable files;
232 \fC*(W)\fP and \fC*(w)\fP, which checks for writable files.
233 \fC*(W)\fP is especially important, since it checks for world-writable
234 files:
236 %\0l\0*(w)
237 bar.o\0\0\0\0\0\0\0foo*\0\0\0\0\0\0\0\0link@\0\0\0\0\0\0\0morestuff/\0\0run123\0\0\0\0\0\0run240
238 file.h\0\0\0\0\0\0foo.c\0\0\0\0\0\0\0main.h\0\0\0\0\0\0pipe\0\0\0\0\0\0\0\0run2\0\0\0\0\0\0\0\0run303
239 file.pro\0\0\0\0foo.o\0\0\0\0\0\0\0main.o\0\0\0\0\0\0q.c\0\0\0\0\0\0\0\0\0run234\0\0\0\0\0\0stuff/
240 %\0l\0*(W)
241 link@\0\0\0run240
242 %\0l\0-l\0link\0run240
243 lrwxrwxrwx\0\01\0pfalstad\0\0\0\0\0\0\010\0May\023\018:12\0link\0->\0/usr/bin/
244 -rw-rw-rw-\0\01\0pfalstad\0\0\0\0\0\0\0\00\0May\023\018:12\0run240
246 If you want to have all the files of a certain type as well as all
247 symbolic links pointing to files of that type, prefix the qualifier
248 with a \fC-\fP:
250 %\0l\0*(-/)
251 link@\0\0\0\0\0\0\0morestuff/\0\0stuff/
253 You can filter out the symbolic links with the \fC^\fP character:
255 %\0l\0*(W^@)
256 run240
257 %\0l\0*(x)
258 foo*\0\0\0\0\0\0\0\0link@\0\0\0\0\0\0\0morestuff/\0\0stuff/
259 %\0l\0*(x^@/)
260 foo*
262 To find all plain files, you can use \fC.\fP:
264 %\0l\0*(.)
265 Makefile\0\0file.h\0\0\0\0foo*\0\0\0\0\0\0foo.o\0\0\0\0\0main.o\0\0\0\0run123\0\0\0\0run234\0\0\0\0run303
266 bar.o\0\0\0\0\0file.pro\0\0foo.c\0\0\0\0\0main.h\0\0\0\0q.c\0\0\0\0\0\0\0run2\0\0\0\0\0\0run240\0\0\0\0sub
267 %\0l\0*(^.)
268 link@\0\0\0\0\0\0\0morestuff/\0\0pipe\0\0\0\0\0\0\0\0stuff/
269 %\0l\0s*(.)
270 stuff/\0\0\0sub
271 %\0l\0*(p)
272 pipe
273 %\0l\0-l\0*(p)
274 prw-r--r--\0\01\0pfalstad\0\0\0\0\0\0\0\00\0May\023\018:12\0pipe
276 \fC*(U)\fP matches all files owned by you.
277 To search for all files not owned by you, use \fC*(^U)\fP:
279 %\0l\0-l\0*(^U)
280 -rw-------\0\01\0subbarao\0\0\0\0\0\0\029\0May\023\018:13\0sub
282 This searches for setuid files:
284 %\0l\0-l\0*(s)
285 -rwsr-xr-x\0\01\0pfalstad\0\0\0\0\0\0\016\0May\023\018:12\0foo*
287 This checks for a certain user's files:
289 %\0l\0-l\0*(u[subbarao])
290 -rw-------\0\01\0subbarao\0\0\0\0\0\0\029\0May\023\018:13\0sub
292 .Sh "Startup Files"
294 There are five startup files that \fBzsh\fP will read commands from:
296 $ZDOTDIR/.zshenv
297 $ZDOTDIR/.zprofile
298 $ZDOTDIR/.zshrc
299 $ZDOTDIR/.zlogin
300 $ZDOTDIR/.zlogout
302 If \fBZDOTDIR\fP is not set, then the value of \fBHOME\fP is used;
303 this is the usual case.
304 .\".KE    <--- missing .KS or .KF above
306 \&\fC.zshenv\fP is sourced on all invocations of the shell,
307 unless the \fC-f\fP option is set.  It should contain commands to set
308 the command search path, plus other important environment
309 variables.
310 \&\fC.zshenv\fP should not contain commands that produce output
311 or assume the shell is attached to a tty.
313 \&\fC.zshrc\fP is sourced in interactive shells.  It should contain
314 commands to set up aliases, functions, options, key bindings, etc.
316 \&\fC.zlogin\fP is sourced in login shells.  It should contain
317 commands that should be executed only in login shells.
318 \&\fC.zlogout\fP is sourced when login shells exit.
319 \&\fC.zprofile\fP is similar to \fC.zlogin\fP, except that it is sourced before
320 \&\fC.zshrc\fP.
321 \&\fC.zprofile\fP is meant as an alternative to \fC.zlogin\fP for
322 ksh fans;
323 the two are not intended to be used together, although this
324 could certainly be done if desired.
325 \&\fC.zlogin\fP is not the place for alias definitions, options, environment
326 variable settings, etc.;
327 as a general rule, it should not change the shell environment
328 at all.  Rather, it should be used to set the terminal type
329 and run a series of external commands (\fCfortune\fP, \fCmsgs\fP, etc).
330 .Sh "Shell Functions"
332 \fBzsh\fP also allows you to create your own commands by defining shell
333 functions.  For example:
335 %\0yp\0()\0{
336 >\0\0\0\0\0\0\0ypmatch\0$1\0passwd.byname
337 >\0}
338 %\0yp\0pfalstad
339 pfalstad:*:3564:35:Paul\0John\0Falstad:/u/pfalstad:/usr/princeton/bin/zsh
341 This function looks up a user in the NIS password map.
342 The \fC$1\fP expands to the first argument to \fCyp\fP.
343 The function could have been equivalently defined in one of the following
344 ways:
346 %\0function\0yp\0{
347 >\0\0\0\0\0\0\0ypmatch\0$1\0passwd.byname
348 >\0}
349 %\0function\0yp\0()\0{
350 >\0\0\0\0\0\0\0ypmatch\0$1\0passwd.byname
351 >\0}
352 %\0function\0yp\0()\0ypmatch\0$1\0passwd.byname
354 Note that aliases are expanded when the function definition is
355 parsed, not when the function is executed.  For example:
357 %\0alias\0ypmatch=echo
358 %\0yp\0pfalstad
359 pfalstad:*:3564:35:Paul\0John\0Falstad:/u/pfalstad:/usr/princeton/bin/zsh
361 Since the alias was defined after the function was parsed, it has
362 no effect on the function's execution.
363 However, if we define the function again with the alias in place:
365 %\0function\0yp\0()\0{\0ypmatch\0$1\0passwd.byname\0}
366 %\0yp\0pfalstad
367 pfalstad\0passwd.byname
369 it is parsed with the new alias definition in place.
370 Therefore, in general you must define aliases before functions.
371 .\".KE    <--- missing .KS or .KF above
373 We can make the function take multiple arguments:
375 %\0unalias\0ypmatch
376 %\0yp\0()\0{
377 >\0\0\0\0\0\0\0for\0i
378 >\0\0\0\0\0\0\0do\0ypmatch\0$i\0passwd.byname
379 >\0\0\0\0\0\0\0done
380 >\0}
381 %\0yp\0pfalstad\0subbarao\0sukthnkr
382 pfalstad:*:3564:35:Paul\0John\0Falstad:/u/pfalstad:/usr/princeton/bin/zsh
383 subbarao:*:3338:35:Kartik\0Subbarao:/u/subbarao:/usr/princeton/bin/zsh
384 sukthnkr:*:1267:35:Rahul\0Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
386 The \fCfor i\fP loops through each of the function's arguments,
387 setting \fCi\fP equal to each of them in turn.
388 We can also make the function do something sensible
389 if no arguments are given:
391 %\0yp\0()\0{
392 >\0\0\0\0\0\0\0if\0((\0$#\0==\00\0))
393 >\0\0\0\0\0\0\0then\0echo\0usage:\0yp\0name\0...;\0fi
394 >\0\0\0\0\0\0\0for\0i;\0do\0ypmatch\0$i\0passwd.byname;\0done
395 >\0}
396 %\0yp
397 usage:\0yp\0name\0...
398 %\0yp\0pfalstad\0sukthnkr
399 pfalstad:*:3564:35:Paul\0John\0Falstad:/u/pfalstad:/usr/princeton/bin/zsh
400 sukthnkr:*:1267:35:Rahul\0Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
402 \fC$#\fP is the number of arguments supplied to the function.
403 If it is equal to zero, we print a usage message; otherwise,
404 we loop through the arguments, and \fCypmatch\fP all of them.
405 .\".KE    <--- missing .KS or .KF above
407 Here's a function that selects a random line from a file:
409 %\0randline\0()\0{
410 >\0\0\0\0\0\0\0integer\0z=$(wc\0-l\0<$1)
411 >\0\0\0\0\0\0\0sed\0-n\0$[RANDOM\0%\0z\0+\01]p\0$1
412 >\0}
413 %\0randline\0/etc/motd
414 PHOENIX\0WILL\0BE\0DOWN\0briefly\0Friday\0morning,\05/24/91\0from\08\0AM\0to
415 %\0randline\0/etc/motd
416 SunOS\0Release\04.1.1\0(PHOENIX)\0#19:\0Tue\0May\014\019:03:15\0EDT\01991
417 %\0randline\0/etc/motd
418 |\0Please\0use\0the\0"msgs"\0command\0to\0read\0announcements.\0\0Refer\0to\0the\0\0\0|
419 %\0echo\0$z
423 \fCrandline\fP has a local variable, \fCz\fP, that holds the number of
424 lines in the file.  \fC$[RANDOM % z + 1]\fP expands to a random number
425 between 1 and \fCz\fP.  An expression of the form \fC$[\fR...\fC]\fR
426 expands to the value of the arithmetic expression within the brackets,
427 and the \fBRANDOM\fP variable returns a random number each time it
428 is referenced.  \fC%\fP is the modulus operator, as in C.
429 Therefore, \fCsed -n $[RANDOM%z+1]p\fP picks a random line from its
430 input, from 1 to \fCz\fP.
432 Function definitions can be viewed with the \fCfunctions\fP builtin:
434 %\0functions\0randline
435 randline\0()\0{
436 \0\0\0\0\0\0\0\0integer\0z=$(wc\0-l\0<$1)
437 \0\0\0\0\0\0\0\0sed\0-n\0$[RANDOM\0%\0z\0+\01]p\0$1
440 %\0functions
441 yp\0()\0{
442 \0\0\0\0\0\0\0\0if\0let\0$#\0==\00\0
443 \0\0\0\0\0\0\0\0
444 \0\0\0\0\0\0\0\0then
445 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0echo\0usage:\0yp\0name\0...
446 \0\0\0\0\0\0\0\0
447 \0\0\0\0\0\0\0\0fi
448 \0\0\0\0\0\0\0\0for\0i
449 \0\0\0\0\0\0\0\0do
450 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0ypmatch\0$i\0passwd.byname
451 \0\0\0\0\0\0\0\0
452 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0done
455 randline\0()\0{
456 \0\0\0\0\0\0\0\0integer\0z=$(wc\0-l\0<$1)
457 \0\0\0\0\0\0\0\0sed\0-n\0$[RANDOM\0%\0z\0+\01]p\0$1
461 Here's another one:
463 %\0cx\0()\0{\0chmod\0+x\0$*\0}
464 %\0ls\0-l\0foo\0bar
465 -rw-r--r--\0\01\0pfalstad\0\0\0\0\0\0\029\0May\024\004:38\0bar
466 -rw-r--r--\0\01\0pfalstad\0\0\0\0\0\0\029\0May\024\004:38\0foo
467 %\0cx\0foo\0bar
468 %\0ls\0-l\0foo\0bar
469 -rwxr-xr-x\0\01\0pfalstad\0\0\0\0\0\0\029\0May\024\004:38\0bar
470 -rwxr-xr-x\0\01\0pfalstad\0\0\0\0\0\0\029\0May\024\004:38\0foo
472 Note that this could also have been implemented as an alias:
474 %\0chmod\0644\0foo\0bar
475 %\0alias\0cx='chmod\0+x'
476 %\0cx\0foo\0bar
477 %\0ls\0-l\0foo\0bar
478 -rwxr-xr-x\0\01\0pfalstad\0\0\0\0\0\0\029\0May\024\004:38\0bar
479 -rwxr-xr-x\0\01\0pfalstad\0\0\0\0\0\0\029\0May\024\004:38\0foo
482 Instead of defining a lot of functions in your \fC.zshrc\fP,
483 all of which you may not use,
484 it is often better to use the \fCautoload\fP builtin.
485 The idea is, you create a directory where function
486 definitions are stored, declare the names in
487 your \fC.zshrc\fP, and tell the shell where to look for them.
488 Whenever you reference a function, the shell
489 will automatically load it into memory.
491 %\0mkdir\0/tmp/funs
492 %\0cat\0>/tmp/funs/yp
493 ypmatch\0$1\0passwd.byname
495 %\0cat\0>/tmp/funs/cx
496 chmod\0+x\0$*
498 %\0FPATH=/tmp/funs
499 %\0autoload\0cx\0yp
500 %\0functions\0cx\0yp
501 undefined\0cx\0()
502 undefined\0yp\0()
503 %\0chmod\0755\0/tmp/funs/{cx,yp}
504 %\0yp\0egsirer
505 egsirer:*:3214:35:Emin\0Gun\0Sirer:/u/egsirer:/bin/sh
506 %\0functions\0yp
507 yp\0()\0{
508 \0\0\0\0\0\0\0\0ypmatch\0$1\0passwd.byname
511 This idea has other benefits.  By adding a \fC#!\fP header
512 to the files, you can make them double as shell scripts.
513 (Although it is faster to use them as functions, since a
514 separate process is not created.)
516 %\0ed\0/tmp/funs/yp
519 #!\0/usr/local/bin/zsh
524 %\0</tmp/funs/yp
525 #!\0/usr/local/bin/zsh
526 ypmatch\0$1\0passwd.byname
527 %\0/tmp/funs/yp\0sukthnkr
528 sukthnkr:*:1267:35:Rahul\0Sukthankar:/u/sukthnkr:/usr/princeton/bin/tcsh
530 Now other people, who may not use \fBzsh\fP, or who don't want to
531 copy all of your \fC.zshrc\fP, may use these functions as shell
532 scripts.
533 .Sh "Directories"
535 One nice feature of \fBzsh\fP is the way it prints directories.
536 For example, if we set the prompt like this:
538 phoenix%\0PROMPT='%~>\0'
539 ~>\0cd\0src
540 ~/src>
542 the shell will print the current directory in the prompt,
543 using the \fC~\fP character.
544 However, \fBzsh\fP is smarter than most other shells in this respect:
546 ~/src>\0cd\0~subbarao
547 ~subbarao>\0cd\0~maruchck
548 ~maruchck>\0cd\0lib
549 ~maruchck/lib>\0cd\0fun
550 ~maruchck/lib/fun>\0foo=/usr/princeton/common/src
551 ~maruchck/lib/fun>\0cd\0~foo
552 ~foo>\0cd\0..
553 /usr/princeton/common>\0cd\0src
554 ~foo>\0cd\0news/nntp
555 ~foo/news/nntp>\0cd\0inews
556 ~foo/news/nntp/inews>
558 Note that \fBzsh\fP prints \fIother\fP users' directories 
559 in the form \fC~user\fP.  Also note that you can
560 set a parameter and use it as a directory name;
561 \fBzsh\fP will act as if \fCfoo\fP is a user
562 with the login directory \fC/usr/princeton/common/src\fP.
563 This is convenient, especially if you're sick of seeing
564 prompts like this:
566 phoenix:/usr/princeton/common/src/X.V11R4/contrib/clients/xv/docs>
568 If you get stuck in this position, you can give the current
569 directory a short name, like this:
571 /usr/princeton/common/src/news/nntp/inews>\0inews=$PWD
572 /usr/princeton/common/src/news/nntp/inews>\0echo\0~inews
573 /usr/princeton/common/src/news/nntp/inews
574 ~inews>
576 When you reference a directory in the form \fC~inews\fP,
577 the shell assumes that you want the directory displayed
578 in this form; thus simply typing \fCecho ~inews\fP or
579 \fCcd ~inews\fP causes the prompt to be shortened.
580 You can define a shell function for this purpose:
582 ~inews>\0namedir\0()\0{\0$1=$PWD\0;\0\0:\0~$1\0}
583 ~inews>\0cd\0/usr/princeton/bin
584 /usr/princeton/bin>\0namedir\0pbin
585 ~pbin>\0cd\0/var/spool/mail
586 /var/spool/mail>\0namedir\0spool
587 ~spool>\0cd\0.msgs
588 ~spool/.msgs>
590 You may want to add this one-line function to your \fC.zshrc\fP.
592 \fBzsh\fP can also put the current directory in your title bar,
593 if you are using a windowing system.
594 One way to do this is with the \fCchpwd\fP function, which is
595 automatically executed by the shell whenever you change
596 directory.  If you are using xterm, this will work:
598 chpwd\0()\0{\0print\0-Pn\0'^[]2;%~^G'\0}
600 The \fC-P\fP option tells \fCprint\fP to treat its arguments like a prompt
601 string; otherwise the \fC%~\fP would not be expanded.
602 The \fC-n\fP option suppresses the terminating newline, as with \fCecho\fP.
604 If you are using an IRIS \fCwsh\fP, do this:
606 chpwd\0()\0{\0print\0-Pn\0'\e2201.y%~\e234'\0}
608 The \fCprint -D\fP command has other uses.  For example, to
609 print the current directory to standard output in short form,
610 you can do this:
612 %\0print\0-D\0$PWD
613 ~subbarao/src
615 and to print each component of the path in short form:
617 %\0print\0-D\0$path
618 /bin\0/usr/bin\0~locbin\0~locbin/X11\0~/bin
620 .Sh "Directory Stacks"
622 If you use csh, you may know about directory stacks.
623 The \fCpushd\fP command puts the current directory on the
624 stack, and changes to a new directory; the \fCpopd\fP command
625 pops a directory off the stack and changes to it.
627 phoenix%\0cd\0
628 phoenix%\0PROMPT='Z\0%~>\0'
629 Z\0~>\0pushd\0/tmp
630 /tmp\0~
631 Z\0/tmp>\0pushd\0/usr/etc
632 /usr/etc\0/tmp\0~
633 Z\0/usr/etc>\0pushd\0/usr/bin
634 /usr/bin\0/usr/etc\0/tmp\0~
635 Z\0/usr/bin>\0popd
636 /usr/etc\0/tmp\0~
637 Z\0/usr/etc>\0popd
638 /tmp\0~
639 Z\0/tmp>\0pushd\0/etc
640 /etc\0/tmp\0~
641 Z\0/etc>\0popd\0
642 /tmp\0~
644 \fBzsh\fP's directory stack commands work similarly.  One
645 difference is the way \fCpushd\fP is handled if no arguments
646 are given.  As in csh, this exchanges the top two elements
647 of the directory stack:
649 Z\0/tmp>\0dirs
650 /tmp\0~
651 Z\0/tmp>\0pushd
652 ~\0/tmp
654 unless the stack only has one entry:
656 Z\0~>\0popd
657 /tmp
658 Z\0/tmp>\0dirs
659 /tmp
660 Z\0/tmp>\0pushd
661 ~\0/tmp
662 Z\0~>
664 or unless the \fIPUSHDTOHOME\fP option is set:
666 Z\0~>\0setopt\0pushdtohome
667 Z\0~>\0pushd
668 ~\0~\0/tmp
671 As an alternative to using directory stacks in this manner,
672 we can get something like a \fIdirectory history\fP
673 by setting a few more options and parameters:
675 ~>\0DIRSTACKSIZE=8
676 ~>\0setopt\0autopushd\0pushdminus\0pushdsilent\0pushdtohome
677 ~>\0alias\0dh='dirs\0-v'
678 ~>\0cd\0/tmp
679 /tmp>\0cd\0/usr
680 /usr>\0cd\0bin
681 /usr/bin>\0cd\0../pub
682 /usr/pub>\0dh
683 0\0\0\0\0\0\0\0/usr/pub
684 1\0\0\0\0\0\0\0/usr/bin
685 2\0\0\0\0\0\0\0/usr
686 3\0\0\0\0\0\0\0/tmp
687 4\0\0\0\0\0\0\0~
688 /usr/pub>\0cd\0-3
689 /tmp>\0dh
690 0\0\0\0\0\0\0\0/tmp
691 1\0\0\0\0\0\0\0/usr/pub
692 2\0\0\0\0\0\0\0/usr/bin
693 3\0\0\0\0\0\0\0/usr
694 4\0\0\0\0\0\0\0~
695 /tmp>\0ls\0=2/df
696 /usr/bin/df
697 /tmp>\0cd\0-4
700 Note that \fC=2\fP expanded to the second directory in the
701 history list, and that \fCcd -3\fP recalled the third
702 directory in the list.
704 You may be wondering what all those options do.
705 \fIAUTOPUSHD\fP made \fCcd\fP act like \fCpushd\fP.
706 (\fCalias cd=pushd\fP is not sufficient, for various reasons.)
707 \fIPUSHDMINUS\fP swapped the meaning of \fCcd +1\fP and
708 \fCcd -1\fP; we want them to mean the opposite of what they mean in csh,
709 because it makes more sense in this scheme, and it's easier to type:
711 ~>\0dh
712 0\0\0\0\0\0\0\0~
713 1\0\0\0\0\0\0\0/tmp
714 2\0\0\0\0\0\0\0/usr/pub
715 3\0\0\0\0\0\0\0/usr/bin
716 4\0\0\0\0\0\0\0/usr
717 ~>\0unsetopt\0pushdminus
718 ~>\0cd\0+1
719 /tmp>\0dh
720 0\0\0\0\0\0\0\0/tmp
721 1\0\0\0\0\0\0\0~
722 2\0\0\0\0\0\0\0/usr/pub
723 3\0\0\0\0\0\0\0/usr/bin
724 4\0\0\0\0\0\0\0/usr
725 /tmp>\0cd\0+2
726 /usr/pub>
728 \fIPUSHDSILENT\fP keeps the shell from printing
729 the directory stack each time we do a \fCcd\fP,
730 and \fIPUSHDTOHOME\fP we mentioned earlier:
732 /usr/pub>\0unsetopt\0pushdsilent
733 /usr/pub>\0cd\0/etc
734 /etc\0/usr/pub\0/tmp\0~\0/usr/bin\0/usr
735 /etc>\0cd
736 ~\0/etc\0/usr/pub\0/tmp\0~\0/usr/bin\0/usr
737 ~>\0unsetopt\0pushdtohome
738 ~>\0cd
739 /etc\0~\0/usr/pub\0/tmp\0~\0/usr/bin\0/usr
740 /etc>
742 \fBDIRSTACKSIZE\fP keeps the directory stack
743 from getting too large, much like \fIHISTSIZE\fP:
745 /etc>\0setopt\0pushdsilent
746 /etc>\0cd\0/
747 />\0cd\0/
748 />\0cd\0/
749 />\0cd\0/
750 />\0cd\0/
751 />\0cd\0/
752 />\0cd\0/
753 />\0cd\0/
754 />\0dh
755 0\0\0\0\0\0\0\0/
756 1\0\0\0\0\0\0\0/
757 2\0\0\0\0\0\0\0/
758 3\0\0\0\0\0\0\0/
759 4\0\0\0\0\0\0\0/
760 5\0\0\0\0\0\0\0/
761 6\0\0\0\0\0\0\0/
762 7\0\0\0\0\0\0\0/
764 .Sh "Command/Process Substitution"
766 Command substitution in \fBzsh\fP can take two forms.
767 In the traditional form, a command enclosed in
768 backquotes (\fC`\fP...\fC`\fP) is replaced on the command line with its output.
769 This is the form used by the older shells.
770 Newer shells (like \fBzsh\fP) also provide another form,
771 \fC$(\fR...\fC)\fR.  This form is much easier to nest.
773 %\0ls\0-l\0`echo\0/vmunix`
774 -rwxr-xr-x\0\01\0root\0\0\0\0\0\01209702\0May\014\019:04\0/vmunix
775 %\0ls\0-l\0$(echo\0/vmunix)
776 -rwxr-xr-x\0\01\0root\0\0\0\0\0\01209702\0May\014\019:04\0/vmunix
777 %\0who\0|\0grep\0mad
778 subbarao\0ttyt7\0\0\0May\023\015:02\0\0\0(mad55sx15.Prince)
779 pfalstad\0ttyu1\0\0\0May\023\016:25\0\0\0(mad55sx14.Prince)
780 subbarao\0ttyu6\0\0\0May\023\015:04\0\0\0(mad55sx15.Prince)
781 pfalstad\0ttyv3\0\0\0May\023\016:25\0\0\0(mad55sx14.Prince)
782 %\0who\0|\0grep\0mad\0|\0awk\0'{print\0$2}'
783 ttyt7
784 ttyu1
785 ttyu6
786 ttyv3
787 %\0cd\0/dev;\0ls\0-l\0$(who\0|
788 >\0grep\0$(echo\0mad)\0|
789 >\0awk\0'{\0print\0$2\0}')
790 crwx-w----\0\01\0subbarao\0\020,\0\071\0May\023\018:35\0ttyt7
791 crw--w----\0\01\0pfalstad\0\020,\0\081\0May\023\018:42\0ttyu1
792 crwx-w----\0\01\0subbarao\0\020,\0\086\0May\023\018:38\0ttyu6
793 crw--w----\0\01\0pfalstad\0\020,\0\099\0May\023\018:41\0ttyv3
795 Many common uses of command substitution, however, are
796 superseded by other mechanisms of \fBzsh\fP:
798 %\0ls\0-l\0`tty`
799 crw-rw-rw-\0\01\0root\0\0\0\0\0\020,\0\028\0May\023\018:35\0/dev/ttyqc
800 %\0ls\0-l\0$TTY
801 crw-rw-rw-\0\01\0root\0\0\0\0\0\020,\0\028\0May\023\018:35\0/dev/ttyqc
802 %\0ls\0-l\0`which\0rn`
803 -rwxr-xr-x\0\01\0root\0\0\0\0\0\0\0172032\0Mar\0\06\018:40\0/usr/princeton/bin/rn
804 %\0ls\0-l\0=rn
805 -rwxr-xr-x\0\01\0root\0\0\0\0\0\0\0172032\0Mar\0\06\018:40\0/usr/princeton/bin/rn
807 A command name with a \fC=\fP prepended is replaced with its full
808 pathname.  This can be very convenient.  If it's not convenient
809 for you, you can turn it off:
811 %\0ls
812 =foo\0\0\0\0=bar
813 %\0ls\0=foo\0=bar
814 zsh:\0foo\0not\0found
815 %\0setopt\0noequals
816 %\0ls\0=foo\0=bar
817 =foo\0\0\0\0=bar
820 Another nice feature is process substitution:
822 %\0who\0|\0fgrep\0-f\0=(print\0-l\0root\0lemke\0shgchan\0subbarao)
823 root\0\0\0\0\0console\0May\019\010:41
824 lemke\0\0\0\0ttyq0\0\0\0May\022\010:05\0\0\0(narnia:0.0)
825 lemke\0\0\0\0ttyr7\0\0\0May\022\010:05\0\0\0(narnia:0.0)
826 lemke\0\0\0\0ttyrd\0\0\0May\022\010:05\0\0\0(narnia:0.0)
827 shgchan\0\0ttys1\0\0\0May\023\016:52\0\0\0(gaudi.Princeton.)
828 subbarao\0ttyt7\0\0\0May\023\015:02\0\0\0(mad55sx15.Prince)
829 subbarao\0ttyu6\0\0\0May\023\015:04\0\0\0(mad55sx15.Prince)
830 shgchan\0\0ttyvb\0\0\0May\023\016:51\0\0\0(gaudi.Princeton.)
832 A command of the form \fC=(\fR...\fC)\fR is replaced with the name of a \fIfile\fP
833 containing its output.  (A command substitution, on the other
834 hand, is replaced with the output itself.)
835 \fCprint -l\fP is like \fCecho\fP, excepts that it prints its arguments
836 one per line, the way \fCfgrep\fP expects them:
838 %\0print\0-l\0foo\0bar
842 We could also have written:
844 %\0who\0|\0fgrep\0-f\0=(echo\0'root
845 >\0lemke
846 >\0shgchan
847 >\0subbarao')
849 Using\0process\0substitution,
850 you\0can\0edit\0the\0output\0of\0a\0command:
852 %\0ed\0=(who\0|\0fgrep\0-f\0~/.friends)
854 g/lemke/d
855 w\0/tmp/filbar
858 %\0cat\0/tmp/filbar
859 root\0\0\0\0\0console\0May\019\010:41
860 shgchan\0\0ttys1\0\0\0May\023\016:52\0\0\0(gaudi.Princeton.)
861 subbarao\0ttyt7\0\0\0May\023\015:02\0\0\0(mad55sx15.Prince)
862 subbarao\0ttyu6\0\0\0May\023\015:04\0\0\0(mad55sx15.Prince)
863 shgchan\0\0ttyvb\0\0\0May\023\016:51\0\0\0(gaudi.Princeton.)
865 or easily read archived mail:
867 %\0mail\0-f\0=(zcat\0~/mail/oldzshmail.Z)
868 "/tmp/zsha06024":\084\0messages,\00\0new,\043\0unread
869 >\0\01\0\0U\0\0TO:\0pfalstad,\0zsh\0(10)
870 \0\0\02\0\0U\0\0nytim!tim@uunet.uu.net,\0Re:\0Zsh\0on\0Sparc1\0/SunOS\04.0.3
871 \0\0\03\0\0U\0\0JAM%TPN@utrcgw.utc.com,\0zsh\0fix\0(15)
872 \0\0\04\0\0U\0\0djm@eng.umd.edu,\0way\0to\0find\0out\0if\0running\0zsh?\0(25)
873 \0\0\05\0\0U\0\0djm@eng.umd.edu,\0Re:\0way\0to\0find\0out\0if\0running\0zsh?\0(17)
874 \0\0\06\0\0\0r\0djm@eng.umd.edu,\0Meta\0.\0(18)
875 \0\0\07\0\0U\0\0jack@cs.glasgow.ac.uk,\0Re:\0problem\0building\0zsh\0(147)
876 \0\0\08\0\0U\0\0nytim!tim@uunet.uu.net,\0Re:\0Zsh\0on\0Sparc1\0/SunOS\04.0.3
877 \0\0\09\0\0\0\0\0ursa!jmd,\0Another\0fix...\0(61)
878 \0\010\0\0U\0\0pplacewa@bbn.com,\0Re:\0v18i084:\0Zsh\02.00\0-\0A\0small\0complaint\0(36)
879 \0\011\0\0U\0\0lubkin@cs.rochester.edu,\0POSIX\0job\0control\0(34)
880 \0\012\0\0U\0\0yale!bronson!tan@uunet.UU.NET
881 \0\013\0\0U\0\0brett@rpi.edu,\0zsh\0(36)
882 \0\014\0\0S\0\0subbarao,\0zsh\0sucks!!!!\0(286)
883 \0\015\0\0U\0\0snibru!d241s008!d241s013!ala@relay.EU.net,\0zsh\0(165)
884 \0\016\0\0U\0\0nytim!tim@uunet.UU.NET,\0Re:\0Zsh\0on\0Sparc1\0/SunOS\04.0.3
885 \0\017\0\0U\0\0subbarao,\0zsh\0is\0a\0junk\0shell\0(43)
886 \0\018\0\0U\0\0amaranth@vela.acs.oakland.edu,\0zsh\0(33)
887 43u/84\01:\0x
888 %\0ls\0-l\0/tmp/zsha06024
889 /tmp/zsha06024\0not\0found
891 Note that the shell creates a temporary file, and deletes it
892 when the command is finished.
894 %\0diff\0=(ls)\0=(ls\0-F)
896 <\0fortune
898 >\0fortune*
899 10c10
900 <\0strfile
902 >\0strfile*
904 If you read \fBzsh\fP's man page, you may notice that \fC<(\fR...\fC)\fR
905 is another form of process substitution which is similar to
906 \fC=(\fR...\fC)\fR.
907 There is an important difference between the two.
908 In the \fC<(\fR...\fC)\fR case, the shell creates a named pipe (FIFO)
909 instead of a file.  This is better, since it does not
910 fill up the file system; but it does not work in all cases.
911 In fact, if we had replaced \fC=(\fR...\fC)\fR with \fC<(\fR...\fC)\fR in 
912 the examples above, all of them would have stopped working
913 except for \fCfgrep -f <(\fR...\fC)\fR.
914 You can not edit a pipe, or open it as a mail folder;
915 \fCfgrep\fP, however, has no problem with reading
916 a list of words from a pipe.
917 You may wonder why \fCdiff <(foo) bar\fP doesn't work, since
918 \fCfoo | diff - bar\fP works; this is because \fCdiff\fP creates
919 a temporary file if it notices that one of its arguments
920 is \fC-\fP, and then copies its standard input to the temporary
921 file.
923 \fC>(\fR...\fC)\fR is just like \fC<(\fR...\fC)\fR except that the
924 command between the parentheses will get its input from the named
925 pipe.
927 %\0dvips\0-o\0>(lpr)\0zsh.dvi
929 .Sh "Redirection"
931 Apart from all the regular redirections like the Bourne shell has,
932 \fBzsh\fP can do more.  You can send the output of a command to more
933 than one file, by specifying more redirections like
935 %\0echo\0Hello\0World\0>file1\0>file2
937 and the text will end up in both files.  Similarly, you can send the
938 output to a file and into a pipe:
940 %\0make\0>\0make.log\0|\0grep\0Error
942 The same goes for input.  You can make the input of a command come
943 from more than one file.
945 %\0sort\0<file1\0<file2\0<file3
947 The command will first get the contents of file1 as its standard
948 input, then those of file2 and finally the contents of file3.  This,
949 too, works with pipes.
951 %\0cut\0-d:\0-f1\0/etc/passwd\0|\0sort\0<newnames
953 The sort will get as its standard input first the output of \fCcut\fP
954 and then the contents of \fCnewnames\fP.
956 Suppose you would like to watch the standard output of a command on
957 your terminal, but want to pipe the standard error to another command.
958 An easy way to do this in \fBzsh\fP is by redirecting the standard
959 error using \fC2> >(\fR...\fC)\fR.
961 %\0find\0/\0-name\0games\02>\0>(grep\0-v\0'Permission'\0>\0realerrors)
963 The above redirection will actually be implemented with a regular
964 pipe, not a temporary named pipe.
965 .Sh "Aliasing"
967 Often-used commands can be abbreviated with an alias:
969 %\0alias\0uc=uncompress
970 %\0ls
971 hanoi.Z
972 %\0uc\0hanoi
973 %\0ls
974 hanoi
976 or commands with certain desired options:
978 %\0alias\0fm='finger\0-m'
979 %\0fm\0root
980 Login\0name:\0root\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0In\0real\0life:\0Operator
981 Directory:\0/\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0Shell:\0/bin/csh
982 On\0since\0May\019\010:41:15\0on\0console\0\0\0\0\03\0days\05\0hours\0Idle\0Time
983 No\0unread\0mail
984 No\0Plan.
986 %\0alias\0lock='lock\0-p\0-60000'
987 %\0lock
988 lock:\0/dev/ttyr4\0on\0phoenix.\0timeout\0in\060000\0minutes
989 time\0now\0is\0Fri\0May\024\004:23:18\0EDT\01991
990 Key:\0
992 %\0alias\0l='ls\0-AF'
993 %\0l\0/
994 \&.bash_history\0\0\0\0\0\0\0\0\0\0\0\0\0\0kadb*
995 \&.bashrc\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0lib@
996 \&.cshrc\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0licensed/
997 \&.exrc\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0lost+found/
998 \&.login\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0macsyma
999 \&\fR...
1001 Aliases can also be used to replace old commands:
1003 %\0alias\0grep=egrep\0ps=sps\0make=gmake
1004 %\0alias\0whoami='echo\0root'
1005 %\0whoami
1006 root
1008 or to define new ones:
1010 %\0cd\0/
1011 %\0alias\0sz='ls\0-l\0|\0sort\0-n\0+3\0|\0tail\0-10'
1012 %\0sz
1013 drwxr-sr-x\0\07\0bin\0\0\0\0\0\0\0\0\0\03072\0May\023\011:59\0etc
1014 drwxrwxrwx\026\0root\0\0\0\0\0\0\0\0\05120\0May\024\004:20\0tmp
1015 drwxr-xr-x\0\02\0root\0\0\0\0\0\0\0\0\08192\0Dec\026\019:34\0lost+found
1016 drwxr-sr-x\0\02\0bin\0\0\0\0\0\0\0\0\014848\0May\023\018:48\0dev
1017 -r--r--r--\0\01\0root\0\0\0\0\0\0\0140520\0Dec\026\020:08\0boot
1018 -rwxr-xr-x\0\01\0root\0\0\0\0\0\0\0311172\0Dec\026\020:08\0kadb
1019 -rwxr-xr-x\0\01\0root\0\0\0\0\0\01209695\0Apr\016\015:33\0vmunix.old
1020 -rwxr-xr-x\0\01\0root\0\0\0\0\0\01209702\0May\014\019:04\0vmunix
1021 -rwxr-xr-x\0\01\0root\0\0\0\0\0\01209758\0May\021\012:23\0vmunix.new.kernelmap.old
1022 -rwxr-xr-x\0\01\0root\0\0\0\0\0\01711848\0Dec\026\020:08\0vmunix.org
1023 %\0cd
1024 %\0alias\0rable='ls\0-AFtrd\0*(R)'\0nrable='ls\0-AFtrd\0*(^R)'
1025 %\0rable
1026 README\0\0\0\0\0\0func/\0\0\0\0\0\0\0bin/\0\0\0\0\0\0\0\0pub/\0\0\0\0\0\0\0\0News/\0\0\0\0\0\0\0src/
1027 nicecolors\0\0etc/\0\0\0\0\0\0\0\0scr/\0\0\0\0\0\0\0\0tmp/\0\0\0\0\0\0\0\0iris/\0\0\0\0\0\0\0zsh*
1028 %\0nrable
1029 Mailboxes/\0\0mail/\0\0\0\0\0\0\0notes
1031 (The pattern \fC*(R)\fP matches all readable files in the current
1032 directory, and \fC*(^R)\fP matches all unreadable files.)
1034 Most other shells have aliases of this kind (\fIcommand\fP aliases).
1035 However, \fBzsh\fP also has \fIglobal\fP aliases, which are substituted
1036 anywhere on a line.
1037 Global aliases can be used to abbreviate frequently-typed
1038 usernames, hostnames, etc.
1040 %\0alias\0-g\0me=pfalstad\0gun=egsirer\0mjm=maruchck
1041 %\0who\0|\0grep\0me
1042 pfalstad\0ttyp0\0\0\0May\024\003:39\0\0\0(mickey.Princeton)
1043 pfalstad\0ttyp5\0\0\0May\024\003:42\0\0\0(mickey.Princeton)
1044 %\0fm\0gun
1045 Login\0name:\0egsirer\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0In\0real\0life:\0Emin\0Gun\0Sirer
1046 Directory:\0/u/egsirer\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0Shell:\0/bin/sh
1047 Last\0login\0Thu\0May\023\019:05\0on\0ttyq3\0from\0bow.Princeton.ED
1048 New\0mail\0received\0Fri\0May\024\002:30:28\01991;
1049 \0\0unread\0since\0Fri\0May\024\002:30:27\01991
1050 %\0alias\0-g\0phx=phoenix.princeton.edu\0warc=wuarchive.wustl.edu
1051 %\0ftp\0warc
1052 Connected\0to\0wuarchive.wustl.edu.
1054 Here are some more interesting uses.
1056 %\0alias\0-g\0M='|\0more'\0GF='|\0fgrep\0-f\0~/.friends'
1057 %\0who\0M\0\0\0#\0\fIpipes\0the\0output\0of\0\fCwho\fI\0through\0\fCmore
1058 %\0who\0GF\0\0#\0\fIsee\0if\0your\0friends\0are\0on\fC
1059 %\0w\0GF\0\0\0\0#\0\fIsee\0what\0your\0friends\0are\0doing
1061 Another example makes use of \fBzsh\fP's process substitution.
1062 If you run NIS, and you miss being able to do this:
1064 %\0grep\0pfalstad\0/etc/passwd
1066 you can define an alias that will seem more natural
1067 than \fCypmatch pfalstad passwd\fP:
1069 %\0alias\0-g\0PASS='<(ypcat\0passwd)'
1070 %\0grep\0pfalstad\0PASS
1071 pfalstad:*:3564:35:Paul\0John\0Falstad:/u/pfalstad:/usr/princeton/bin/zsh
1073 If you're really crazy, you can even call it \fC/etc/passwd\fP:
1075 %\0alias\0-g\0/etc/passwd='<(ypcat\0passwd)'
1076 %\0grep\0pfalstad\0/etc/passwd
1077 pfalstad:*:3564:35:Paul\0John\0Falstad:/u/pfalstad:/usr/princeton/bin/zsh
1079 The last example shows one of the perils of global aliases;
1080 they have a lot of potential to cause confusion.
1081 For example, if you defined a global alias called \fC|\fP (which is
1082 possible), \fBzsh\fP would begin to act very strangely; every pipe
1083 symbol would be replaced with the text of your alias.
1084 To some extent, global aliases are like macros in C;
1085 discretion is advised in using them and in choosing names for them.
1086 Using names in all caps is not a bad idea, especially
1087 for aliases which introduce shell metasyntax (like \fCM\fP and \fCGF\fP
1088 above).
1090 Note that \fBzsh\fP aliases are not like csh aliases.  The syntax for
1091 defining them is different, and they do not have arguments.
1092 All your favorite csh aliases will probably not work under \fBzsh\fP.
1093 For example, if you try:
1095 alias\0rm\0mv\0'\e!*\0/tmp/wastebasket'
1097 no aliases will be defined, but \fBzsh\fP will not report an error.
1098 In csh, this line defines an alias that makes \fCrm\fP safe---files
1099 that are \fCrm\fP'd will be moved to a temporary directory instead of
1100 instantly destroyed.  In \fBzsh\fP's syntax, however, this line asks
1101 the shell to print any existing alias definitions for \fCrm\fP,
1102 \fCmv\fP, or \fC!*\ /tmp/wastebasket\fP.  Since there are none, most
1103 likely, the shell will not print anything, although \fCalias\fP will
1104 return a nonzero exit code.  The proper syntax is this:
1106 alias\0rm='mv\0\e!*\0/tmp/wastebasket'
1108 However, this won't work either:
1110 %\0rm\0foo.dvi
1111 zsh:\0no\0matches\0found:\0!*
1113 While this makes \fCrm\fP safe, it is certainly not what the user
1114 intended.  In \fBzsh\fP, you must use a shell function for this:
1116 %\0unalias\0rm
1117 %\0rm\0()\0{\0mv\0$*\0/tmp/wastebasket\0}
1118 %\0rm\0foo.dvi
1119 %\0ls\0/tmp/wastebasket
1120 foo.dvi
1122 While this is much cleaner and easier to read (I hope you will
1123 agree), it is not csh-compatible.  Therefore, a script to convert
1124 csh aliases and variables has been provided.  You should only need to use it
1125 once, to convert all your csh aliases and parameters to \fBzsh\fP format:
1127 %\0csh
1128 csh>\0alias
1129 l\0\0\0\0\0\0\0ls\0-AF
1130 more\0\0\0\0less
1131 on\0\0\0\0\0\0last\0-2\0!:1\0;\0who\0|\0grep\0!:1
1132 csh>\0exit
1133 %\0c2z\0>neat_zsh_aliases
1134 %\0cat\0neat_zsh_aliases
1135 alias\0l='ls\0-AF'
1136 alias\0more='less'
1137 on\0()\0{\0last\0-2\0$1\0;\0who\0|\0grep\0$1\0}
1138 \&...
1140 The first two aliases were converted to regular \fBzsh\fP aliases, while
1141 the third, since it needed to handle arguments, was converted to
1142 a function.  \fCc2z\fP can convert most aliases to \fBzsh\fP format without
1143 any problems.  However, if you're using some really arcane csh tricks,
1144 or if you have an alias with a name like \fCdo\fP (which is reserved
1145 in \fBzsh\fP), you may have to fix some of the aliases by hand.
1147 The \fCc2z\fP script checks your csh setup, and produces a list
1148 of \fBzsh\fP commands which replicate your aliases and parameter settings
1149 as closely as possible.  You could include its output in your
1150 startup file, \fC.zshrc\fP.
1151 .Sh "History"
1153 There are several ways to manipulate history in \fBzsh\fP.
1154 One way is to use csh-style \fC!\fP history:
1156 %\0/usr/local/bin/!:0\0!-2*:s/foo/bar/\0>>!$
1158 If you don't want to use this, you can turn it off
1159 by typing \fCsetopt nobanghist\fP.  If you are afraid of accidentally
1160 executing the wrong command you can set the \fIHISTVERIFY\fP option.
1161 If this option is set, commands that result from history expansion
1162 will not be executed immediately, but will be put back into the editor
1163 buffer for further consideration.
1165 If you're not familiar with \fC!\fP history, here follows some
1166 explanation.  History substitutions always start with a \fC!\fP,
1167 commonly called \*Qbang\*U.  After the \fC!\fP comes an (optional)
1168 designation of which \*Qevent\*U (command) to use, then a colon, and
1169 then a designation of what word of that command to use.  For example,
1170 \fC!-\fIn\fR refers to the command \fIn\fP commands ago.
1172 %\0ls
1173 foo\0\0bar
1174 %\0cd\0foo
1175 %\0!-2
1177 baz\0\0bam
1179 No word designator was used, which means that the whole command
1180 referred to was repeated.  Note that the shell will echo the result of
1181 the history substitution.  The word designator can, among other
1182 things, be a number indicating the argument to use, where \fC0\fP is
1183 the command.
1185 %\0/usr/bin/ls\0foo
1187 %\0!:0\0bar
1188 /usr/bin/ls\0bar
1191 In this example, no event designator was used, which tells \fBzsh\fP
1192 to use the previous command.  A \fC$\fP specifies the last argument
1194 %\0mkdir\0/usr/local/lib/emacs/site-lisp/calc
1195 %\0cd\0!:$
1196 cd\0/usr/local/lib/emacs/site-lisp/calc
1198 If you use more words of the same command, only the first \fC!\fP
1199 needs an event designator.
1201 %\0make\0prig\0>>\0make.log
1202 make:\0***\0No\0rule\0to\0make\0target\0`prig'.\0\0Stop.
1203 %\0cd\0src
1204 %\0!-2:0\0prog\0>>\0!:$
1205 make\0prog\0>>\0make.log
1207 This is different from csh, where a bang with no event designator
1208 always refers to the previous command.  If you actually like this
1209 behaviour, set the \fICSHJUNKIEHISTORY\fP option.
1211 %\0setopt\0cshjunkiehistory
1212 %\0!-2:0\0prog2\0>>\0!:$
1213 make\0prog2\0>>\0cshjunkiehistory
1215 Another way to use history is to use the \fCfc\fP command.  For
1216 example, if you type an erroneous command:
1218 %\0for\0i\0in\0`cat\0/etc/clients`\0
1219 \0do\0
1220 \0rpu\0$i\0
1221 \0done
1222 zsh:\0command\0not\0found:\0rpu
1223 zsh:\0command\0not\0found:\0rpu
1224 zsh:\0command\0not\0found:\0rpu
1225 \&\fR...
1227 typing \fCfc\fP will execute an editor on this command, allowing
1228 you to fix it.  (The default editor is \fCvi\fP, by the way,
1229 not \fCed\fP).
1231 %\0fc
1233 /rpu/s//rup/p
1234 \0rup\0$i\0
1238 for\0i\0in\0`cat\0/etc/clients`\0
1239 \0do\0
1240 \0rup\0$i\0
1241 \0done
1242 \0\0\0\0\0\0\0\0beam\0\0\0\0up\0\02\0days,\010:17,\0\0\0\0load\0average:\00.86,\00.80,\00.50
1243 \0\0\0\0\0\0\0\0\0bow\0\0\0\0up\0\04\0days,\0\08:41,\0\0\0\0load\0average:\00.91,\00.80,\00.50
1244 \0\0\0\0\0\0\0\0burn\0\0\0\0up\0\0\0\0\0\0\0\0\0\017:18,\0\0\0\0load\0average:\00.91,\00.80,\00.50
1245 \0\0\0\0\0\0\0burst\0\0\0\0up\0\09\0days,\0\01:49,\0\0\0\0load\0average:\00.95,\00.80,\00.50
1246 \0\0\0\0\0\0\0\0\0tan\0\0\0\0up\0\0\0\0\0\0\0\0\0\011:14,\0\0\0\0load\0average:\00.91,\00.80,\00.50
1247 \0\0\0\0\0\0\0bathe\0\0\0\0up\0\03\0days,\017:49,\0\0\0\0load\0average:\01.84,\01.79,\01.50
1248 \0\0\0\0\0\0\0\0bird\0\0\0\0up\0\01\0day,\0\0\09:13,\0\0\0\0load\0average:\01.95,\01.82,\01.51
1249 \0\0\0\0\0\0bonnet\0\0\0\0up\0\02\0days,\021:18,\0\0\0\0load\0average:\00.93,\00.80,\00.50
1250 \&\fR...
1252 A variant of the \fCfc\fP command is \fCr\fP, which redoes the last
1253 command, with optional changes:
1255 %\0echo\0foo
1257 %\0r
1258 echo\0foo
1261 %\0echo\0foo
1263 %\0r\0foo=bar
1264 echo\0bar
1267 .Sh "Command Line Editing"
1269 \fBzsh\fP's command line editor, \fBZLE\fP, is quite powerful.
1270 It is designed to emulate either emacs or vi; the default
1271 is emacs.  To set the bindings for vi mode, type \fCbindkey -v\fP.  If
1272 your \fBEDITOR\fP or \fBVISUAL\fP environment variable is vi,
1273 \fBzsh\fP will use vi emulation by default.  You can then switch to
1274 emacs mode with \fCbindkey -e\fP.
1276 In addition to basic editing, the shell allows you to 
1277 recall previous lines in the history.  In emacs mode,
1278 this is done with \fI^P\fP (control-P) or (on many terminals) with the
1279 cursor-up key:
1281 %\0ls\0~
1282 -\0\0\0\0\0\0\0\0\0\0\0README\0\0\0\0\0\0file\0\0\0\0\0\0\0\0mail\0\0\0\0\0\0\0\0pub\0\0\0\0\0\0\0\0\0tmp
1283 Mailboxes\0\0\0bin\0\0\0\0\0\0\0\0\0func\0\0\0\0\0\0\0\0nicecolors\0\0scr\0\0\0\0\0\0\0\0\0zsh
1284 News\0\0\0\0\0\0\0\0etc\0\0\0\0\0\0\0\0\0iris\0\0\0\0\0\0\0\0notes\0\0\0\0\0\0\0src
1285 %\0echo\0foobar
1286 foobar
1287 %\0\fI^P\fC
1288 %\0echo\0foobar\fI^P\fC
1289 %\0ls\0~_
1291 Pressing \fI^P\fP once brings up the previous line (\fCecho foobar\fP);
1292 pressing it again brings up the line before that (\fCls ~\fP).
1293 The cursor is left at the end of the line, allowing you to
1294 edit the line if desired before executing it.
1295 In many cases, \fBZLE\fP eliminates the need for the \fCfc\fP command,
1296 since it is powerful enough to handle even multiline commands:
1298 %\0for\0i\0in\0a\0b\0c\0d\0e
1299 >\0do
1300 >\0echo\0$i
1301 >\0done
1307 %\0\fI^P\fC
1308 %\0for\0i\0in\0a\0b\0c\0d\0e\0
1309 \0do\0
1310 \0echo\0$i\0
1311 \0done_
1313 Now you can just move up to the part you want to change...
1315 %\0for\0i\0in\0\kxa\l'|\nxu\(ul'\0b\0c\0d\0e
1316 \0do\0
1317 \0echo\0$i\0
1318 \0done
1320 change it, and execute the new command.
1322 %\0for\0i\0in\0f\0g\0h\0i\0j
1323 \0do\0
1324 \0echo\0$i\0
1325 \0done
1332 Also, you can search the history for a certain command using
1333 \fIESC-P\fP, this will look for the last command that started with the
1334 (part of the) word at the beginning of the current line.  Hitting
1335 \fIESC-P\fP another time gets you the command before that, etc.
1337 %\0set\0\fIESC-P\fC
1338 %\0setopt\0autolist\0\fIESC-P\fC
1339 %\0setopt\0nocorrect_
1341 Another way is to do an incremental search, emacs-style:
1343 %\0\fI^R\fC
1344 %\0_
1345 i-search:
1347 %\0l\kxs\l'|\nxu\(ul'\0/usr/bin
1348 i-search:\0l
1350 %\0date\0>\0foofile\kx.\l'|\nxu\(ul'c
1351 i-search:\0le
1353 Suppose you have retrieved an old history event in one of these ways
1354 and would like to execute several consecutive old commands starting
1355 with this one.  \fC^O\fP will execute the current command and then put
1356 the next command from the history into the editor buffer.  Typing
1357 \fC^O\fP several times will therefore reexecute several consecutive
1358 commands from the history.  Of course, you can edit some of those
1359 commands in between.
1361 In addition to completion (see below), \fITAB\fP performs expansion if
1362 possible.
1364 %\0ls\0*.c\fITAB\fC
1365 %\0ls\0foofile.c\0fortune.c\0rnd.c\0strfile.c\0unstr.c_
1367 For example, suppose you have a bunch of weird files in an important
1368 directory:
1370 %\0ls
1371 \0\0*\0*\0*\0\0\0\0\0\0\0;\0&\0%\0$??foo\0\0dspfok\0\0\0\0\0\0\0\0foo.c
1372 \0\0!"foo"!\0\0\0\0\0\0\0`\0\e\0`\0\0\0\0\0\0\0\0\0foo\0\0\0\0\0\0\0\0\0\0\0rrr
1374 You want to remove them, but you don't want to damage \fCfoo.c\fP.
1375 Here is one way to do this:
1377 %\0rm\0*\fITAB\fC
1378 %\0rm\0\e\0\e\0\e*\e\0\e*\e\0\e*\e\0\e\0\e\0\0\e!\e"foo\e"\e!\0\e;\e\0\e&\e\0%\e\0\e$'
1380 'foo\0\e`\e\0\e\e\e\0\e`\0dspfok\0foo\0foo.c\0rrr_
1382 When you expand \fC*\fP, \fBzsh\fP inserts the names of all the files
1383 into the editing buffer, with proper shell quoting.
1384 Now, just move back and remove \fCfoo.c\fP from the buffer:
1386 %\0rm\0\e\0\e\0\e*\e\0\e*\e\0\e*\e\0\e\0\e\0\0\e!\e"foo\e"\e!\0\e;\e\0\e&\e\0%\e\0\e$'
1388 'foo\0\e`\e\0\e\e\e\0\e`\0dspfok\0foo\0\kxr\l'|\nxu\(ul'rr
1390 and press return.
1391 Everything except \fCfoo.c\fP will be deleted from the directory.  If
1392 you do not want to actually expand the current word, but would like to
1393 see what the matches are, type \fC^Xg\fP.
1395 %\0rm\0f*\fI^Xg\fP
1396 foo\0\0\0\0foo.c
1397 %\0rm\0f*_
1399 Here's another trick; let's say you have typed this command in:
1401 %\0gcc\0-o\0x.out\0foob.c\0-g\0-Wpointer-arith\0-Wtrigraphs_
1403 and you forget which library you want.  You need to escape
1404 out for a minute and check by typing
1405 \fCls /usr/lib\fP, or some other such command;
1406 but you don't want to retype the whole command again,
1407 and you can't press return now because the current command
1408 is incomplete.
1409 In \fBzsh\fP, you can put the line on the \fIbuffer stack\fP, using
1410 \fIESC-Q\fP, and type some other commands.  The next time a prompt is printed,
1411 the \fCgcc\fP line will be popped off the stack and put
1412 in the editing buffer automatically; you can then enter the
1413 proper library name and press return (or, \fIESC-Q\fP again and look
1414 for some other libraries whose names you forgot).
1416 A similar situation: what if you forget the option to gcc that
1417 finds bugs using AI techniques?  You could either use \fIESC-Q\fP
1418 again, and type \fCman gcc\fP, or you could press \fIESC-H\fP, which
1419 essentially does the same thing; it puts the current line on
1420 the buffer stack, and executes the command \fCrun-help gcc\fP,
1421 where \fCrun-help\fP is an alias for \fCman\fP.
1423 Another interesting command is \fIESC-A\fP.  This executes the
1424 current line, but retains it in the buffer, so that it appears
1425 again when the next prompt is printed.
1426 Also, the cursor stays in the same place.
1427 This is useful for executing a series of similar commands:
1429 %\0cc\0grok.c\0-g\0-lc\0-lgl\0-lsun\0-lmalloc\0-Bstatic\0-o\0b.out
1430 %\0cc\0fubar.c\0-g\0-lc\0-lgl\0-lsun\0-lmalloc\0-Bstatic\0-o\0b.out
1431 %\0cc\0fooble.c\0-g\0-lc\0-lgl\0-lsun\0-lmalloc\0-Bstatic\0-o\0b.out
1434 The \fIESC-'\fP command is useful for managing the shell's quoting
1435 conventions.  Let's say you want to print this string:
1437 don't\0do\0that;\0type\0'rm\0-rf\0\e*',\0with\0a\0\e\0before\0the\0*.
1439 All that is necessary is to type it into the editing buffer:
1441 %\0don't\0do\0that;\0type\0'rm\0-rf\0\e*',\0with\0a\0\e\0before\0the\0*.
1443 press \fIESC-'\fP (escape-quote):
1445 %\0'don'\e''t\0do\0that;\0type\0'\e''rm\0-rf\0\e*'\e'',\0with\0a\0\e\0before\0the\0*.'
1447 then move to the beginning and add the \fCecho\fP command.
1449 %\0echo\0'don'\e''t\0do\0that;\0type\0'\e''rm\0-rf\0\e*'\e'',\0with\0a\0\e\0before\0the\0*.'
1450 don't\0do\0that;\0type\0'rm\0-rf\0\e*',\0with\0a\0\e\0before\0the\0*.
1452 Let's say you want to create an alias to do this \fCecho\fP command.
1453 This can be done by recalling the line with \fI^P\fP and pressing
1454 \fIESC-'\fP again:
1456 %\0'echo\0'\e''don'\e''\e'\e'''\e''t\0do\0that;\0type\0'\e''\e'\e'''\e''rm\0-rf
1457 \e*'\e''\e'\e'''\e'',\0with\0a\0\e\0before\0the\0*.'\e'''
1459 and then move to the beginning and add the command to create
1460 an alias.
1462 %\0alias\0zoof='echo\0'\e''don'\e''\e'\e'''\e''t\0do\0that;\0type\0'\e''\e'\e'''\e''rm
1463 -rf\0\e*'\e''\e'\e'''\e'',\0with\0a\0\e\0before\0the\0*.'\e'''
1464 %\0zoof
1465 don't\0do\0that;\0type\0'rm\0-rf\0\e*',\0with\0a\0\e\0before\0the\0*.
1467 If one of these fancy editor commands changes your command line in a
1468 way you did not intend, you can undo changes with \fC^_\fP, if you can
1469 get it out of your keyboard, or \fC^X^U\fP, otherwise.
1471 Another use of the editor is to edit the value of variables.
1472 For example, an easy way to change your path is to use
1473 the \fCvared\fP command:
1475 %\0vared\0PATH
1476 >\0/u/pfalstad/scr:/u/pfalstad/bin/sun4:/u/maruchck/scr:/u/subbarao/bin:/u/maruc
1477 hck/bin:/u/subbarao/scripts:/usr/princeton/bin:/usr/ucb:/usr/bin:/bin:/usr/host
1478 s:/usr/princeton/bin/X11:/./usr/lang:/./usr/etc:/./etc
1480 You can now edit the path.  When you press return, the contents
1481 of the edit buffer will be assigned to \fBPATH\fP.
1482 .Sh "Completion"
1484 Another great \fBzsh\fP feature is completion.  If you hit \fITAB\fP, \fBzsh\fP
1485 will complete all kinds of stuff.  Like commands or filenames:
1487 %\0comp\fITAB\fC
1488 %\0compress\0_
1490 %\0ls\0nic\fITAB\fC
1491 %\0ls\0nicecolors\0_
1493 %\0ls\0/usr/pr\fITAB\fC
1494 %\0ls\0/usr/princeton/_
1496 %\0ls\0-l\0=com\fITAB\fC
1497 %\0ls\0-l\0=compress\0_
1499 If the completion is ambiguous, the editor will beep.  If you find
1500 this annoying, you can set the \fINOLISTBEEP\fP option.  Completion
1501 can even be done in the middle of words.  To use this, you will have
1502 to set the \fICOMPLETEINWORD\fP option:
1504 %\0setopt\0completeinword
1505 %\0ls\0/usr/p\kxt\l'|\nxu\(ul'on\fITAB\fC
1506 %\0ls\0/usr/prince\kxt\l'|\nxu\(ul'on/
1507 %\0setopt\0alwaystoend
1508 %\0ls\0/usr/p\kxt\l'|\nxu\(ul'on\fITAB\fC
1509 %\0ls\0/usr/princeton/_
1511 You can list possible completions by pressing \fI^D\fP:
1513 %\0ls\0/vmu\fITAB\0\(embeep\(em\fC
1514 %\0ls\0/vmunix_
1515 %\0ls\0/vmunix\fI^D\fC
1516 vmunix\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0vmunix.old\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1517 vmunix.new.kernelmap.old\0\0vmunix.org
1519 Or, you could just set the \fIAUTOLIST\fP option:
1521 %\0setopt\0autolist
1522 %\0ls\0/vmu\fITAB\0\(embeep\(em\fC
1523 vmunix\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0vmunix.old\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1524 vmunix.new.kernelmap.old\0\0vmunix.org
1525 %\0ls\0/vmunix_
1527 If you like to see the types of the files in these lists, like in
1528 \fCls\ -F\fP, you can set the \fILISTTYPES\fP option.  Together with
1529 \fIAUTOLIST\fP you can use \fILISTAMBIGUOUS\fP.  This will only list
1530 the possibilities if there is no unambiguous part to add:
1532 %\0setopt\0listambiguous
1533 %\0ls\0/vmu\fITAB\0\(embeep\(em\fC
1534 %\0ls\0/vmunix_\fITAB\0\(embeep\(em\fC
1535 vmunix\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0vmunix.old\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1536 vmunix.new.kernelmap.old\0\0vmunix.org
1538 If you don't want several of these listings to scroll the screen so
1539 much, the \fIALWAYSLASTPROMPT\fP option is useful.  If set, you can
1540 continue to edit the line you were editing, with the completion
1541 listing appearing beneath it.
1543 Another interesting option is \fIMENUCOMPLETE\fP.  This affects the
1544 way \fITAB\fP works.  Let's look at the \fC/vmunix\fP example again:
1546 %\0setopt\0menucomplete
1547 %\0ls\0/vmu\fITAB\fC
1548 %\0ls\0/vmunix\fITAB\fC
1549 %\0ls\0/vmunix.new.kernelmap.old\fITAB\fC
1550 %\0ls\0/vmunix.old_
1552 Each time you press \fITAB\fP, it displays the next possible completion.
1553 In this way, you can cycle through the possible completions until
1554 you find the one you want.
1556 The \fIAUTOMENU\fP option makes a nice compromise between this method
1557 of completion and the regular method.  If you set this option,
1558 pressing \fITAB\fP once completes the unambiguous part normally,
1559 pressing the \fITAB\fP key repeatedly after an ambiguous completion
1560 will cycle through the possible completions.
1562 Another option you could set is \fIRECEXACT\fP, which causes
1563 exact matches to be accepted, even if there are other possible
1564 completions:
1566 %\0setopt\0recexact
1567 %\0ls\0/vmu\fITAB\0\(embeep\(em\fC
1568 vmunix\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0vmunix.old\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1569 vmunix.new.kernelmap.old\0\0vmunix.org
1570 %\0ls\0/vmunix_\fITAB\fC
1571 %\0ls\0/vmunix\0_
1573 To facilitate the typing of pathnames, a slash will be added whenever
1574 a directory is completed.  Some computers don't like the spurious
1575 slashes at the end of directory names.  In that case, the
1576 \fIAUTOREMOVESLASH\fP option comes to rescue.  It will remove these
1577 slashes when you type a space or return after them.
1579 The \fIfignore\fP variable lists suffixes of files to ignore
1580 during completion.
1582 %\0ls\0foo\fITAB\0\(embeep\(em\fC
1583 foofile.c\0\0foofile.o
1584 %\0fignore=(\0.o\0\e~\0.bak\0.junk\0)
1585 %\0ls\0foo\fITAB\fP
1586 %\0ls\0foofile.c\0_
1588 Since \fCfoofile.o\fP has a suffix that is in the \fCfignore\fP list,
1589 it was not considered a possible completion of \fCfoo\fP.
1591 Username completion is also supported:
1593 %\0ls\0~pfal\fITAB\fC
1594 %\0ls\0~pfalstad/_
1596 and parameter name completion:
1598 %\0echo\0$ORG\fITAB\fC
1599 %\0echo\0$ORGANIZATION\0_
1600 %\0echo\0${ORG\fITAB\fC
1601 %\0echo\0${ORGANIZATION\0_
1603 Note that in the last example a space is added after the completion as
1604 usual.  But if you want to add a colon or closing brace, you probably
1605 don't want this extra space.  Setting the \fIAUTOPARAMKEYS\fP option
1606 will automatically remove this space if you type a colon or closing
1607 brace after such a completion.
1609 There is also option completion:
1611 %\0setopt\0nocl\fITAB\fC
1612 %\0setopt\0noclobber\0_
1614 and binding completion:
1616 %\0bindkey\0'^X^X'\0pu\fITAB\fC
1617 %\0bindkey\0'^X^X'\0push-line\0_
1619 The \fCcompctl\fP command is used to control completion of the
1620 arguments of specific commands.  For example, to specify that certain
1621 commands take other commands as arguments, you use \fCcompctl -c\fP:
1623 %\0compctl\0-c\0man\0nohup
1624 %\0man\0upt\fITAB\fC
1625 %\0man\0uptime\0_
1627 To specify that a command should complete filenames, you should use
1628 \fCcompctl -f\fP.  This is the default.  It can be combined with \fC-c\fP,
1629 as well.
1631 %\0compctl\0-cf\0echo
1632 %\0echo\0upt\fITAB\fC
1633 %\0echo\0uptime\0_
1635 %\0echo\0fo\fITAB\fC
1636 %\0echo\0foo.c
1638 Similarly, use \fC-o\fP to specify options, \fC-v\fP to specify
1639 variables, and \fC-b\fP to specify bindings.
1641 %\0compctl\0-o\0setopt\0unsetopt
1642 %\0compctl\0-v\0typeset\0vared\0unset\0export
1643 %\0compctl\0-b\0bindkey
1645 You can also use \fC-k\fP to specify a custom list of keywords to use
1646 in completion.  After the \fC-k\fP comes either the name of an array
1647 or a literal array to take completions from.
1649 %\0ftphosts=(ftp.uu.net\0wuarchive.wustl.edu)
1650 %\0compctl\0-k\0ftphosts\0ftp
1651 %\0ftp\0wu\fITAB\fC
1652 %\0ftp\0wuarchive.wustl.edu\0_
1654 %\0compctl\0-k\0'(cpirazzi\0subbarao\0sukthnkr)'\0mail\0finger
1655 %\0finger\0cp\fITAB\fC
1656 %\0finger\0cpirazzi\0_
1658 To better specify the files to complete for a command, use the
1659 \fC-g\fP option which takes any glob pattern as an argument.  Be sure
1660 to quote the glob patterns as otherwise they will be expanded when the
1661 \fCcompctl\fP command is run.
1663 %\0ls
1664 letter.tex\0\0letter.dvi\0\0letter.aux\0\0letter.log\0\0letter.toc
1665 %\0compctl\0-g\0'*.tex'\0latex
1666 %\0compctl\0-g\0'*.dvi'\0xdvi\0dvips
1667 %\0latex\0l\fITAB\fC
1668 %\0latex\0letter.tex\0_
1669 %\0xdvi\0l\fITAB\fC
1670 %\0xdvi\0letter.dvi\0_
1672 Glob patterns can include qualifiers within parentheses.  To rmdir
1673 only directories and cd to directories and symbolic links pointing to
1674 them:
1676 %\0compctl\0-g\0'*(-/)'\0cd
1677 %\0compctl\0-g\0'*(/)'\0rmdir
1679 RCS users like to run commands on files which are not in the current
1680 directory, but in the RCS subdirectory where they all get \fC,v\fP
1681 suffixes.  They might like to use
1683 %\0compctl\0-g\0'RCS/*(:t:s/\e,v//)'\0co\0rlog\0rcs
1684 %\0ls\0RCS
1685 builtin.c,v\0\0lex.c,v\0\0\0\0\0\0zle_main.c,v
1686 %\0rlog\0bu\fITAB\fC
1687 %\0rlog\0builtin.c\0_
1689 The \fC:t\fP modifier keeps only the last part of the pathname and the
1690 \fC:s/\e,v//\fP will replace any \fC,v\fP by nothing.
1692 The \fC-s\fP flag is similar to \fC-g\fP, but it uses all expansions,
1693 instead of just globbing, like brace expansion, parameter substitution
1694 and command substitution.
1696 %\0compctl\0-s\0'$(setopt)'\0unsetopt
1698 will only complete options which are actually set to be arguments to
1699 \fCunsetopt\fP.
1701 Sometimes a command takes another command as its argument.  You can
1702 tell \fBzsh\fP to complete commands as the first argument to such a
1703 command and then use the completion method of the second command.  The
1704 \fC-l\fP flag with a null-string argument is used for this.
1706 %\0compctl\0-l\0''\0nohup\0exec
1707 %\0nohup\0comp\fITAB\fC
1708 %\0nohup\0compress\0_
1709 %\0nohup\0compress\0fil\fITAB\fC
1710 %\0nohup\0compress\0filename\0_
1712 Sometimes you would like to run really complicated commands to find
1713 out what the possible completions are.  To do this, you can specify a
1714 shell function to be called that will assign the possible completions
1715 to a variable called reply.  Note that this variable must be an array.
1716 Here's another (much slower) way to get the completions for \fCco\fP
1717 and friends:
1719 %\0function\0getrcs\0{
1720 >\0reply=()
1721 >\0for\0i\0in\0RCS/*
1722 >\0\0\0do
1723 >\0\0\0reply=($reply[*]\0$(basename\0$i\0,v))
1724 >\0\0\0done
1725 >\0}
1726 %\0compctl\0-K\0getrcs\0co\0rlog\0rcs
1728 Some command arguments use a prefix that is not a part of the things
1729 to complete.  The kill builtin command takes a signal name after a
1730 \fC-\fP.  To make such a prefix be ignored in the completion process,
1731 you can use the \fC-P\fP flag.
1733 %\0compctl\0-P\0-\0-k\0signals\0kill
1734 %\0kill\0-H\fITAB\fP
1735 %\0kill\0-HUP\0_
1737 TeX is usually run on files ending in \fC.tex\fP, but also sometimes
1738 on other files.  It is somewhat annoying to specify that the arguments
1739 of TeX should end in \fC.tex\fP and then not be able to complete these
1740 other files.  Therefore you can specify things like \*QComplete to
1741 files ending in \fC.tex\fP if available, otherwise complete to any
1742 filename.\*U.  This is done with \fIxor\fPed completion:
1744 %\0compctl\0-g\0'*.tex'\0+\0-f\0tex
1746 The \fC+\fP tells the editor to only take the next thing into account
1747 if the current one doesn't generate any matches.  If you have not
1748 changed the default completion, the above example is in fact
1749 equivalent to
1751 %\0compctl\0-g\0'*.tex'\0+\0tex
1753 as a lone \fC+\fP at the end is equivalent to specifying the default
1754 completion after the \fC+\fP.  This form of completion is also
1755 frequently used if you want to run some command only on a certain type
1756 of files, but not necessarily in the current directory.  In this case
1757 you will want to complete both files of this type and directories.
1758 Depending on your preferences you can use either of
1760 %\0compctl\0-g\0'*.ps'\0+\0-g\0'*(-/)'\0ghostview
1761 %\0compctl\0-g\0'*.ps\0*(-/)'\0ghostview
1763 where the first one will only complete directories (and symbolic links
1764 pointing to directories) if no postscript file matches the already
1765 typed part of the argument.
1766 .Sh "Extended completion"
1768 If you play with completion, you will soon notice that you would like
1769 to specify what to complete, depending on what flags you give to the
1770 command and where you are on the command line.  For example, a command
1771 could take any filename argument after a \fC-f\fP flag, a username
1772 after a \fC-u\fP flag and an executable after a \fC-x\fP flag.  This
1773 section will introduce you to the ways to specify these things.  To
1774 many people it seems rather difficult at first, but taking the trouble
1775 to understand it can save you lots of typing in the end.  Even I keep
1776 being surprised when \fBzsh\fP manages to complete a small or even
1777 empty prefix to the right file in a large directory.
1779 To tell \fBzsh\fP about these kinds of completion, you use \*Qextended
1780 completion\*U by specifying the \fC-x\fP flag to compctl.  The
1781 \fC-x\fP flag takes a list of patterns/flags pairs.  The patterns
1782 specify when to complete and the flags specify what.  The flags are
1783 simply those mentioned above, like \fC-f\fP or \fC-g \fIglob
1784 pattern\fR.
1786 As an example, the \fCr[\fIstring1\fC,\fIstring2\fC]\fR pattern
1787 matches if the cursor is after something that starts with
1788 \fIstring1\fP and before something that starts with \fIstring2\fP.
1789 The \fIstring2\fP is often something that you do not want to match
1790 anything at all.
1792 %\0ls
1793 foo1\0\0\0bar1\0\0\0foo.Z\0\0bar.Z
1794 %\0compctl\0-g\0'^*.Z'\0-x\0'r[-d,---]'\0-g\0'*.Z'\0--\0compress
1795 %\0compress\0f\fITAB\fP
1796 %\0compress\0foo1\0_
1797 %\0compress\0-d\0f\fITAB\fP
1798 %\0compress\0-d\0foo.Z\0_
1800 In the above example, if the cursor is after the \fC-d\fP the pattern
1801 will match and therefore \fBzsh\fP uses the \fC-g *.Z\fP flag that will only
1802 complete files ending in \fC.Z\fP.  Otherwise, if no pattern matches,
1803 it will use the flags before the \fC-x\fP and in this case complete
1804 every file that does not end in \fC.Z\fP.
1806 The \fCs[\fIstring\fC]\fR pattern matches if the current word starts
1807 with \fIstring\fP.  The \fIstring\fP itself is not considered to be
1808 part of the completion.
1810 %\0compctl\0-x\0's[-]'\0-k\0signals\0--\0kill
1811 %\0kill\0-H\fITAB\fP
1812 %\0kill\0-HUP\0_
1814 The \fCtar\fP command takes a tar file as an argument after the
1815 \fC-f\fP option.  The \fCc[\fIoffset\fC,\fIstring\fC]\fR pattern
1816 matches if the word in position \fIoffset\fP relative to the current
1817 word is \fIstring\fP.  More in particular, if \fIoffset\fP is -1, it
1818 matches if the previous word is \fIstring\fP.  This suggests
1820 %\0compctl\0-f\0-x\0'c[-1,-f]'\0-g\0'*.tar'\0--\0tar
1822 But this is not enough.  The \fC-f\fP option could be the last of a
1823 longer string of options.  \fCC[\fR...\fC,\fR...\fC]\fR is just like
1824 \fCc[\fR...\fC,\fR...\fC]\fR, except that it uses glob-like pattern
1825 matching for \fIstring\fP.  So
1827 %\0compctl\0-f\0-x\0'C[-1,-*f]'\0-g\0'*.tar'\0--\0tar
1829 will complete tar files after any option string ending in an \fCf\fP.
1830 But we'd like even more.  Old versions of tar used all options as the
1831 first argument, but without the minus sign.  This might be
1832 inconsistent with option usage in all other commands, but it is still
1833 supported by newer versions of \fCtar\fP.  So we would also like to
1834 complete tar files if the first argument ends in an \fCf\fP and we're
1835 right behind it.
1837 We can `and' patterns by putting them next to each other with a space
1838 between them.  We can `or' these sets by putting comma's between them.
1839 We will also need some new patterns.  \fCp[\fInum\fC]\fR will match if
1840 the current argument (the one to be completed) is the \fInum\fPth
1841 argument.  \fCW[\fIindex\fC,\fIpattern\fC]\fR will match if the
1842 argument in place \fIindex\fP matches the \fIpattern\fP.  This gives
1845 %\0compctl\0-f\0-x\0'C[-1,-*f]\0,\0W[1,*f]\0p[2]'\0-g\0'*.tar'\0--\0tar
1847 In words: If the previous argument is an option string that ends in an
1848 \fCf\fP, or the first argument ended in an \fCf\fP and it is now the
1849 second argument, then complete only filenames ending in \fC.tar\fP.
1851 All the above examples used only one set of patterns with one
1852 completion flag.  You can use several of these pattern/flag pairs
1853 separated by a \fC-\fP.  The first matching pattern will be used.
1854 Suppose you have a version of \fCtar\fP that supports compressed files
1855 by using a \fC-Z\fP option.  Leaving the old tar syntax aside for a
1856 moment, we would like to complete files ending in \fC.tar.Z\fP if a
1857 \fC-Z\fP option has been used and files ending in \fC.tar\fP
1858 otherwise, all this only after a \fC-f\fP flag.  Again, the \fC-Z\fP
1859 can be alone or it can be part of a longer option string, perhaps the
1860 same as that of the \fC-f\fP flag.  Here's how to do it; note the
1861 backslash and the secondary prompt which are not part of the
1862 \fCcompctl\fP command.
1864 %\0compctl\0-f\0-x\0'C[-1,-*Z*f]\0,\0R[-*Z*,---]\0C[-1,-*f]'\0-g\0'*.tar.Z'\0-\0\e
1865 >\0'C[-1,-*f]'\0-g\0'*.tar'\0--\0tar
1867 The first pattern set tells us to match if either the previous
1868 argument was an option string including a \fCZ\fP and ending in an
1869 \fCf\fP or there was an option string with a \fCZ\fP somewhere and the
1870 previous word was any option string ending in an \fCf\fP.  If this is
1871 the case, we need a compressed tar file.  Only if this is not the case
1872 the second pattern set will be considered.  By the way,
1873 \fCR[\fIpattern1\fC,\fIpattern2\fC]\fR is just like
1874 \fCr[\fR...\fC,\fR...\fC]\fR except that it uses pattern matching with
1875 shell metacharacters instead of just strings.
1877 You will have noticed the \fC--\fP before the command name.  This ends
1878 the list of pattern/flag pairs of \fC-x\fP.  It is usually used just
1879 before the command name, but you can also use an extended completion
1880 as one part of a list of xored completions, in which case the \fC--\fP
1881 appears just before one of the \fC+\fP signs.
1883 Note the difference between using extended completion as part of a
1884 list of xored completions as in
1886 %\0ls
1887 foo\0\0bar
1888 %\0compctl\0-x\0'r[-d,---]'\0-g\0'*.Z'\0--\0+\0-g\0'^*.Z'\0compress
1889 %\0compress\0-d\0f\fITAB\fP
1890 %\0compress\0-d\0foo\0_
1892 and specifying something before the \fC-x\fP as in
1894 %\0compctl\0-g\0'^*.Z'\0-x\0'r[-d,---]'\0-g\0'*.Z'\0--\0compress
1895 %\0compress\0-d\0f\fITAB\fP
1896 %\0compress\0-d\0f_
1898 In the first case, the alternative glob pattern (\fC^*.Z\fP) will be
1899 used if the first part does not generate any possible completions,
1900 while in the second case the alternative glob pattern will only be
1901 used if the \fCr[\fR...\fC]\fR pattern doesn't match.
1902 .Sh "Bindings"
1904 Each of the editor commands we have seen was actually a function bound
1905 by default to a certain key.  The real names of the commands are:
1907 \fCexpand-or-complete\0\0\0\fITAB\fR
1908 \fCpush-line\0\0\0\0\0\0\0\0\0\0\0\0\fIESC-Q\fR
1909 \fCrun-help\0\0\0\0\0\0\0\0\0\0\0\0\0\fIESC-H\fR
1910 \fCaccept-and-hold\0\0\0\0\0\0\fIESC-A\fR
1911 \fCquote-line\0\0\0\0\0\0\0\0\0\0\0\fIESC-'\fR
1913 These bindings are arbitrary; you could change them if you want.
1914 For example, to bind \fCaccept-line\fP to \fI^Z\fP:
1916 %\0bindkey\0'^Z'\0accept-line
1918 Another idea would be to bind the delete key to \fCdelete-char\fP;
1919 this might be convenient if you use \fI^H\fP for backspace.
1921 %\0bindkey\0'^?'\0delete-char
1923 Or, you could bind \fI^X\fP\fI^H\fP to \fCrun-help\fP:
1925 %\0bindkey\0'^X^H'\0run-help
1927 Other examples:
1929 %\0bindkey\0'^X^Z'\0universal-argument
1930 %\0bindkey\0'\0'\0magic-space
1931 %\0bindkey\0-s\0'^T'\0'uptime
1932 >\0'
1933 %\0bindkey\0'^Q'\0push-line-or-edit
1935 \fCuniversal-argument\fP multiplies the next command by 4.
1936 Thus \fI^X\fP\fI^Z\fP\fI^W\fP might delete the last four words on the line.
1937 If you bind space to \fCmagic-space\fP, then csh-style history
1938 expansion is done on the line whenever you press the space bar.
1940 Something that often happens is that I am typing a multiline command
1941 and discover an error in one of the previous lines.  In this case,
1942 \fCpush-line-or-edit\fP will put the entire multiline construct into
1943 the editor buffer.  If there is only a single line, it is equivalent
1944 to \fCpush-line\fP.
1946 The \fC-s\fP flag to \fCbindkey\fP specifies that you are binding the key
1947 to a string, not a command.  Thus \fCbindkey -s '^T' 'uptime\en'\fP
1948 lets you VMS lovers get the load average whenever you press \fI^T\fP.
1950 If you have a NeXT keyboard, the one with the \fC|\fP and \fC\e\fP keys
1951 very inconveniently placed, the following
1952 bindings may come in handy:
1954 %\0bindkey\0-s\0'\ee/'\0'\e\e'
1955 %\0bindkey\0-s\0'\ee='\0'|'
1957 Now you can type \fIALT-/\fP to get a backslash, and \fIALT-=\fP to
1958 get a vertical bar.  This only works inside \fBzsh\fP, of course;
1959 \fCbindkey\fP has no effect on the key mappings inside \fCtalk\fP
1960 or \fCmail\fP, etc.
1962 Some people like to bind \fC^S\fP and \fC^Q\fP to editor commands.
1963 Just binding these has no effect, as the terminal will catch them and
1964 use them for flow control.  You could unset them as stop and start
1965 characters, but most people like to use these for external commands.
1966 The solution is to set the \fINOFLOWCONTROL\fP option.  This will
1967 allow you to bind the start and stop characters to editor commands,
1968 while retaining their normal use for external commands.
1969 .Sh "Parameter Substitution"
1971 In \fBzsh\fP, parameters are set like this:
1973 %\0foo=bar
1974 %\0echo\0$foo
1977 Spaces before or after the \fC=\fP are frowned upon:
1979 %\0foo\0=\0bar
1980 zsh:\0command\0not\0found:\0foo
1982 Also, \fCset\fP doesn't work for setting parameters:
1984 %\0set\0foo=bar
1985 %\0set\0foo\0=\0bar
1986 %\0echo\0$foo
1990 Note that no error message was printed.  This is because both
1991 of these commands were perfectly valid; the \fCset\fP builtin
1992 assigns its arguments to the \fIpositional parameters\fP
1993 (\fC$1\fP, \fC$2\fP, etc.).
1995 %\0set\0foo=bar
1996 %\0echo\0$1
1997 foo=bar
1998 %\0set\0foo\0=\0bar
1999 %\0echo\0$3\0$2
2000 bar\0=
2002 If you're really intent on using the csh syntax, define a
2003 function like this:
2005 %\0set\0()\0{
2006 >\0\0\0\0eval\0"$1$2$3"
2007 >\0}
2008 %\0set\0foo\0=\0bar
2009 %\0set\0fuu=brrr
2010 %\0echo\0$foo\0$fuu
2011 bar\0brrr
2013 But then, of course you can't use the form of \fCset\fP with
2014 options, like \fCset -F\fP (which turns off filename generation).
2015 Also, the \fCset\fP command by itself won't list all the parameters
2016 like it should.
2017 To get around that you need a \fCcase\fP statement:
2019 %\0set\0()\0{
2020 >\0\0\0\0case\0$1\0in
2021 >\0\0\0\0-*|+*|'')\0builtin\0set\0$*\0;;
2022 >\0\0\0\0*)\0eval\0"$1$2$3"\0;;
2023 >\0\0\0\0esac
2024 >\0}
2026 For the most part, this should make csh users happy.
2028 The following sh-style operators are supported in \fBzsh\fP:
2030 %\0unset\0null
2031 %\0echo\0${foo-xxx}
2033 %\0echo\0${null-xxx}
2035 %\0unset\0null
2036 %\0echo\0${null=xxx}
2038 %\0echo\0$null
2040 %\0echo\0${foo=xxx}
2042 %\0echo\0$foo
2044 %\0unset\0null
2045 %\0echo\0${null+set}
2047 %\0echo\0${foo+set}
2050 Also, csh-style \fC:\fP modifiers may be appended to a parameter
2051 substitution.
2053 %\0echo\0$PWD
2054 /home/learning/pf/zsh/zsh2.00/src
2055 %\0echo\0$PWD:h
2056 /home/learning/pf/zsh/zsh2.00
2057 %\0echo\0$PWD:h:h
2058 /home/learning/pf/zsh
2059 %\0echo\0$PWD:t
2061 %\0name=foo.c
2062 %\0echo\0$name
2063 foo.c
2064 %\0echo\0$name:r
2066 %\0echo\0$name:e
2069 The equivalent constructs in ksh (which are also supported in \fBzsh\fP)
2070 are a bit more general and easier to remember.
2071 When the shell expands \fC${foo#\fR\fIpat\fR\fC}\fR,
2072 it checks to see if \fIpat\fP matches a substring at the beginning
2073 of the value
2074 of \fCfoo\fP.  If so, it removes that portion of \fCfoo\fP, using the shortest
2075 possible match.
2076 With \fC${foo##\fR\fIpat\fR\fC}\fR, the longest possible match is removed.
2077 \fC${foo%\fR\fIpat\fR\fC}\fR and \fC${foo%%\fR\fIpat\fR\fC}\fR remove the match
2078 from the end.
2079 Here are the ksh equivalents of the \fC:\fP modifiers:
2081 %\0echo\0${PWD%/*}
2082 /home/learning/pf/zsh/zsh2.00
2083 %\0echo\0${PWD%/*/*}
2084 /home/learning/pf/zsh
2085 %\0echo\0${PWD##*/}
2087 %\0echo\0${name%.*}
2089 %\0echo\0${name#*.}
2092 \fBzsh\fP also has upper/lowercase modifiers:
2094 %\0xx=Test
2095 %\0echo\0$xx:u
2096 TEST
2097 %\0echo\0$xx:l
2098 test
2100 and a substitution modifier:
2102 %\0echo\0$name:s/foo/bar/
2103 bar.c
2104 %\0ls
2105 foo.c\0\0\0\0foo.h\0\0\0\0foo.o\0\0\0\0foo.pro
2106 %\0for\0i\0in\0foo.*;\0mv\0$i\0$i:s/foo/bar/
2107 %\0ls
2108 bar.c\0\0\0\0bar.h\0\0\0\0bar.o\0\0\0\0bar.pro
2110 There is yet another syntax to modify substituted parameters.  You can
2111 add certain modifiers in parentheses after the opening brace like:
2113 ${(\fImodifiers\fC)\fIparameter\fC}
2115 For example, \fCo\fP sorts the words resulting from the expansion:
2117 %\0echo\0${path}
2118 /usr/bin\0/usr/bin/X11\0/etc
2119 %\0echo\0${(o)path}
2120 /etc\0/usr/bin\0/usr/bin/X11
2122 One possible source of confusion is the fact that in \fBzsh\fP,
2123 the result of parameter substitution is \fInot\fP split into
2124 words.  Thus, this will not work:
2126 %\0srcs='glob.c\0exec.c\0init.c'
2127 %\0ls\0$srcs
2128 glob.c\0exec.c\0init.c\0not\0found
2130 This is considered a feature, not a bug.
2131 If splitting were done by default, as it is in most other shells,
2132 functions like this would not work properly:
2134 $\0ll\0()\0{\0ls\0-F\0$*\0}
2135 $\0ll\0'fuu\0bar'
2136 fuu\0not\0found
2137 bar\0not\0found
2139 %\0ll\0'fuu\0bar'
2140 fuu\0bar\0not\0found
2142 Of course, a hackish workaround is available in sh (and \fBzsh\fP):
2144 %\0setopt\0shwordsplit
2145 %\0ll\0()\0{\0ls\0-F\0"$@"\0}
2146 %\0ll\0'fuu\0bar'
2147 fuu\0bar\0not\0found
2149 If you like the sh behaviour, \fBzsh\fP can accomodate you:
2151 %\0ls\0${=srcs}
2152 exec.c\0\0glob.c\0\0init.c
2153 %\0setopt\0shwordsplit
2154 %\0ls\0$srcs
2155 exec.c\0\0glob.c\0\0init.c
2157 Another way to get the \fC$srcs\fP trick to work is to use an array:
2159 %\0unset\0srcs
2160 %\0srcs=(\0glob.c\0exec.c\0init.c\0)\0\0
2161 %\0ls\0$srcs
2162 exec.c\0\0glob.c\0\0init.c
2164 or an alias:
2166 %\0alias\0-g\0SRCS='exec.c\0glob.c\0init.c'
2167 %\0ls\0SRCS
2168 exec.c\0\0glob.c\0\0init.c
2170 Another option that modifies parameter expansion is
2171 \fIRCEXPANDPARAM\fP:
2173 %\0echo\0foo/$srcs
2174 foo/glob.c\0exec.c\0init.c
2175 %\0setopt\0rcexpandparam
2176 %\0echo\0foo/$srcs
2177 foo/glob.c\0foo/exec.c\0foo/init.c
2178 %\0echo\0foo/${^srcs}
2179 foo/glob.c\0foo/exec.c\0foo/init.c
2180 %\0echo\0foo/$^srcs
2181 foo/glob.c\0foo/exec.c\0foo/init.c
2183 .Sh "Shell Parameters"
2185 The shell has many predefined parameters that may be
2186 accessed.  Here are some examples:
2188 %\0sleep\010\0&
2189 [1]\03820
2190 %\0echo\0$!
2191 3820
2192 %\0set\0a\0b\0c
2193 %\0echo\0$#
2195 %\0echo\0$ARGC
2197 %\0(\0exit\020\0)\0;\0echo\0$?
2199 %\0false;\0echo\0$status
2202 (\fC$?\fP and \fC$status\fP are equivalent.)
2204 %\0echo\0$HOST\0$HOSTTYPE
2205 dendrite\0sun4
2206 %\0echo\0$UID\0$GID
2207 701\060
2208 %\0cd\0/tmp
2209 %\0cd\0/home
2210 %\0echo\0$PWD\0$OLDPWD
2211 /home\0/tmp
2212 %\0ls\0$OLDPWD/.getwd\0
2213 /tmp/.getwd
2215 \fC~+\fP and \fC~-\fP are short for \fC$PWD\fP and \fC$OLDPWD\fP, respectively.
2217 %\0ls\0~-/.getwd
2218 /tmp/.getwd
2219 %\0ls\0-d\0~+/learning
2220 /home/learning
2221 %\0echo\0$RANDOM
2222 4880
2223 %\0echo\0$RANDOM
2224 11785
2225 %\0echo\0$RANDOM
2226 2062
2227 %\0echo\0$TTY
2228 /dev/ttyp4
2229 %\0echo\0$VERSION
2230 zsh\0v2.00.03
2231 %\0echo\0$USERNAME
2235 The \fCcdpath\fP variable sets the search path for the \fCcd\fP command.
2236 If you do not specify \fC.\fP somewhere in the path, it is assumed to
2237 be the first component.
2239 %\0cdpath=(\0/usr\0~\0~/zsh\0)
2240 %\0ls\0/usr
2241 5bin\0\0\0\0\0\0\0\0\0dict\0\0\0\0\0\0\0\0\0lang\0\0\0\0\0\0\0\0\0net\0\0\0\0\0\0\0\0\0\0sccs\0\0\0\0\0\0\0\0\0sys
2242 5include\0\0\0\0\0etc\0\0\0\0\0\0\0\0\0\0lector\0\0\0\0\0\0\0nserve\0\0\0\0\0\0\0services\0\0\0\0\0tmp
2243 5lib\0\0\0\0\0\0\0\0\0export\0\0\0\0\0\0\0lib\0\0\0\0\0\0\0\0\0\0oed\0\0\0\0\0\0\0\0\0\0share\0\0\0\0\0\0\0\0ucb
2244 adm\0\0\0\0\0\0\0\0\0\0games\0\0\0\0\0\0\0\0local\0\0\0\0\0\0\0\0old\0\0\0\0\0\0\0\0\0\0skel\0\0\0\0\0\0\0\0\0ucbinclude
2245 bin\0\0\0\0\0\0\0\0\0\0geac\0\0\0\0\0\0\0\0\0lost+found\0\0\0openwin\0\0\0\0\0\0spool\0\0\0\0\0\0\0\0ucblib
2246 boot\0\0\0\0\0\0\0\0\0hosts\0\0\0\0\0\0\0\0macsyma_417\0\0pat\0\0\0\0\0\0\0\0\0\0src\0\0\0\0\0\0\0\0\0\0xpg2bin
2247 demo\0\0\0\0\0\0\0\0\0include\0\0\0\0\0\0man\0\0\0\0\0\0\0\0\0\0princeton\0\0\0\0stand\0\0\0\0\0\0\0\0xpg2include
2248 diag\0\0\0\0\0\0\0\0\0kvm\0\0\0\0\0\0\0\0\0\0mdec\0\0\0\0\0\0\0\0\0pub\0\0\0\0\0\0\0\0\0\0swap\0\0\0\0\0\0\0\0\0xpg2lib
2249 %\0cd\0spool
2250 /usr/spool
2251 %\0cd\0bin
2252 /usr/bin
2253 %\0cd\0func
2254 ~/func
2255 %\0cd\0
2256 %\0cd\0pub
2257 %\0pwd
2258 /u/pfalstad/pub
2259 %\0ls\0-d\0/usr/pub
2260 /usr/pub
2262 \fBPATH\fP and \fBpath\fP both set the search path for commands.
2263 These two variables are equivalent, except that one is a string
2264 and one is an array.  If the user modifies \fBPATH\fP, the shell
2265 changes \fBpath\fP as well, and vice versa.
2267 %\0PATH=/bin:/usr/bin:/tmp:.
2268 %\0echo\0$path
2269 /bin\0/usr/bin\0/tmp\0.
2270 %\0path=(\0/usr/bin\0.\0/usr/local/bin\0/usr/ucb\0)
2271 %\0echo\0$PATH
2272 /usr/bin:.:/usr/local/bin:/usr/ucb
2274 The same is true of \fBCDPATH\fP and \fBcdpath\fP:
2276 %\0echo\0$CDPATH
2277 /usr:/u/pfalstad:/u/pfalstad/zsh
2278 %\0CDPATH=/u/subbarao:/usr/src:/tmp
2279 %\0echo\0$cdpath
2280 /u/subbarao\0/usr/src\0/tmp
2282 In general, predefined parameters with names in all lowercase are
2283 arrays; assignments to them take the form:
2285 \fIname\fR\fC=(\fR\0\fIelem\fR\0...\\0\fC)\fR
2287 Predefined parameters with names in all uppercase are strings.  If
2288 there is both an array and a string version of the same parameter, the
2289 string version is a colon-separated list, like \fBPATH\fP.
2291 \fBHISTFILE\fP is the name of the history file, where the history
2292 is saved when a shell exits.
2294 %\0zsh
2295 phoenix%\0HISTFILE=/tmp/history
2296 phoenix%\0SAVEHIST=20
2297 phoenix%\0echo\0foo
2299 phoenix%\0date
2300 Fri\0May\024\005:39:35\0EDT\01991
2301 phoenix%\0uptime
2302 \0\05:39am\0\0up\04\0days,\020:02,\0\040\0users,\0\0load\0average:\02.30,\02.20,\02.00
2303 phoenix%\0exit
2304 %\0cat\0/tmp/history
2305 HISTFILE=/tmp/history
2306 SAVEHIST=20
2307 echo\0foo
2308 date
2309 uptime
2310 exit
2311 %\0HISTSIZE=3
2312 %\0history
2313 \0\0\028\0\0rm\0/tmp/history
2314 \0\0\029\0\0HISTSIZE=3
2315 \0\0\030\0\0history
2317 If you have several incantations of \fBzsh\fP running at the same
2318 time, like when using the X window system, it might be preferable to
2319 append the history of each shell to a file when a shell exits instead
2320 of overwriting the old contents of the file.  You can get this
2321 behaviour by setting the \fIAPPENDHISTORY\fP option.
2323 In \fBzsh\fP, if you say
2325 %\0>file
2327 the command \fCcat\fP is normally assumed:
2329 %\0>file
2330 foo!\0\0\0\0
2332 %\0cat\0file
2333 foo!
2335 Thus, you can view a file simply by typing:
2337 %\0<file
2338 foo!
2340 However, this is not csh or sh compatible.  To correct this,
2341 change the value of the parameter \fBNULLCMD\fP,
2342 which is \fCcat\fP by default.
2344 %\0NULLCMD=:
2345 %\0>file
2346 %\0ls\0-l\0file
2347 -rw-r--r--\0\01\0pfalstad\0\0\0\0\0\0\0\00\0May\024\005:41\0file
2349 If \fCNULLCMD\fP is unset, the shell reports an error if no
2350 command is specified (like csh).
2352 %\0unset\0NULLCMD
2353 %\0>file
2354 zsh:\0redirection\0with\0no\0command
2356 Actually, \fBREADNULLCMD\fP is used whenever you have a null command
2357 reading input from a single file.  Thus, you can set \fBREADNULLCMD\fP
2358 to \fCmore\fP or \fCless\fP rather than \fCcat\fP.  Also, if you
2359 set \fBNULLCMD\fP to \fC:\fP for sh compatibility, you can still read
2360 files with \fC< file\fP if you leave \fBREADNULLCMD\fP set to \fCmore\fP.
2361 .Sh "Prompting"
2363 The default prompt for \fBzsh\fP is:
2365 phoenix%\0echo\0$PROMPT
2366 %m%#\0
2368 The \fC%m\fP stands for the short form of the current hostname,
2369 and the \fC%#\fP stands for a \fC%\fP or a \fC#\fP, depending on whether
2370 the shell is running as root or not.
2371 \fBzsh\fP supports many other control sequences
2372 in the \fBPROMPT\fP variable.
2374 %\0PROMPT='%/>\0'
2375 /u/pfalstad/etc/TeX/zsh>
2377 %\0PROMPT='%~>\0'\0\0\0
2378 ~/etc/TeX/zsh>\0
2380 %\0PROMPT='%h\0%~>\0'
2381 6\0~/etc/TeX/zsh>\0
2383 \fC%h\fP\0represents\0the\0number\0of\0current\0history\0event.
2385 %\0PROMPT='%h\0%~\0%M>\0'
2386 10\0~/etc/TeX/zsh\0apple-gunkies.gnu.ai.mit.edu>\0
2388 %\0PROMPT='%h\0%~\0%m>\0'
2389 11\0~/etc/TeX/zsh\0apple-gunkies>\0
2391 %\0PROMPT='%h\0%t>\0'
2392 12\06:11am>\0
2394 %\0PROMPT='%n\0%w\0tty%l>'
2395 pfalstad\0Fri\024\0ttyp0>
2397 \fBPROMPT2\fP is used in multiline commands, like for-loops.  The
2398 \fC%_\fP escape sequence was made especially for this prompt.  It is
2399 replaced by the kind of command that is being entered.
2401 %\0PROMPT2='%_>\0'
2402 %\0for\0i\0in\0foo\0bar
2403 for>
2405 %\0echo\0'hi
2406 quote>
2408 Also available is the \fBRPROMPT\fP parameter.
2409 If this is set, the shell puts a prompt on the \fIright\fP side
2410 of the screen.
2412 %\0RPROMPT='%t'
2413 %\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\06:14am
2415 %\0RPROMPT='%~'
2416 %\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0~/etc/TeX/zsh
2418 %\0PROMPT='%l\0%T\0%m[%h]\0'\0RPROMPT='\0%~'
2419 p0\06:15\0phoenix[5]\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0~/etc/TeX/zsh
2421 These special escape sequences can also be used with the
2422 \fC-P\fP option to \fCprint\fP:
2424 %\0print\0-P\0%h\0tty%l
2425 15\0ttyp1
2428 The \fBPOSTEDIT\fP parameter is printed whenever the editor exits.
2429 This can be useful for termcap tricks.  To highlight the prompt
2430 and command line while leaving command output unhighlighted, try this:
2432 %\0POSTEDIT=`echotc\0se`
2433 %\0PROMPT='%S%%\0'
2435 .Sh "Login/logout watching"
2437 You can specify login or logout events to monitor
2438 by setting the \fBwatch\fP variable.
2439 Normally, this is done by specifying a list of usernames.
2441 %\0watch=(\0pfalstad\0subbarao\0sukthnkr\0egsirer\0)
2443 The \fClog\fP command reports all people logged in
2444 that you are watching for.
2446 %\0log
2447 pfalstad\0has\0logged\0on\0p0\0from\0mickey.
2448 pfalstad\0has\0logged\0on\0p5\0from\0mickey.
2449 %\0\fR...\fC
2450 subbarao\0has\0logged\0on\0p8\0from\0phoenix.
2451 %\0\fR...\fC
2452 subbarao\0has\0logged\0off\0p8\0from\0phoenix.
2453 %\0\fR...\fC
2454 sukthnkr\0has\0logged\0on\0p8\0from\0dew.
2455 %\0\fR...\fC
2456 sukthnkr\0has\0logged\0off\0p8\0from\0dew.
2458 If you specify hostnames with an \fC@\fP prepended,
2459 the shell will watch for all users logging in from
2460 the specified host.
2462 %\0watch=(\0@mickey\0@phoenix\0)
2463 %\0log
2464 djthongs\0has\0logged\0on\0q2\0from\0phoenix.
2465 pfalstad\0has\0logged\0on\0p0\0from\0mickey.
2466 pfalstad\0has\0logged\0on\0p5\0from\0mickey.
2468 If you give a tty name with a \fC%\fP prepended, the shell
2469 will watch for all users logging in on that tty.
2471 %\0watch=(\0%ttyp0\0%console\0)
2472 %\0log
2473 root\0has\0logged\0on\0console\0from\0.
2474 pfalstad\0has\0logged\0on\0p0\0from\0mickey.
2476 The format of the reports may also be changed.
2478 %\0watch=(\0pfalstad\0gettes\0eps\0djthongs\0jcorr\0bdavis\0)
2479 %\0log
2480 jcorr\0has\0logged\0on\0tf\0from\0128.112.176.3:0.
2481 jcorr\0has\0logged\0on\0r0\0from\0128.112.176.3:0.
2482 gettes\0has\0logged\0on\0p4\0from\0yo:0.0.
2483 djthongs\0has\0logged\0on\0pe\0from\0grumpy:0.0.
2484 djthongs\0has\0logged\0on\0q2\0from\0phoenix.
2485 bdavis\0has\0logged\0on\0qd\0from\0BRUNO.
2486 eps\0has\0logged\0on\0p3\0from\0csx30:0.0.
2487 pfalstad\0has\0logged\0on\0p0\0from\0mickey.
2488 pfalstad\0has\0logged\0on\0p5\0from\0mickey.
2489 %\0WATCHFMT='%n\0on\0tty%l\0from\0%M'
2490 %\0log
2491 jcorr\0on\0ttytf\0from\0128.112.176.3:0.
2492 jcorr\0on\0ttyr0\0from\0128.112.176.3:0.
2493 gettes\0on\0ttyp4\0from\0yo:0.0
2494 djthongs\0on\0ttype\0from\0grumpy:0.0
2495 djthongs\0on\0ttyq2\0from\0phoenix.Princeto
2496 bdavis\0on\0ttyqd\0from\0BRUNO.pppl.gov
2497 eps\0on\0ttyp3\0from\0csx30:0.0
2498 pfalstad\0on\0ttyp0\0from\0mickey.Princeton
2499 pfalstad\0on\0ttyp5\0from\0mickey.Princeton
2500 %\0WATCHFMT='%n\0fm\0%m'
2501 %\0log
2502 jcorr\0fm\0128.112.176.3:0
2503 jcorr\0fm\0128.112.176.3:0
2504 gettes\0fm\0yo:0.0
2505 djthongs\0fm\0grumpy:0.0
2506 djthongs\0fm\0phoenix
2507 bdavis\0fm\0BRUNO
2508 eps\0fm\0csx30:0.0
2509 pfalstad\0fm\0mickey
2510 pfalstad\0fm\0mickey
2511 %\0WATCHFMT='%n\0%a\0at\0%t\0%w.'
2512 %\0log
2513 jcorr\0logged\0on\0at\03:15pm\0Mon\020.
2514 jcorr\0logged\0on\0at\03:16pm\0Wed\022.
2515 gettes\0logged\0on\0at\06:54pm\0Wed\022.
2516 djthongs\0logged\0on\0at\07:19am\0Thu\023.
2517 djthongs\0logged\0on\0at\07:20am\0Thu\023.
2518 bdavis\0logged\0on\0at\012:40pm\0Thu\023.
2519 eps\0logged\0on\0at\04:19pm\0Thu\023.
2520 pfalstad\0logged\0on\0at\03:39am\0Fri\024.
2521 pfalstad\0logged\0on\0at\03:42am\0Fri\024.
2523 If you have a \fC.friends\fP file in your home directory,
2524 a convenient way to make \fBzsh\fP watch for all your friends
2525 is to do this:
2527 %\0watch=(\0$(<\0~/.friends)\0)
2528 %\0echo\0$watch
2529 subbarao\0maruchck\0root\0sukthnkr\0\fR...
2531 If watch is set to \fCall\fP, then all users logging in or out
2532 will be reported.
2533 .Sh "Options"
2535 Some options have already been mentioned; here are a few more:
2537 Using the \fIAUTOCD\fP option, you can simply type the name
2538 of a directory, and it will become the current directory.
2540 %\0cd\0/
2541 %\0setopt\0autocd
2542 %\0bin
2543 %\0pwd
2544 /bin
2545 %\0../etc
2546 %\0pwd
2547 /etc
2549 With \fICDABLEVARS\fP, if the argument to \fCcd\fP is the name of a
2550 parameter whose value is a valid directory, it will become
2551 the current directory.
2553 %\0setopt\0cdablevars
2554 %\0foo=/tmp
2555 %\0cd\0foo
2556 /tmp
2558 \fICORRECT\fP turns on spelling correction for commands,
2559 and the \fICORRECTALL\fP option turns on spelling correction
2560 for all arguments.
2562 %\0setopt\0correct
2563 %\0sl
2564 zsh:\0correct\0`sl'\0to\0`ls'\0[nyae]?\0y
2565 %\0setopt\0correctall
2566 %\0ls\0x.v11r4
2567 zsh:\0correct\0`x.v11r4'\0to\0`X.V11R4'\0[nyae]?\0n
2568 /usr/princton/src/x.v11r4\0not\0found
2569 %\0ls\0/etc/paswd
2570 zsh:\0correct\0to\0`/etc/paswd'\0to\0`/etc/passwd'\0[nyae]?\0y
2571 /etc/passwd
2573 If you press \fCy\fP
2574 when the shell asks you if you want to correct a word, it will
2575 be corrected.  If you press \fCn\fP, it will be left alone.
2576 Pressing \fCa\fP aborts the command, and pressing \fCe\fP brings the line
2577 up for editing again, in case you agree the word is spelled wrong
2578 but you don't like the correction.
2580 Normally, a quoted expression may contain a newline:
2582 %\0echo\0'
2583 >\0foo
2584 >\0'
2590 With \fICSHJUNKIEQUOTES\fP set, this is illegal, as it is
2591 in csh.
2593 %\0setopt\0cshjunkiequotes
2594 %\0ls\0'foo
2595 zsh:\0unmatched\0'
2597 \fIGLOBDOTS\fP lets files beginning with a \fC.\fP be matched without
2598 explicitly specifying the dot.
2600 %\0ls\0-d\0*x*
2601 Mailboxes
2602 %\0setopt\0globdots
2603 %\0ls\0-d\0*x*
2604 \&.exrc\0\0\0\0\0\0\0\0\0.pnewsexpert\0\0.xserverrc
2605 \&.mushexpert\0\0\0.xinitrc\0\0\0\0\0\0Mailboxes
2607 \fIHISTIGNOREDUPS\fP prevents the current line from being
2608 saved in the history if it is the same as the previous one;
2609 \fIHISTIGNORESPACE\fP prevents the current line from being
2610 saved if it begins with a space.
2612 %\0PROMPT='%h>\0'
2613 39>\0setopt\0histignoredups
2614 40>\0echo\0foo
2616 41>\0echo\0foo
2618 41>\0echo\0foo
2620 41>\0echo\0bar
2622 42>\0setopt\0histignorespace
2623 43>\0\0echo\0foo
2625 43>\0\0echo\0fubar
2626 fubar
2627 43>\0\0echo\0fubar
2628 fubar
2630 \fIIGNOREBRACES\fP turns off csh-style brace expansion.
2632 %\0echo\0x{y{z,a},{b,c}d}e
2633 xyze\0xyae\0xbde\0xcde
2634 %\0setopt\0ignorebraces
2635 %\0echo\0x{y{z,a},{b,c}d}e
2636 x{y{z,a},{b,c}d}e
2638 \fIIGNOREEOF\fP forces the user to type \fCexit\fP or \fClogout\fP,
2639 instead of just pressing \fI^D\fP.
2641 %\0setopt\0ignoreeof
2642 %\0^D
2643 zsh:\0use\0'exit'\0to\0exit.
2645 \fIINTERACTIVECOMMENTS\fP turns on interactive comments;
2646 comments begin with a \fC#\fP.
2648 %\0setopt\0interactivecomments
2649 %\0date\0#\0this\0is\0a\0comment
2650 Fri\0May\024\006:54:14\0EDT\01991
2652 \fINOBEEP\fP makes sure the shell never beeps.
2654 \fINOCLOBBER\fP prevents you from accidentally
2655 overwriting an existing file.
2657 %\0setopt\0noclobber
2658 %\0cat\0/dev/null\0>~/.zshrc
2659 zsh:\0file\0exists:\0/u/pfalstad/.zshrc
2661 If you really do want to clobber a file, you can use the
2662 \fC>!\fP operator.
2663 To make things easier in this case, the \fC>\fP is stored in
2664 the history list as a \fC>!\fP:
2666 %\0cat\0/dev/null\0>!\0~/.zshrc
2667 %\0cat\0/etc/motd\0>\0~/.zshrc
2668 zsh:\0file\0exists:\0/u/pfalstad/.zshrc
2669 %\0!!
2670 cat\0/etc/motd\0>!\0~/.zshrc
2671 %\0\fR...
2673 \fIRCQUOTES\fP lets you use a more elegant method for including
2674 single quotes in a singly quoted string:
2676 %\0echo\0'"don'\e''t\0do\0that."'
2677 "don't\0do\0that."
2678 %\0echo\0'"don''t\0do\0that."'
2679 "dont\0do\0that."
2680 %\0setopt\0rcquotes
2681 %\0echo\0'"don''t\0do\0that."'
2682 "don't\0do\0that."
2684 Finally,
2685 \fISUNKEYBOARDHACK\fP wins the award for the strangest option.
2686 If a line ends with \fC`\fP, and there are an odd number of them
2687 on the line, the shell will ignore the trailing \fC`\fP.  This
2688 is provided for keyboards whose RETURN key is too small,
2689 and too close to the \fC`\fP key.
2691 %\0setopt\0sunkeyboardhack
2692 %\0date`
2693 Fri\0May\024\006:55:38\0EDT\01991
2695 .Sh "Closing Comments"
2697 I (Bas de Bakker) would be happy to receive mail if anyone has any
2698 tricks or ideas to add to this document, or if there are some points
2699 that could be made clearer or covered more thoroughly.  Please notify
2700 me of any errors in this document.
2701 .if o \{\
2703 .sv 1i
2705 .pn 1