This file is indexed.

/usr/share/doc/zsh-common/html/Shell-Grammar.html is in zsh-doc 5.0.2-3ubuntu6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on December 21, 2012 by texi2html 1.82
texi2html was written by: 
            Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>zsh: 6. Shell Grammar</title>

<meta name="description" content="zsh: 6. Shell Grammar">
<meta name="keywords" content="zsh: 6. Shell Grammar">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Shell-Grammar"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Files.html#Files-2" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Simple-Commands-_0026-Pipelines" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="Files.html#Files" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Shell-Grammar-1"></a>
<h1 class="chapter">6. Shell Grammar</h1>
<a name="index-shell-grammar"></a>
<a name="index-grammar_002c-shell"></a>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Simple-Commands-_0026-Pipelines">6.1 Simple Commands &amp; Pipelines</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Precommand-Modifiers">6.2 Precommand Modifiers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Complex-Commands">6.3 Complex Commands</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Alternate-Forms-For-Complex-Commands">6.4 Alternate Forms For Complex Commands</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Reserved-Words">6.5 Reserved Words</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Errors">6.6 Errors</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Comments">6.7 Comments</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Aliasing">6.8 Aliasing</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Quoting">6.9 Quoting</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr size="6">
<a name="Simple-Commands-_0026-Pipelines"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Shell-Grammar" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Precommand-Modifiers" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Simple-Commands-_0026-Pipelines-1"></a>
<h2 class="section">6.1 Simple Commands &amp; Pipelines</h2>
<a name="index-simple-commands"></a>
<a name="index-commands_002c-simple"></a>
<p>A <em>simple command</em> is a sequence of optional parameter
assignments followed by blank-separated words,
with optional redirections interspersed.
The first word is the command to be executed, and the remaining
words, if any, are arguments to the command.
If a command name is given, the parameter assignments modify
the environment of the command when it is executed.
The value of a simple command is its exit status,
or 128 plus the signal number if terminated by a signal.
For example,
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">echo foo
</pre></td></tr></table>

<p>is a simple command with arguments.
</p>
<a name="index-pipeline"></a>
<p>A <em>pipeline</em> is either a simple command, or a sequence of two or more
simple commands where each command is separated from the next by &lsquo;<tt>|</tt>&rsquo;
or &lsquo;<tt>|&amp;</tt>&rsquo;.  Where commands are separated by &lsquo;<tt>|</tt>&rsquo;, the standard
output of the first command is connected to the
standard input of the next.  &lsquo;<tt>|&amp;</tt>&rsquo; is shorthand for &lsquo;<tt>2&gt;&amp;1 |</tt>&rsquo;, which
connects both the standard output and the standard error of the
command to the standard input of the next.  The value of a pipeline
is the value of the last command, unless the pipeline is preceded by
&lsquo;<tt>!</tt>&rsquo; in which case the value is the logical inverse of the value of the
last command.
For example,
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">echo foo | sed 's/foo/bar/'
</pre></td></tr></table>

<p>is a pipeline, where the output (&lsquo;<tt>foo</tt>&rsquo; plus a newline) of the first
command will be passed to the input of the second.
</p>
<a name="index-coproc"></a>
<a name="index-coprocess"></a>
<p>If a pipeline is preceded by &lsquo;<tt>coproc</tt>&rsquo;, it is executed as a coprocess;
a two-way pipe is established between it and the parent shell.  The
shell can read from or write to the coprocess by means of the &lsquo;<tt>&gt;&amp;p</tt>&rsquo;
and &lsquo;<tt>&lt;&amp;p</tt>&rsquo; redirection operators or with &lsquo;<tt>print -p</tt>&rsquo; and &lsquo;<tt>read -p</tt>&rsquo;.
A pipeline cannot be preceded by both &lsquo;<tt>coproc</tt>&rsquo; and &lsquo;<tt>!</tt>&rsquo;.
If job control is active, the coprocess can be treated in other than input
and output as an ordinary background job.
</p>
<a name="index-sublist"></a>
<p>A <em>sublist</em> is either a single pipeline, or a sequence of two or more
pipelines separated by &lsquo;<tt>&amp;&amp;</tt>&rsquo; or &lsquo;<tt>||</tt>&rsquo;.  If two pipelines are separated
by &lsquo;<tt>&amp;&amp;</tt>&rsquo;, the second pipeline is executed only if the first succeeds
(returns a zero status).  If two pipelines are separated by &lsquo;<tt>||</tt>&rsquo;, the
second is executed only if the first fails (returns a nonzero status).
Both operators have equal precedence and are left associative.
The value of the sublist is the value of the last pipeline executed.
For example,
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">dmesg | grep panic &amp;&amp; print yes
</pre></td></tr></table>

<p>is a sublist consisting of two pipelines, the second just a simple command
which will be executed if and only if the <tt>grep</tt> command returns a zero
status.  If it does not, the value of the sublist is that return status, else
it is the status returned by the <tt>print</tt> (almost certainly zero).
</p>
<a name="index-list"></a>
<p>A <em>list</em> is a sequence of zero or more sublists, in which each sublist
is terminated by &lsquo;<tt>;</tt>&rsquo;, &lsquo;<tt>&amp;</tt>&rsquo;, &lsquo;<tt>&amp;|</tt>&rsquo;, &lsquo;<tt>&amp;!</tt>&rsquo;, or a newline.
This terminator
may optionally be omitted from the last sublist in the list when the
list appears as a complex command inside &lsquo;<tt>(</tt>...<tt>)</tt>&rsquo;
or &lsquo;<tt>{</tt>...<tt>}</tt>&rsquo;.  When a
sublist is terminated by &lsquo;<tt>;</tt>&rsquo; or newline, the shell waits for it to
finish before executing the next sublist.  If a sublist is terminated
by a &lsquo;<tt>&amp;</tt>&rsquo;, &lsquo;<tt>&amp;|</tt>&rsquo;, or &lsquo;<tt>&amp;!</tt>&rsquo;,
the shell executes the last pipeline in it in the background, and
does not wait for it to finish (note the difference from other shells
which execute the whole sublist in the background).
A backgrounded pipeline returns a status of zero.
</p>
<p>More generally, a list can be seen as a set of any shell commands
whatsoever, including the complex commands below; this is implied wherever
the word &lsquo;list&rsquo; appears in later descriptions.  For example, the commands
in a shell function form a special sort of list.
</p><hr size="6">
<a name="Precommand-Modifiers"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Simple-Commands-_0026-Pipelines" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Complex-Commands" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Precommand-Modifiers-1"></a>
<h2 class="section">6.2 Precommand Modifiers</h2>
<a name="index-precommand-modifiers"></a>
<a name="index-modifiers_002c-precommand"></a>
<p>A simple command may be preceded by a <em>precommand modifier</em>,
which will alter how the command is interpreted.  These modifiers are
shell builtin commands with the exception of <tt>nocorrect</tt> which is
a reserved word.
</p>
<dl compact="compact">
<dd><a name="index-_002d"></a>
</dd>
<dt> <tt>-</tt></dt>
<dd><p>The command is executed with a &lsquo;<tt>-</tt>&rsquo; prepended to its
<tt>argv[0]</tt> string.
</p>
<a name="index-builtin"></a>
</dd>
<dt> <tt>builtin</tt></dt>
<dd><p>The command word is taken to be the name of a builtin command,
rather than a shell function or external command.
</p>
<a name="index-command"></a>
</dd>
<dt> <tt>command</tt> [ <tt>-pvV</tt> ]</dt>
<dd><p>The command word is taken to be the name of an external command,
rather than a shell function or builtin.   If the <tt>POSIX_BUILTINS</tt> option
is set, builtins will also be executed but certain special properties
of them are suppressed. The <tt>-p</tt> flag causes a default path to be
searched instead of that in <tt>$path</tt>. With the <tt>-v</tt> flag, <tt>command</tt>
is similar to <tt>whence</tt> and with <tt>-V</tt>, it is equivalent to <tt>whence
-v</tt>.
</p>
<a name="index-exec"></a>
</dd>
<dt> <tt>exec</tt> [ <tt>-cl</tt> ] [ <tt>-a</tt> <var>argv0</var> ]</dt>
<dd><p>The following command together with any arguments is run in place
of the current process, rather than as a sub-process.  The shell does not
fork and is replaced.  The shell does not invoke <tt>TRAPEXIT</tt>, nor does it
source <tt>zlogout</tt> files.
The options are provided for compatibility with other shells.
</p>
<p>The <tt>-c</tt> option clears the environment.
</p>
<p>The <tt>-l</tt> option is equivalent to the <tt>-</tt> precommand modifier, to
treat the replacement command as a login shell; the command is executed
with a <tt>-</tt> prepended to its <tt>argv[0]</tt> string.  This flag has no effect
if used together with the <tt>-a</tt> option.
</p>
<p>The <tt>-a</tt> option is used to specify explicitly the <tt>argv[0]</tt> string
(the name of the command as seen by the process itself) to be used by the
replacement command and is directly equivalent to setting a value
for the <tt>ARGV0</tt> environment variable.
</p>
<a name="index-nocorrect"></a>
</dd>
<dt> <tt>nocorrect</tt></dt>
<dd><p>Spelling correction is not done on any of the words.  This must appear
before any other precommand modifier, as it is interpreted immediately,
before any parsing is done.  It has no effect in non-interactive shells.
</p>
<a name="index-noglob"></a>
</dd>
<dt> <tt>noglob</tt></dt>
<dd><p>Filename generation (globbing) is not performed on any of
the words.
</p>
</dd>
</dl>
<hr size="6">
<a name="Complex-Commands"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Precommand-Modifiers" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Alternate-Forms-For-Complex-Commands" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Complex-Commands-1"></a>
<h2 class="section">6.3 Complex Commands</h2>
<a name="index-complex-commands"></a>
<a name="index-commands_002c-complex"></a>
<p>A <em>complex command</em> in zsh is one of the following:
</p>
<dl compact="compact">
<dd><a name="index-if"></a>
<a name="index-if-construct"></a>
</dd>
<dt> <tt>if</tt> <var>list</var> <tt>then</tt> <var>list</var> [ <tt>elif</tt> <var>list</var> <tt>then</tt> <var>list</var> ] ... [ <tt>else</tt> <var>list</var> ] <tt>fi</tt></dt>
<dd><p>The <tt>if</tt> <var>list</var> is executed, and if it returns a zero exit status,
the <tt>then</tt> <var>list</var> is executed.
Otherwise, the <tt>elif</tt> <var>list</var> is executed and if its status is zero,
the <tt>then</tt> <var>list</var> is executed.
If each <tt>elif</tt> <var>list</var> returns nonzero status, the <tt>else</tt> <var>list</var>
is executed.
</p>
<a name="index-for"></a>
<a name="index-for-loops"></a>
<a name="index-loops_002c-for"></a>
</dd>
<dt> <tt>for</tt> <var>name</var> ... [ <tt>in</tt> <var>word</var> ... ] <var>term</var> <tt>do</tt> <var>list</var> <tt>done</tt></dt>
<dd><p>where <var>term</var> is at least one newline or <tt>;</tt>.
Expand the list of <var>word</var>s, and set the parameter
<var>name</var> to each of them in turn, executing
<var>list</var> each time.  If the <tt>in</tt> <var>word</var> is omitted,
use the positional parameters instead of the <var>word</var>s.
</p>
<p>More than one parameter <var>name</var> can appear before the list of
<var>word</var>s.  If <var>N</var> <var>name</var>s are given, then on each execution of the
loop the next <tt>N</tt> <var>word</var>s are assigned to the corresponding
parameters.  If there are more <var>name</var>s than remaining <var>word</var>s, the
remaining parameters are each set to the empty string.  Execution of the
loop ends when there is no remaining <var>word</var> to assign to the first
<var>name</var>.  It is only possible for <tt>in</tt> to appear as the first <var>name</var>
in the list, else it will be treated as marking the end of the list.
</p>
</dd>
<dt> <tt>for ((</tt> [<var>expr1</var>] <tt>;</tt> [<var>expr2</var>] <tt>;</tt> [<var>expr3</var>] <tt>)) do</tt> <var>list</var> <tt>done</tt></dt>
<dd><p>The arithmetic expression <var>expr1</var> is evaluated first (see
<a href="Arithmetic-Evaluation.html#Arithmetic-Evaluation">Arithmetic Evaluation</a>).  The arithmetic expression
<var>expr2</var> is repeatedly evaluated until it evaluates to zero and
when non-zero, <var>list</var> is executed and the arithmetic expression
<var>expr3</var> evaluated.  If any expression is omitted, then it behaves
as if it evaluated to 1.
</p>
<a name="index-while"></a>
<a name="index-while-loops"></a>
<a name="index-loops_002c-while"></a>
</dd>
<dt> <tt>while</tt> <var>list</var> <tt>do</tt> <var>list</var> <tt>done</tt></dt>
<dd><p>Execute the <tt>do</tt> <var>list</var> as long as the <tt>while</tt> <var>list</var>
returns a zero exit status.
</p>
<a name="index-until"></a>
<a name="index-until-loops"></a>
<a name="index-loops_002c-until"></a>
</dd>
<dt> <tt>until</tt> <var>list</var> <tt>do</tt> <var>list</var> <tt>done</tt></dt>
<dd><p>Execute the <tt>do</tt> <var>list</var> as long as <tt>until</tt> <var>list</var>
returns a nonzero exit status.
</p>
<a name="index-repeat"></a>
<a name="index-repeat-loops"></a>
<a name="index-loops_002c-repeat"></a>
</dd>
<dt> <tt>repeat</tt> <var>word</var> <tt>do</tt> <var>list</var> <tt>done</tt></dt>
<dd><p><var>word</var> is expanded and treated as an arithmetic expression,
which must evaluate to a number <var>n</var>.
<var>list</var> is then executed <var>n</var> times.
</p>
<p>The <tt>repeat</tt> syntax is disabled by default when the
shell starts in a mode emulating another shell.  It can be enabled
with the command &lsquo;<tt>enable -r repeat</tt>&rsquo;
</p>
<a name="index-case"></a>
<a name="index-case-selection"></a>
<a name="index-selection_002c-case"></a>
</dd>
<dt> <tt>case</tt> <var>word</var> <tt>in</tt> [ [<tt>(</tt>] <var>pattern</var> [ <tt>|</tt> <var>pattern</var> ] ... <tt>)</tt> <var>list</var> (<tt>;;</tt>|<tt>;&amp;</tt>|<tt>;|</tt>) ] ... <tt>esac</tt></dt>
<dd><p>Execute the <var>list</var> associated with the first <var>pattern</var>
that matches <var>word</var>, if any.  The form of the patterns
is the same as that used for filename generation.  See
<a href="Expansion.html#Filename-Generation">Filename Generation</a>.
</p>
<p>If the <var>list</var> that is executed is terminated with <tt>;&amp;</tt> rather than
<tt>;;</tt>, the following list is also executed.  The rule for
the terminator of the following list <tt>;;</tt>, <tt>;&amp;</tt> or <tt>;|</tt> is
applied unless the <tt>esac</tt> is reached.
</p>
<p>If the <var>list</var> that is executed is terminated with <tt>;|</tt> the
shell continues to scan the <var>pattern</var>s looking for the next match,
executing the corresponding <var>list</var>, and applying the rule for
the corresponding terminator <tt>;;</tt>, <tt>;&amp;</tt> or <tt>;|</tt>.
Note that <var>word</var> is not re-expanded; all applicable <var>pattern</var>s
are tested with the same <var>word</var>.
</p>
<a name="index-select"></a>
<a name="index-user-selection"></a>
<a name="index-selection_002c-user"></a>
</dd>
<dt> <tt>select</tt> <var>name</var> [ <tt>in</tt> <var>word</var> ... <var>term</var> ] <tt>do</tt> <var>list</var> <tt>done</tt></dt>
<dd><p>where <var>term</var> is one or more newline or <tt>;</tt> to terminate the <var>word</var>s.
<a name="index-REPLY_002c-use-of"></a>
Print the set of <var>word</var>s, each preceded by a number.
If the <tt>in</tt> <var>word</var> is omitted, use the positional parameters.
The <tt>PROMPT3</tt> prompt is printed and a line is read from the line editor
if the shell is interactive and that is active, or else standard input.
If this line consists of the
number of one of the listed <var>word</var>s, then the parameter <var>name</var>
is set to the <var>word</var> corresponding to this number.
If this line is empty, the selection list is printed again.
Otherwise, the value of the parameter <var>name</var> is set to null.
The contents of the line read from standard input is saved
in the parameter <tt>REPLY</tt>.  <var>list</var> is executed
for each selection until a break or end-of-file is encountered.
</p>
<a name="index-subshell"></a>
</dd>
<dt> <tt>(</tt> <var>list</var> <tt>)</tt></dt>
<dd><p>Execute <var>list</var> in a subshell.  Traps set by the <tt>trap</tt> builtin
are reset to their default values while executing <var>list</var>.
</p>
</dd>
<dt> <tt>{</tt> <var>list</var> <tt>}</tt></dt>
<dd><p>Execute <var>list</var>.
</p>
<a name="index-always"></a>
<a name="index-always-blocks"></a>
<a name="index-try-blocks"></a>
</dd>
<dt> <tt>{</tt> <var>try-list</var> <tt>} always {</tt> <var>always-list</var> <tt>}</tt></dt>
<dd><p>First execute <var>try-list</var>.  Regardless of errors, or <tt>break</tt>,
<tt>continue</tt>, or <tt>return</tt> commands encountered within <var>try-list</var>,
execute <var>always-list</var>.  Execution then continues from the
result of the execution of <var>try-list</var>; in other words, any error,
or <tt>break</tt>, <tt>continue</tt>, or <tt>return</tt> command is treated in the
normal way, as if <var>always-list</var> were not present.  The two
chunks of code are referred to as the &lsquo;try block&rsquo; and the &lsquo;always block&rsquo;.
</p>
<p>Optional newlines or semicolons may appear after the <tt>always</tt>;
note, however, that they may <em>not</em> appear between the preceding
closing brace and the <tt>always</tt>.
</p>
<p>An &lsquo;error&rsquo; in this context is a condition such as a syntax error which
causes the shell to abort execution of the current function, script, or
list.  Syntax errors encountered while the shell is parsing the
code do not cause the <var>always-list</var> to be executed.  For example,
an erroneously constructed <tt>if</tt> block in <tt>try-list</tt> would cause the
shell to abort during parsing, so that <tt>always-list</tt> would not be
executed, while an erroneous substitution such as <tt>${*foo*}</tt> would
cause a run-time error, after which <tt>always-list</tt> would be executed.
</p>
<p>An error condition can be tested and reset with the special integer
variable <tt>TRY_BLOCK_ERROR</tt>.  Outside an <tt>always-list</tt> the value is
irrelevant, but it is initialised to <tt>-1</tt>.  Inside <tt>always-list</tt>, the
value is 1 if an error occurred in the <tt>try-list</tt>, else 0.  If
<tt>TRY_BLOCK_ERROR</tt> is set to 0 during the <tt>always-list</tt>, the error
condition caused by the <tt>try-list</tt> is reset, and shell execution
continues normally after the end of <tt>always-list</tt>.  Altering the value
during the <tt>try-list</tt> is not useful (unless this forms part of an
enclosing <tt>always</tt> block).
</p>
<p>Regardless of <tt>TRY_BLOCK_ERROR</tt>, after the end of <tt>always-list</tt> the
normal shell status <tt>$?</tt> is the value returned from <tt>always-list</tt>.
This will be non-zero if there was an error, even if <tt>TRY_BLOCK_ERROR</tt>
was set to zero.
</p>
<p>The following executes the given code, ignoring any errors it causes.
This is an alternative to the usual convention of protecting code by
executing it in a subshell.
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">{
    # code which may cause an error
  } always {
    # This code is executed regardless of the error.
    (( TRY_BLOCK_ERROR = 0 ))
}
# The error condition has been reset.
</pre></td></tr></table>

<p>An <tt>exit</tt> command (or a <tt>return</tt> command executed at the outermost
function level of a script) encountered in <tt>try-list</tt> does <em>not</em> cause
the execution of <var>always-list</var>.  Instead, the shell exits immediately
after any <tt>EXIT</tt> trap has been executed.
</p>
<a name="index-function"></a>
</dd>
<dt> <tt>function</tt> <var>word</var> ... [ <tt>()</tt> ] [ <var>term</var> ] <tt>{</tt> <var>list</var> <tt>}</tt></dt>
<dt> <var>word</var> ... <tt>()</tt> [ <var>term</var> ] <tt>{</tt> <var>list</var> <tt>}</tt></dt>
<dt> <var>word</var> ... <tt>()</tt> [ <var>term</var> ] <var>command</var></dt>
<dd><p>where <var>term</var> is one or more newline or <tt>;</tt>.
Define a function which is referenced by any one of <var>word</var>.
Normally, only one <var>word</var> is provided; multiple <var>word</var>s
are usually only useful for setting traps.
The body of the function is the <var>list</var> between
the <tt>{</tt> and <tt>}</tt>.  See <a href="Functions.html#Functions">Functions</a>.
</p>
<p>If the option <tt>SH_GLOB</tt> is set for compatibility with other shells, then
whitespace may appear between between the left and right parentheses when
there is a single <var>word</var>;  otherwise, the parentheses will be treated as
forming a globbing pattern in that case.
</p>
<a name="index-timing"></a>
<a name="index-time"></a>
</dd>
<dt> <tt>time</tt> [ <var>pipeline</var> ]</dt>
<dd><p>The <var>pipeline</var> is executed, and timing statistics are
reported on the standard error in the form specified
by the <tt>TIMEFMT</tt> parameter.
If <var>pipeline</var> is omitted, print statistics about the
shell process and its children.
</p>
<a name="index-conditional-expression"></a>
<a name="index-_005b_005b"></a>
</dd>
<dt> <tt>[[</tt> <var>exp</var> <tt>]]</tt></dt>
<dd><p>Evaluates the conditional expression <var>exp</var>
and return a zero exit status if it is true.
See <a href="Conditional-Expressions.html#Conditional-Expressions">Conditional Expressions</a>
for a description of <var>exp</var>.
</p>
</dd>
</dl>
<hr size="6">
<a name="Alternate-Forms-For-Complex-Commands"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Complex-Commands" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Reserved-Words" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Alternate-Forms-For-Complex-Commands-1"></a>
<h2 class="section">6.4 Alternate Forms For Complex Commands</h2>
<a name="index-alternate-forms-for-complex-commands"></a>
<a name="index-commands_002c-alternate-forms-for-complex"></a>
<p>Many of zsh&rsquo;s complex commands have alternate forms.  These are
non-standard and are likely not to be obvious even to seasoned shell
programmers; they should not be used anywhere that portability of shell
code is a concern.
</p>
<p>The short versions below only work if <var>sublist</var> is of the form &lsquo;<tt>{</tt>
<var>list</var> <tt>}</tt>&rsquo; or if the <tt>SHORT_LOOPS</tt> option is set.  For the <tt>if</tt>,
<tt>while</tt> and <tt>until</tt> commands, in both these cases the test part of the
loop must also be suitably delimited, such as by &lsquo;<tt>[[ ... ]]</tt>&rsquo; or &lsquo;<tt>((
... ))</tt>&rsquo;, else the end of the test will not be recognized.  For the
<tt>for</tt>, <tt>repeat</tt>, <tt>case</tt> and <tt>select</tt> commands no such special form
for the arguments is necessary, but the other condition (the special form
of <var>sublist</var> or use of the <tt>SHORT_LOOPS</tt> option) still applies.
</p>
<dl compact="compact">
<dt> <tt>if</tt> <var>list</var> <tt>{</tt> <var>list</var> <tt>}</tt> [ <tt>elif</tt> <var>list</var> <tt>{</tt> <var>list</var> <tt>}</tt> ] ... [ <tt>else {</tt> <var>list</var> <tt>}</tt> ]</dt>
<dd><p>An alternate form of <tt>if</tt>.  The rules mean that
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">if [[ -o ignorebraces ]] {
  print yes
}
</pre></td></tr></table>

<p>works, but
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">if true {  # Does not work!
  print yes
}

</pre></td></tr></table>

<p>does <em>not</em>, since the test is not suitably delimited.
</p>
</dd>
<dt> <tt>if</tt> <var>list</var> <var>sublist</var></dt>
<dd><p>A short form of the alternate &lsquo;if&rsquo;.  The same limitations on the form of
<var>list</var> apply as for the previous form.
</p>
</dd>
<dt> <tt>for</tt> <var>name</var> ... <tt>(</tt> <var>word</var> ... <tt>)</tt> <var>sublist</var></dt>
<dd><p>A short form of <tt>for</tt>.
</p>
</dd>
<dt> <tt>for</tt> <var>name</var> ... [ <tt>in</tt> <var>word</var> ... ] <var>term</var> <var>sublist</var></dt>
<dd><p>where <var>term</var> is at least one newline or <tt>;</tt>.
Another short form of <tt>for</tt>.
</p>
</dd>
<dt> <tt>for ((</tt> [<var>expr1</var>] <tt>;</tt> [<var>expr2</var>] <tt>;</tt> [<var>expr3</var>] <tt>))</tt> <var>sublist</var></dt>
<dd><p>A short form of the arithmetic <tt>for</tt> command.
</p>
<a name="index-foreach"></a>
</dd>
<dt> <tt>foreach</tt> <var>name</var> ... <tt>(</tt> <var>word</var> ... <tt>)</tt> <var>list</var> <tt>end</tt></dt>
<dd><p>Another form of <tt>for</tt>.
</p>
</dd>
<dt> <tt>while</tt> <var>list</var> <tt>{</tt> <var>list</var> <tt>}</tt></dt>
<dd><p>An alternative form of <tt>while</tt>.  Note the limitations on the form of
<var>list</var> mentioned above.
</p>
</dd>
<dt> <tt>until</tt> <var>list</var> <tt>{</tt> <var>list</var> <tt>}</tt></dt>
<dd><p>An alternative form of <tt>until</tt>.  Note the limitations on the form of
<var>list</var> mentioned above.
</p>
</dd>
<dt> <tt>repeat</tt> <var>word</var> <var>sublist</var></dt>
<dd><p>This is a short form of <tt>repeat</tt>.
</p>
</dd>
<dt> <tt>case</tt> <var>word</var> <tt>{</tt> [ [<tt>(</tt>] <var>pattern</var> [ <tt>|</tt> <var>pattern</var> ] ... <tt>)</tt> <var>list</var> (<tt>;;</tt>|<tt>;&amp;</tt>|<tt>;|</tt>) ] ... <tt>}</tt></dt>
<dd><p>An alternative form of <tt>case</tt>.
</p>
</dd>
<dt> <tt>select</tt> <var>name</var> [ <tt>in</tt> <var>word</var> <var>term</var> ] <var>sublist</var></dt>
<dd><p>where <var>term</var> is at least one newline or <tt>;</tt>.
A short form of <tt>select</tt>.
</p>
</dd>
</dl>
<hr size="6">
<a name="Reserved-Words"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Alternate-Forms-For-Complex-Commands" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Errors" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Reserved-Words-1"></a>
<h2 class="section">6.5 Reserved Words</h2>
<a name="index-reserved-words"></a>
<a name="index-disable_002c-use-of"></a>
<p>The following words are recognized as reserved words when used as the first
word of a command unless quoted or disabled using <tt>disable -r</tt>:
</p>
<p><tt>do done esac then elif else fi for case
if while function repeat time until
select coproc nocorrect foreach end ! [[ { }</tt>
</p>
<p>Additionally, &lsquo;<tt>}</tt>&rsquo; is recognized in any position if neither the
<tt>IGNORE_BRACES</tt> option nor the <tt>IGNORE_CLOSE_BRACES</tt> option is set.
</p><hr size="6">
<a name="Errors"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Reserved-Words" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Comments" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Errors-1"></a>
<h2 class="section">6.6 Errors</h2>
<a name="index-errors_002c-handling-of"></a>
<p>Certain errors are treated as fatal by the shell: in an interactive
shell, they cause control to return to the command line, and in a
non-interactive shell they cause the shell to be aborted.  In older
versions of zsh, a non-interactive shell running a script would not
abort completely, but would resume execution at the next command to be
read from the script, skipping the remainder of any functions or
shell constructs such as loops or conditions; this somewhat illogical
behaviour can be recovered by setting the option <tt>CONTINUE_ON_ERROR</tt>.
</p>
<p>Fatal errors found in non-interactive shells include:
</p><dl compact="compact">
<dt> Failure to parse shell options passed when invoking the shell</dt>
<dt> Failure to change options with the <tt>set</tt> builtin</dt>
<dt> Parse errors of all sorts, including failures to parse</dt>
<dd><p>mathematical expressions
</p></dd>
<dt> Failures to set or modify variable behaviour with <tt>typeset</tt>,</dt>
<dd><p><tt>local</tt>, <tt>declare</tt>, <tt>export</tt>, <tt>integer</tt>, <tt>float</tt>
</p></dd>
<dt> Execution of incorrectly positioned loop control structures</dt>
<dd><p>(<tt>continue</tt>, <tt>break</tt>)
</p></dd>
<dt> Attempts to use regular expression with no regular expression</dt>
<dd><p>module available
</p></dd>
<dt> Disallowed operations when the <tt>RESTRICTED</tt> options is set</dt>
<dt> Failure to create a pipe needed for a pipeline</dt>
<dt> Failure to create a multio</dt>
<dt> Failure to autoload a module needed for a declared shell feature</dt>
<dt> Errors creating command or process substitutions</dt>
<dt> Syntax errors in glob qualifiers</dt>
<dt> File generation errors where not caught by the option <tt>BAD_PATTERN</tt></dt>
<dt> All bad patterns used for matching within case statements</dt>
<dt> File generation failures where not caused by <tt>NO_MATCH</tt> or</dt>
<dt> All file generation errors where the pattern was used to create a</dt>
<dd><p>multio
</p></dd>
<dt> Memory errors where detected by the shell</dt>
<dt> Invalid subscripts to shell variables</dt>
<dt> Attempts to assign read-only variables</dt>
<dt> Logical errors with variables such as assignment to the wrong type</dt>
<dt> Use of invalid variable names</dt>
<dt> Errors in variable substitution syntax</dt>
<dt> Failure to convert characters in <tt>$&rsquo;</tt>...<tt>&rsquo;</tt> expressions</dt>
<dd><p>similar options
</p></dd>
<dt></dt>
</dl>

<p>If the <tt>POSIX_BUILTINS</tt> option is set, more errors associated with
shell builtin commands are treated as fatal, as specified by the POSIX
standard.
</p>
<hr size="6">
<a name="Comments"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Errors" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Aliasing" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Comments-1"></a>
<h2 class="section">6.7 Comments</h2>
<a name="index-comments"></a>
<a name="index-INTERACTIVE_005fCOMMENTS_002c-use-of"></a>
<a name="index-histchars_002c-use-of"></a>
<p>In non-interactive shells, or in interactive shells with the
<tt>INTERACTIVE_COMMENTS</tt> option set, a word beginning
with the third character of the <tt>histchars</tt> parameter
(&lsquo;<tt>#</tt>&rsquo; by default) causes that word and all the following
characters up to a newline to be ignored.
</p><hr size="6">
<a name="Aliasing"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Comments" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Quoting" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Aliasing-1"></a>
<h2 class="section">6.8 Aliasing</h2>
<a name="index-aliasing"></a>
<p>Every token in the shell input is checked to see if there
is an alias defined for it.
If so, it is replaced by the text of the alias if it is in command
position (if it could be the first word of a simple command),
or if the alias is global.
If the text ends with a space, the next word in the shell input
is treated as though it were in command position for purposes of alias
expansion.
<a name="index-alias_002c-use-of"></a>
<a name="index-aliases_002c-global"></a>
An alias is defined using the <tt>alias</tt> builtin; global aliases
may be defined using the <tt>-g</tt> option to that builtin.
</p>
<p>Alias expansion is done on the shell input before any other expansion
except history expansion.  Therefore, if an alias is defined for the
word <tt>foo</tt>, alias expansion may be avoided by quoting part of the
word, e.g. <tt>\foo</tt>.  Any form of quoting works, although there is
nothing to prevent an alias being defined for the quoted form such as
<tt>\foo</tt> as well.  For use with completion, which would remove an
initial backslash followed by a character that isn&rsquo;t special, it may be
more convenient to quote the word by starting with a single quote,
i.e. <tt>&rsquo;foo</tt>; completion will automatically add the trailing single
quote.
</p>
<p>There is a commonly encountered problem with aliases
illustrated by the following code:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">alias echobar='echo bar'; echobar
</pre></td></tr></table>

<p>This prints a message that the command <tt>echobar</tt> could not be found.
This happens because aliases are expanded when the code is read in;
the entire line is read in one go, so that when <tt>echobar</tt> is executed it
is too late to expand the newly defined alias.  This is often
a problem in shell scripts, functions, and code executed with &lsquo;<tt>source</tt>&rsquo;
or &lsquo;<tt>.</tt>&rsquo;.  Consequently, use of functions rather than aliases is
recommended in non-interactive code.
</p>
<p>Note also the unhelpful interaction of aliases and function definitions:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">alias func='noglob func'
func() {
    echo Do something with $*
}
</pre></td></tr></table>

<p>Because aliases are expanded in function definitions, this causes the
following command to be executed:
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">noglob func() {
    echo Do something with $*
}
</pre></td></tr></table>

<p>which defines <tt>noglob</tt> as well as <tt>func</tt> as functions with the
body given.  To avoid this, either quote the name <tt>func</tt> or use the
alternative function definition form &lsquo;<tt>function func</tt>&rsquo;.  Ensuring the
alias is defined after the function works but is problematic if the
code fragment might be re-executed.
</p>
<hr size="6">
<a name="Quoting"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Aliasing" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Shell-Grammar" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Quoting-1"></a>
<h2 class="section">6.9 Quoting</h2>
<a name="index-quoting"></a>
<p>A character may be <var>quoted</var> (that is, made
to stand for itself) by preceding it with a &lsquo;<tt>\</tt>&rsquo;.
&lsquo;<tt>\</tt>&rsquo; followed by a newline is ignored.
</p>
<p>A string enclosed between &lsquo;<tt>$&rsquo;</tt>&rsquo; and &lsquo;<tt>&rsquo;</tt>&rsquo; is
processed the same way as the string arguments of the
<tt>print</tt> builtin, and the resulting string is considered to be
entirely quoted.  A literal &lsquo;<tt>&rsquo;</tt>&rsquo; character can be included in the
string by using the &lsquo;<tt>\&rsquo;</tt>&rsquo; escape.
</p>
<a name="index-RC_005fQUOTES_002c-use-of"></a>
<p>All characters enclosed between a pair of single quotes (<tt>&rsquo;&rsquo;</tt>) that
is not preceded by a &lsquo;<tt>$</tt>&rsquo; are quoted.  A single quote cannot appear
within single quotes unless the option <tt>RC_QUOTES</tt> is set, in which case
a pair of single quotes are turned into a single quote.  For example,
</p>
<table><tr><td>&nbsp;</td><td><pre class="example">print ''''
</pre></td></tr></table>

<p>outputs nothing apart from a newline if <tt>RC_QUOTES</tt> is not set, but one
single quote if it is set.
</p>
<p>Inside double quotes (<tt>&quot;&quot;</tt>), parameter and
command substitution occur, and &lsquo;<tt>\</tt>&rsquo; quotes the characters
&lsquo;<tt>\</tt>&rsquo;, &lsquo;<tt>&lsquo;</tt>&rsquo;, &lsquo;<tt>&quot;</tt>&rsquo;, and &lsquo;<tt>$</tt>&rsquo;.
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Shell-Grammar" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Redirection.html#Redirection" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="zsh.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>Peter Stephenson</em> on <em>December 21, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
 </font>
 <br>

</p>
</body>
</html>