File: tutorial.html

package info (click to toggle)
fish 4.2.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,976 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (808 lines) | stat: -rw-r--r-- 82,421 bytes parent folder | download
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
<!DOCTYPE html>

<html lang="en" data-content_root="./">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>Tutorial &#8212; fish-shell 4.2.1 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=4da8bbd6" />
    <link rel="stylesheet" type="text/css" href="_static/pydoctheme.css?v=f89b4716" />
    <script src="_static/documentation_options.js?v=6fb65176"></script>
    <script src="_static/doctools.js?v=9bcbadda"></script>
    <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Writing your own completions" href="completions.html" />
    <link rel="prev" title="Fish for bash users" href="fish_for_bash_users.html" />
    <link rel="shortcut icon" type="image/png" href="_static/fish.png" />
     

  </head><body><div id="fmain">  
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
    <li><img src="_static/fish.png" alt=""
             style="width: 80px; height: 80px; vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="https://fishshell.com/">fish-shell</a> &#187;</li>
    
    <a href="index.html">fish-shell 4.2.1 documentation</a> &#187;
    

        <li class="nav-item nav-item-this"><a href="">Tutorial</a></li>
    <li class="right">
        

    <div class="inline-search" role="search">
        <form class="inline-search" action="search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    </li>
    
    <div id="old-docs-notice" style="display: none">
        This documents an old version of fish.
        <a href="../current/">See the latest release.</a>
    </div>

      </ul>
    </div>    

    <div class="document">
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<div>
<h3><a href="index.html">Documents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently asked questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="interactive.html">Interactive use</a></li>
<li class="toctree-l1"><a class="reference internal" href="language.html">The fish language</a></li>
<li class="toctree-l1"><a class="reference internal" href="commands.html">Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="fish_for_bash_users.html">Fish for bash users</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="completions.html">Writing your own completions</a></li>
<li class="toctree-l1"><a class="reference internal" href="prompt.html">Writing your own prompt</a></li>
<li class="toctree-l1"><a class="reference internal" href="design.html">Design</a></li>
<li class="toctree-l1"><a class="reference internal" href="relnotes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="terminal-compatibility.html">Terminal Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing To Fish</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>

</div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
<div>
<h4><a href="index.html">Sections</a></h4>
<ul>
<li><a class="reference internal" href="#">Tutorial</a><ul>
<li><a class="reference internal" href="#why-fish">Why fish?</a></li>
<li><a class="reference internal" href="#getting-started">Getting started</a></li>
<li><a class="reference internal" href="#learning-fish">Learning fish</a></li>
<li><a class="reference internal" href="#running-commands">Running Commands</a></li>
<li><a class="reference internal" href="#getting-help">Getting Help</a></li>
<li><a class="reference internal" href="#syntax-highlighting">Syntax Highlighting</a></li>
<li><a class="reference internal" href="#autosuggestions">Autosuggestions</a></li>
<li><a class="reference internal" href="#tab-completions">Tab Completions</a></li>
<li><a class="reference internal" href="#variables">Variables</a></li>
<li><a class="reference internal" href="#exports-shell-variables">Exports (Shell Variables)</a></li>
<li><a class="reference internal" href="#lists">Lists</a></li>
<li><a class="reference internal" href="#wildcards">Wildcards</a></li>
<li><a class="reference internal" href="#pipes-and-redirections">Pipes and Redirections</a></li>
<li><a class="reference internal" href="#command-substitutions">Command Substitutions</a></li>
<li><a class="reference internal" href="#separating-commands-semicolon">Separating Commands (Semicolon)</a></li>
<li><a class="reference internal" href="#exit-status">Exit Status</a></li>
<li><a class="reference internal" href="#combiners-and-or-not">Combiners (And, Or, Not)</a></li>
<li><a class="reference internal" href="#conditionals-if-else-switch">Conditionals (If, Else, Switch)</a></li>
<li><a class="reference internal" href="#functions">Functions</a></li>
<li><a class="reference internal" href="#loops">Loops</a></li>
<li><a class="reference internal" href="#prompt">Prompt</a></li>
<li><a class="reference internal" href="#path">$PATH</a></li>
<li><a class="reference internal" href="#startup-where-s-bashrc">Startup (Where’s .bashrc?)</a></li>
<li><a class="reference internal" href="#autoloading-functions">Autoloading Functions</a></li>
<li><a class="reference internal" href="#universal-variables">Universal Variables</a></li>
<li><a class="reference internal" href="#ready-for-more">Ready for more?</a></li>
</ul>
</li>
</ul>

</div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="tutorial">
<h1>Tutorial<a class="headerlink" href="#tutorial" title="Link to this heading">¶</a></h1>
<section id="why-fish">
<h2>Why fish?<a class="headerlink" href="#why-fish" title="Link to this heading">¶</a></h2>
<p>Fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. Fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.</p>
<p>If you want to make your command line more productive, more useful, and more fun, without learning a bunch of arcane syntax and configuration options, then fish might be just what you’re looking for!</p>
</section>
<section id="getting-started">
<h2>Getting started<a class="headerlink" href="#getting-started" title="Link to this heading">¶</a></h2>
<p>Once installed, just type in <code class="docutils literal notranslate"><span class="pre">fish</span></code> into your current shell to try it out!</p>
<p>You will be greeted by the standard fish prompt,
which means you are all set up and can start using fish:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">fish</span>
<span class="go">Welcome to fish, the friendly interactive shell</span>
<span class="go">Type help for instructions on how to use fish</span>
<span class="go">you@hostname ~&gt;</span>
</pre></div>
</div>
<p>This prompt that you see above is the fish default prompt: it shows your username, hostname, and working directory. You can customize it, see <a class="reference internal" href="interactive.html#prompt"><span class="std std-ref">how to change your prompt</span></a>.</p>
<p>From now on, we’ll pretend your prompt is just a <code class="docutils literal notranslate"><span class="pre">&gt;</span></code> to save space.</p>
</section>
<section id="learning-fish">
<h2>Learning fish<a class="headerlink" href="#learning-fish" title="Link to this heading">¶</a></h2>
<p>This tutorial assumes a basic understanding of command line shells and Unix commands, and that you have a working copy of fish.</p>
<p>If you have a strong understanding of other shells, and want to know what fish does differently, search for the magic phrase <em>unlike other shells</em>, which is used to call out important differences.</p>
<p>Or, if you want a quick overview over the differences to other shells like Bash, see <a class="reference internal" href="fish_for_bash_users.html"><span class="doc">Fish For Bash Users</span></a>.</p>
<p>For the full, detailed description of how to use fish interactively, see <a class="reference internal" href="interactive.html"><span class="doc">Interactive Use</span></a>.</p>
<p>For a comprehensive description of fish’s scripting language, see <a class="reference internal" href="language.html"><span class="doc">The Fish Language</span></a>.</p>
</section>
<section id="running-commands">
<h2>Running Commands<a class="headerlink" href="#running-commands" title="Link to this heading">¶</a></h2>
<p>Fish runs commands like other shells: you type a command, followed by its arguments. Spaces are separators:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="no">hello</span><span class="w"> </span><span class="no">world</span>
<span class="go">hello world</span>
</pre></div>
</div>
<p>This runs the command <code class="docutils literal notranslate"><span class="pre">echo</span></code> with the arguments <code class="docutils literal notranslate"><span class="pre">hello</span></code> and <code class="docutils literal notranslate"><span class="pre">world</span></code>. In this case that’s the same as one argument <code class="docutils literal notranslate"><span class="pre">hello</span> <span class="pre">world</span></code>, but in many cases it’s not. If you need to pass an argument that includes a space, you can <a class="reference internal" href="language.html#escapes"><span class="std std-ref">escape</span></a> with a backslash, or <a class="reference internal" href="language.html#quotes"><span class="std std-ref">quote</span></a> it using single or double quotes:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">mkdir</span><span class="w"> </span><span class="no">My</span><span class="se">\ </span><span class="no">Files</span>
<span class="go"># Makes a directory called &quot;My Files&quot;, with a space in the name</span>
<span class="gp">&gt; </span><span class="nf">cp</span><span class="w"> </span><span class="o">~</span><span class="no">/Some</span><span class="se">\ </span><span class="no">File</span><span class="w"> </span><span class="s1">&#39;My Files&#39;</span>
<span class="go"># Copies a file called &quot;Some File&quot; in the home directory to &quot;My Files&quot;</span>
<span class="gp">&gt; </span><span class="nf">ls</span><span class="w"> </span><span class="s2">&quot;My Files&quot;</span>
<span class="go">Some File</span>
</pre></div>
</div>
</section>
<section id="getting-help">
<h2>Getting Help<a class="headerlink" href="#getting-help" title="Link to this heading">¶</a></h2>
<p>Run <code class="docutils literal notranslate"><span class="pre">help</span></code> to open fish’s help in a web browser, and <code class="docutils literal notranslate"><span class="pre">man</span></code> with the page (like <code class="docutils literal notranslate"><span class="pre">fish-language</span></code>) to open it in a man page. You can also ask for help with a specific command, for example, <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">set</span></code> to open in a web browser, or <code class="docutils literal notranslate"><span class="pre">man</span> <span class="pre">set</span></code> to see it in the terminal.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">man</span><span class="w"> </span><span class="no">set</span>
<span class="go">set - handle shell variables</span>
<span class="go">  Synopsis...</span>
</pre></div>
</div>
<p>To open this section, use <code class="docutils literal notranslate"><span class="pre">help</span> <span class="pre">getting-help</span></code>.</p>
<p>This only works for fish’s own documentation for itself and its built-in commands (the “builtins”). For any other commands on your system, they should provide their own documentation, often in the man system. For example <code class="docutils literal notranslate"><span class="pre">man</span> <span class="pre">ls</span></code> should tell you about your computer’s <code class="docutils literal notranslate"><span class="pre">ls</span></code> command.</p>
</section>
<section id="syntax-highlighting">
<h2>Syntax Highlighting<a class="headerlink" href="#syntax-highlighting" title="Link to this heading">¶</a></h2>
<p>You’ll quickly notice that fish performs syntax highlighting as you type. Invalid commands are colored red by default:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="red">/bin/mkd</span></pre>
<p>A command may be invalid because it does not exist, or refers to a file that you cannot execute. When the command becomes valid, it is shown in a different color:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">/bin/mkdir</span>
</pre></div>
</div>
<p>Valid file paths are underlined as you type them:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="command">cat</span> <span class="param-valid-path">~/somefi</span></pre>
<p>This tells you that there exists a file that starts with <code class="docutils literal notranslate"><span class="pre">somefi</span></code>, which is useful feedback as you type.</p>
<p>These colors, and many more, can be changed by running <code class="docutils literal notranslate"><span class="pre">fish_config</span></code>, or by modifying <a class="reference internal" href="interactive.html#variables-color"><span class="std std-ref">color variables</span></a> directly.</p>
<p>For example, if you want to disable (almost) all coloring:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">fish_config</span><span class="w"> </span><span class="no">theme</span><span class="w"> </span><span class="no">choose</span><span class="w"> </span><span class="no">None</span>
</pre></div>
</div>
<p>This picks the “none” theme. To see all themes:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">fish_config</span><span class="w"> </span><span class="no">theme</span><span class="w"> </span><span class="no">show</span>
</pre></div>
</div>
<p>Just running <code class="docutils literal notranslate"><span class="pre">fish_config</span></code> will open up a browser interface that allows you to pick from the available themes.</p>
</section>
<section id="autosuggestions">
<h2>Autosuggestions<a class="headerlink" href="#autosuggestions" title="Link to this heading">¶</a></h2>
<p>As you type fish will suggest commands to the right of the cursor, in gray. For example:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="red">/bin/h</span><span class="gray">ostname</span></pre>
<p>It knows about paths and options:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="command">grep</span> <span class="param">--i</span><span class="gray">gnore-case</span></pre>
<p>And history too. Type a command once, and you can re-summon it by just typing a few letters:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="red">r</span><span class="gray">sync -avze ssh . myname&#64;somelonghost.com:/some/long/path/doo/dee/doo/dee/doo</span></pre>
<p>To accept the autosuggestion, hit <kbd class="kbd docutils literal notranslate">right</kbd> (<code class="docutils literal notranslate"><span class="pre">→</span></code>) or <kbd class="kbd docutils literal notranslate">ctrl</kbd>-<kbd class="kbd docutils literal notranslate">f</kbd>. To accept a single word of the autosuggestion, <kbd class="kbd docutils literal notranslate">alt</kbd>-<kbd class="kbd docutils literal notranslate">right</kbd> (<code class="docutils literal notranslate"><span class="pre">→</span></code>). If the autosuggestion is not what you want, just ignore it.</p>
<p>If you don’t like autosuggestions, you can disable them by setting <code class="docutils literal notranslate"><span class="pre">$fish_autosuggestion_enabled</span></code> to 0:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">set</span><span class="w"> </span><span class="no">-g</span><span class="w"> </span><span class="no">fish_autosuggestion_enabled</span><span class="w"> </span><span class="no">0</span>
</pre></div>
</div>
</section>
<section id="tab-completions">
<h2>Tab Completions<a class="headerlink" href="#tab-completions" title="Link to this heading">¶</a></h2>
<p>A rich set of tab completions work “out of the box”.</p>
<p>Press <kbd class="kbd docutils literal notranslate">tab</kbd> and fish will attempt to complete the command, argument, or path:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="red">/pri</span><kbd class="kbd docutils literal notranslate">tab</kbd> =&gt; <span class="command">/private/</span></pre>
<p>If there’s more than one possibility, it will list them:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="red">~/stuff/s</span><kbd class="kbd docutils literal notranslate">tab</kbd>
~/stuff/script.sh  <span class="gray">(command)</span>  ~/stuff/sources/  <span class="gray">(directory)</span></pre>
<p>Hit tab again to cycle through the possibilities. The part in parentheses there (that “command” and “directory”) is the completion description. It’s just a short hint to explain what kind of argument it is.</p>
<p>fish can also complete many commands, like git branches:</p>
<pre class="highlight literal-block"><span class="prompt">&gt;</span> <span class="command">git</span> <span class="param">merge pr</span><kbd class="kbd docutils literal notranslate">tab</kbd> =&gt; <span class="command">git</span> <span class="param">merge prompt_designer</span>
<span class="prompt">&gt;</span> <span class="command">git</span> <span class="param">checkout b</span><kbd class="kbd docutils literal notranslate">tab</kbd>
builtin_list_io_merge <span class="gray">(Branch)</span>  builtin_set_color <span class="gray">(Branch)</span> busted_events <span class="gray">(Tag)</span></pre>
<p>Try hitting tab and see what fish can do!</p>
</section>
<section id="variables">
<h2>Variables<a class="headerlink" href="#variables" title="Link to this heading">¶</a></h2>
<p>Like other shells, a dollar sign followed by a variable name is replaced with the value of that variable:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="no">My</span><span class="w"> </span><span class="no">home</span><span class="w"> </span><span class="no">directory</span><span class="w"> </span><span class="no">is</span><span class="w"> </span><span class="o">$HOME</span>
<span class="go">My home directory is /home/tutorial</span>
</pre></div>
</div>
<p>This is known as variable substitution, and it also happens in double quotes, but not single quotes:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;My current directory is </span><span class="o">$PWD</span><span class="s2">&quot;</span>
<span class="go">My current directory is /home/tutorial</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="s1">&#39;My current directory is $PWD&#39;</span>
<span class="go">My current directory is $PWD</span>
</pre></div>
</div>
<p>Unlike other shells, fish has an ordinary command to set variables: <code class="docutils literal notranslate"><span class="pre">set</span></code>, which takes a variable name, and then its value.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">name</span><span class="w"> </span><span class="s1">&#39;Mister Noodle&#39;</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$name</span>
<span class="go">Mister Noodle</span>
</pre></div>
</div>
<p>(Notice the quotes: without them, <code class="docutils literal notranslate"><span class="pre">Mister</span></code> and <code class="docutils literal notranslate"><span class="pre">Noodle</span></code> would have been separate arguments, and <code class="docutils literal notranslate"><span class="pre">$name</span></code> would have been made into a list of two elements.)</p>
<p>Unlike other shells, variables are not further split after substitution:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">mkdir</span><span class="w"> </span><span class="o">$name</span>
<span class="gp">&gt; </span><span class="nf">ls</span>
<span class="go">Mister Noodle</span>
</pre></div>
</div>
<p>In bash, this would have created two directories “Mister” and “Noodle”. In fish, it created only one: the variable had the value “Mister Noodle”, so that is the argument that was passed to <code class="docutils literal notranslate"><span class="pre">mkdir</span></code>, spaces and all.</p>
<p>You can erase (or “delete”) a variable with <code class="docutils literal notranslate"><span class="pre">-e</span></code> or <code class="docutils literal notranslate"><span class="pre">--erase</span></code></p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">-e</span><span class="w"> </span><span class="no">MyVariable</span>
<span class="gp">&gt; </span><span class="nf">env</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">grep</span><span class="w"> </span><span class="no">MyVariable</span>
<span class="go">(no output)</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="language.html#expand-variable"><span class="std std-ref">Variable expansion</span></a>.</p>
</section>
<section id="exports-shell-variables">
<span id="tut-exports"></span><h2>Exports (Shell Variables)<a class="headerlink" href="#exports-shell-variables" title="Link to this heading">¶</a></h2>
<p>Sometimes you need to have a variable available to an external command, often as a setting. For example many programs like <code class="docutils literal notranslate"><span class="pre">git</span></code> or <code class="docutils literal notranslate"><span class="pre">man</span></code> read the <code class="docutils literal notranslate"><span class="pre">$PAGER</span></code> variable to figure out your preferred pager (the program that lets you scroll text). Other variables used like this include <code class="docutils literal notranslate"><span class="pre">$BROWSER</span></code>, <code class="docutils literal notranslate"><span class="pre">$LANG</span></code> (to configure your language) and <code class="docutils literal notranslate"><span class="pre">$PATH</span></code>. You’ll note these are written in ALLCAPS, but that’s just a convention.</p>
<p>To give a variable to an external command, it needs to be “exported”. This is done with a flag to <code class="docutils literal notranslate"><span class="pre">set</span></code>, either <code class="docutils literal notranslate"><span class="pre">--export</span></code> or just <code class="docutils literal notranslate"><span class="pre">-x</span></code>.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">-x</span><span class="w"> </span><span class="no">MyVariable</span><span class="w"> </span><span class="no">SomeValue</span>
<span class="gp">&gt; </span><span class="nf">env</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">grep</span><span class="w"> </span><span class="no">MyVariable</span>
<span class="go">MyVariable=SomeValue</span>
</pre></div>
</div>
<p>It can also be unexported with <code class="docutils literal notranslate"><span class="pre">--unexport</span></code> or <code class="docutils literal notranslate"><span class="pre">-u</span></code>.</p>
<p>This works the other way around as well! If fish is started by something else, it inherits that parents exported variables. So if your terminal emulator starts fish, and it exports <code class="docutils literal notranslate"><span class="pre">$LANG</span></code> set to <code class="docutils literal notranslate"><span class="pre">en_US.UTF-8</span></code>, fish will receive that setting. And whatever started your terminal emulator also gave <em>it</em> some variables that it will then pass on unless it specifically decides not to. This is how fish usually receives the values for things like <code class="docutils literal notranslate"><span class="pre">$LANG</span></code>, <code class="docutils literal notranslate"><span class="pre">$PATH</span></code> and <code class="docutils literal notranslate"><span class="pre">$TERM</span></code>, without you having to specify them again.</p>
<p>Exported variables can be local or global or universal - “exported” is not a <a class="reference internal" href="language.html#variables-scope"><span class="std std-ref">scope</span></a>! Usually you’d make them global via <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">-gx</span> <span class="pre">MyVariable</span> <span class="pre">SomeValue</span></code>.</p>
<p>For more, see <a class="reference internal" href="language.html#variables-export"><span class="std std-ref">Exporting variables</span></a>.</p>
</section>
<section id="lists">
<span id="tut-lists"></span><h2>Lists<a class="headerlink" href="#lists" title="Link to this heading">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">set</span></code> command above used quotes to ensure that <code class="docutils literal notranslate"><span class="pre">Mister</span> <span class="pre">Noodle</span></code> was one argument. If it had been two arguments, then <code class="docutils literal notranslate"><span class="pre">name</span></code> would have been a list of length 2.  In fact, all variables in fish are really lists, that can contain any number of values, or none at all.</p>
<p>Some variables, like <code class="docutils literal notranslate"><span class="pre">$PWD</span></code>, only have one value. By convention, we talk about that variable’s value, but we really mean its first (and only) value.</p>
<p>Other variables, like <code class="docutils literal notranslate"><span class="pre">$PATH</span></code>, really do have multiple values. During variable expansion, the variable expands to become multiple arguments:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$PATH</span>
<span class="go">/usr/bin /bin /usr/sbin /sbin /usr/local/bin</span>
</pre></div>
</div>
<p>Variables whose name ends in “PATH” are automatically split on colons to become lists. They are joined using colons when exported to subcommands. This is for compatibility with other tools, which expect $PATH to use colons. You can also explicitly add this quirk to a variable with <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">--path</span></code>, or remove it with <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">--unpath</span></code>.</p>
<p>Lists cannot contain other lists: there is no recursion.  A variable is a list of strings, full stop.</p>
<p>Get the length of a list with <code class="docutils literal notranslate"><span class="pre">count</span></code>:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">count</span><span class="w"> </span><span class="o">$PATH</span>
<span class="go">5</span>
</pre></div>
</div>
<p>You can append (or prepend) to a list by setting the list to itself, with some additional arguments. Here we append /usr/local/bin to $PATH:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">PATH</span><span class="w"> </span><span class="o">$PATH</span><span class="w"> </span><span class="no">/usr/local/bin</span>
</pre></div>
</div>
<p>You can access individual elements with square brackets. Indexing starts at 1 from the beginning, and -1 from the end:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$PATH</span>
<span class="go">/usr/bin /bin /usr/sbin /sbin /usr/local/bin</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$PATH[</span><span class="no">1</span><span class="o">]</span>
<span class="go">/usr/bin</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$PATH[</span><span class="no">-1</span><span class="o">]</span>
<span class="go">/usr/local/bin</span>
</pre></div>
</div>
<p>You can also access ranges of elements, known as “slices”:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$PATH[</span><span class="no">1..2</span><span class="o">]</span>
<span class="go">/usr/bin /bin</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$PATH[</span><span class="no">-1..2</span><span class="o">]</span>
<span class="go">/usr/local/bin /sbin /usr/sbin /bin</span>
</pre></div>
</div>
<p>You can iterate over a list (or a slice) with a for loop:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">for</span><span class="w"> </span><span class="no">val</span><span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="o">$PATH</span>
<span class="w">  </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;entry: </span><span class="o">$val</span><span class="s2">&quot;</span>
<span class="nf">end</span>
<span class="c"># Will print:</span>
<span class="c"># entry: /usr/bin/</span>
<span class="c"># entry: /bin</span>
<span class="c"># entry: /usr/sbin</span>
<span class="c"># entry: /sbin</span>
<span class="c"># entry: /usr/local/bin</span>
</pre></div>
</div>
<p>One particular bit is that you can use lists like <a class="reference internal" href="language.html#expand-brace"><span class="std std-ref">Brace expansion</span></a>. If you attach another string to a list, it’ll combine every element of the list with the string:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">mydirs</span><span class="w"> </span><span class="no">/usr/bin</span><span class="w"> </span><span class="no">/bin</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$mydirs</span><span class="no">/fish</span><span class="w"> </span><span class="c"># this is just like {/usr/bin,/bin}/fish</span>
<span class="go">/usr/bin/fish /bin/fish</span>
</pre></div>
</div>
<p>This also means that, if the list is empty, there will be no argument:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">empty</span><span class="w"> </span><span class="c"># no argument</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$empty</span><span class="no">/this_is_gone</span><span class="w"> </span><span class="c"># prints an empty line</span>
</pre></div>
</div>
<p>If you quote the list, it will be used as one string and so you’ll get one argument even if it is empty.</p>
<p>For more, see <a class="reference internal" href="language.html#variables-lists"><span class="std std-ref">Lists</span></a>.
For more on combining lists with strings (or even other lists), see <a class="reference internal" href="language.html#cartesian-product"><span class="std std-ref">cartesian products</span></a> and <a class="reference internal" href="language.html#expand-variable"><span class="std std-ref">Variable expansion</span></a>.</p>
</section>
<section id="wildcards">
<h2>Wildcards<a class="headerlink" href="#wildcards" title="Link to this heading">¶</a></h2>
<p>Fish supports the familiar wildcard <code class="docutils literal notranslate"><span class="pre">*</span></code>. To list all JPEG files:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">ls</span><span class="w"> </span><span class="o">*</span><span class="no">.jpg</span>
<span class="go">lena.jpg</span>
<span class="go">meena.jpg</span>
<span class="go">santa maria.jpg</span>
</pre></div>
</div>
<p>You can include multiple wildcards:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">ls</span><span class="w"> </span><span class="no">l</span><span class="o">*</span><span class="no">.p</span><span class="o">*</span>
<span class="go">lena.png</span>
<span class="go">lesson.pdf</span>
</pre></div>
</div>
<p>The recursive wildcard <code class="docutils literal notranslate"><span class="pre">**</span></code> searches directories recursively:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">ls</span><span class="w"> </span><span class="no">/var/</span><span class="o">**</span><span class="no">.log</span>
<span class="go">/var/log/system.log</span>
<span class="go">/var/run/sntp.log</span>
</pre></div>
</div>
<p>If that directory traversal is taking a long time, you can <kbd class="kbd docutils literal notranslate">ctrl</kbd>-<kbd class="kbd docutils literal notranslate">c</kbd> out of it.</p>
<p>For more, see <a class="reference internal" href="language.html#expand-wildcard"><span class="std std-ref">Wildcards</span></a>.</p>
</section>
<section id="pipes-and-redirections">
<h2>Pipes and Redirections<a class="headerlink" href="#pipes-and-redirections" title="Link to this heading">¶</a></h2>
<p>You can pipe between commands with the usual vertical bar:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="no">hello</span><span class="w"> </span><span class="no">world</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">wc</span>
<span class="go">      1       2      12</span>
</pre></div>
</div>
<p>stdin and stdout can be redirected via the familiar <code class="docutils literal notranslate"><span class="pre">&lt;</span></code> and <code class="docutils literal notranslate"><span class="pre">&gt;</span></code>. stderr is redirected with a <code class="docutils literal notranslate"><span class="pre">2&gt;</span></code>.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">grep</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="p">&lt;</span><span class="w"> </span><span class="p">/etc/shells</span><span class="w"> </span><span class="p">&gt;</span><span class="w"> </span><span class="p">~/output.txt</span><span class="w"> </span><span class="p">2&gt;</span><span class="w"> </span><span class="p">~/errors.txt</span>
</pre></div>
</div>
<p>To redirect stdout and stderr into one file, you can use <code class="docutils literal notranslate"><span class="pre">&amp;&gt;</span></code>:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">make</span><span class="w"> </span><span class="p">&amp;&gt;</span><span class="w"> </span><span class="p">make_output.txt</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="language.html#redirects"><span class="std std-ref">Input and output redirections</span></a> and <a class="reference internal" href="language.html#pipes"><span class="std std-ref">Pipes</span></a>.</p>
</section>
<section id="command-substitutions">
<h2>Command Substitutions<a class="headerlink" href="#command-substitutions" title="Link to this heading">¶</a></h2>
<p>Command substitutions use the output of one command as an argument to another. Unlike other shells, fish does not use backticks `` for command substitutions. Instead, it uses parentheses with or without a dollar:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="no">In</span><span class="w"> </span><span class="o">(</span><span class="nf">pwd</span><span class="o">)</span><span class="no">,</span><span class="w"> </span><span class="no">running</span><span class="w"> </span><span class="o">$(</span><span class="nf">uname</span><span class="o">)</span>
<span class="go">In /home/tutorial, running FreeBSD</span>
</pre></div>
</div>
<p>A common idiom is to capture the output of a command in a variable:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">os</span><span class="w"> </span><span class="o">(</span><span class="nf">uname</span><span class="o">)</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$os</span>
<span class="go">Linux</span>
</pre></div>
</div>
<p>Command substitutions without a dollar are not expanded within quotes, so the version with a dollar is simpler:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">touch</span><span class="w"> </span><span class="s2">&quot;testing_</span><span class="o">$(</span><span class="nf">date</span><span class="w"> </span><span class="no">+%s</span><span class="o">)</span><span class="s2">.txt&quot;</span>
<span class="gp">&gt; </span><span class="nf">ls</span><span class="w"> </span><span class="o">*</span><span class="no">.txt</span>
<span class="go">testing_1360099791.txt</span>
</pre></div>
</div>
<p>Unlike other shells, fish does not split command substitutions on any whitespace (like spaces or tabs), only newlines. Usually this is a big help because unix commands operate on a line-by-line basis. Sometimes it can be an issue with commands like <code class="docutils literal notranslate"><span class="pre">pkg-config</span></code> that print what is meant to be multiple arguments on a single line. To split it on spaces too, use <code class="docutils literal notranslate"><span class="pre">string</span> <span class="pre">split</span></code>.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">printf</span><span class="w"> </span><span class="s1">&#39;%s\n&#39;</span><span class="w"> </span><span class="o">(</span><span class="nf">pkg-config</span><span class="w"> </span><span class="no">--libs</span><span class="w"> </span><span class="no">gio-2.0</span><span class="o">)</span>
<span class="go">-lgio-2.0 -lgobject-2.0 -lglib-2.0</span>
<span class="gp">&gt; </span><span class="nf">printf</span><span class="w"> </span><span class="s1">&#39;%s\n&#39;</span><span class="w"> </span><span class="o">(</span><span class="nf">pkg-config</span><span class="w"> </span><span class="no">--libs</span><span class="w"> </span><span class="no">gio-2.0</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">string</span><span class="w"> </span><span class="no">split</span><span class="w"> </span><span class="no">-n</span><span class="w"> </span><span class="s2">&quot; &quot;</span><span class="o">)</span>
<span class="go">-lgio-2.0</span>
<span class="go">-lgobject-2.0</span>
<span class="go">-lglib-2.0</span>
</pre></div>
</div>
<p>If you need a command substitutions output as one argument, without any splits, use quoted command substitution:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="gr">&quot;</span><span class="s2">first line</span>
<span class="go">second line&quot; &gt; myfile</span>
<span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">myfile</span><span class="w"> </span><span class="s2">&quot;</span><span class="o">$(</span><span class="nf">cat</span><span class="w"> </span><span class="no">myfile</span><span class="o">)</span><span class="s2">&quot;</span>
<span class="gp">&gt; </span><span class="nf">printf</span><span class="w"> </span><span class="s1">&#39;|%s|&#39;</span><span class="w"> </span><span class="o">$myfile</span>
<span class="go">|first line</span>
<span class="go">second line|</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="language.html#expand-command-substitution"><span class="std std-ref">Command substitution</span></a>.</p>
</section>
<section id="separating-commands-semicolon">
<span id="tut-semicolon"></span><h2>Separating Commands (Semicolon)<a class="headerlink" href="#separating-commands-semicolon" title="Link to this heading">¶</a></h2>
<p>Like other shells, fish allows multiple commands either on separate lines or the same line.</p>
<p>To write them on the same line, use the semicolon (“;”). That means the following two examples are equivalent:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">echo</span><span class="w"> </span><span class="no">fish</span><span class="p">;</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="no">chips</span>

<span class="c"># or</span>
<span class="nf">echo</span><span class="w"> </span><span class="no">fish</span>
<span class="nf">echo</span><span class="w"> </span><span class="no">chips</span>
</pre></div>
</div>
<p>This is useful interactively to enter multiple commands. In a script it’s easier to read if the commands are on separate lines.</p>
</section>
<section id="exit-status">
<h2>Exit Status<a class="headerlink" href="#exit-status" title="Link to this heading">¶</a></h2>
<p>When a command exits, it returns a status code as a non-negative integer (that’s a whole number &gt;= 0).</p>
<p>Unlike other shells, fish stores the exit status of the last command in <code class="docutils literal notranslate"><span class="pre">$status</span></code> instead of <code class="docutils literal notranslate"><span class="pre">$?</span></code>.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">false</span>
<span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$status</span>
<span class="go">1</span>
</pre></div>
</div>
<p>This indicates how the command fared - 0 usually means success, while the others signify kinds of failure. For instance fish’s <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">--query</span></code> returns the number of variables it queried that weren’t set - <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">--query</span> <span class="pre">PATH</span></code> usually returns 0, <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">--query</span> <span class="pre">arglbargl</span> <span class="pre">boogagoogoo</span></code> usually returns 2.</p>
<p>There is also a <code class="docutils literal notranslate"><span class="pre">$pipestatus</span></code> list variable for the exit statuses <a class="footnote-reference brackets" href="#id2" id="id1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a> of processes in a pipe.</p>
<p>For more, see <a class="reference internal" href="language.html#variables-status"><span class="std std-ref">The status variable</span></a>.</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id2" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id1">1</a><span class="fn-bracket">]</span></span>
<p>or “stati” if you prefer, or “statūs” if you’ve time-travelled from ancient Rome or work as a latin teacher</p>
</aside>
</aside>
</section>
<section id="combiners-and-or-not">
<span id="tut-combiners"></span><h2>Combiners (And, Or, Not)<a class="headerlink" href="#combiners-and-or-not" title="Link to this heading">¶</a></h2>
<p>fish supports the familiar <code class="docutils literal notranslate"><span class="pre">&amp;&amp;</span></code> and <code class="docutils literal notranslate"><span class="pre">||</span></code> to combine commands, and <code class="docutils literal notranslate"><span class="pre">!</span></code> to negate them:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">./configure</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="nf">make</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="nf">sudo</span><span class="w"> </span><span class="no">make</span><span class="w"> </span><span class="no">install</span>
</pre></div>
</div>
<p>Here, <code class="docutils literal notranslate"><span class="pre">make</span></code> is only executed if <code class="docutils literal notranslate"><span class="pre">./configure</span></code> succeeds (returns 0), and <code class="docutils literal notranslate"><span class="pre">sudo</span> <span class="pre">make</span> <span class="pre">install</span></code> is only executed if both <code class="docutils literal notranslate"><span class="pre">./configure</span></code> and <code class="docutils literal notranslate"><span class="pre">make</span></code> succeed.</p>
<p>fish also supports <a class="reference internal" href="cmds/and.html"><span class="doc">and</span></a>, <a class="reference internal" href="cmds/or.html"><span class="doc">or</span></a>, and <a class="reference internal" href="cmds/not.html"><span class="doc">not</span></a>. The first two are job modifiers and have lower precedence. Example usage:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">cp</span><span class="w"> </span><span class="no">file1</span><span class="w"> </span><span class="no">file1_bak</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="nf">cp</span><span class="w"> </span><span class="no">file2</span><span class="w"> </span><span class="no">file2_bak</span><span class="p">;</span><span class="w"> </span><span class="o">and</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;Backup successful&quot;</span><span class="p">;</span><span class="w"> </span><span class="o">or</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;Backup failed&quot;</span>
<span class="go">Backup failed</span>
</pre></div>
</div>
<p>As mentioned in <a class="reference internal" href="#tut-semicolon"><span class="std std-ref">the section on the semicolon</span></a>, this can also be written in multiple lines, like so:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">cp</span><span class="w"> </span><span class="no">file1</span><span class="w"> </span><span class="no">file1_bak</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="nf">cp</span><span class="w"> </span><span class="no">file2</span><span class="w"> </span><span class="no">file2_bak</span>
<span class="o">and</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;Backup successful&quot;</span>
<span class="o">or</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;Backup failed&quot;</span>
</pre></div>
</div>
</section>
<section id="conditionals-if-else-switch">
<h2>Conditionals (If, Else, Switch)<a class="headerlink" href="#conditionals-if-else-switch" title="Link to this heading">¶</a></h2>
<p>Use <a class="reference internal" href="cmds/if.html"><span class="doc">if</span></a> and <a class="reference internal" href="cmds/else.html"><span class="doc">else</span></a> to conditionally execute code, based on the exit status of a command.</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">if</span><span class="w"> </span><span class="nf">grep</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="no">/etc/shells</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Found</span><span class="w"> </span><span class="no">fish</span>
<span class="nf">else</span><span class="w"> </span><span class="nf">if</span><span class="w"> </span><span class="nf">grep</span><span class="w"> </span><span class="no">bash</span><span class="w"> </span><span class="no">/etc/shells</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Found</span><span class="w"> </span><span class="no">bash</span>
<span class="nf">else</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Got</span><span class="w"> </span><span class="no">nothing</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>To compare strings or numbers or check file properties (whether a file exists or is writeable and such), use <a class="reference internal" href="cmds/test.html"><span class="doc">test</span></a>, like</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">if</span><span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="s2">&quot;</span><span class="o">$fish</span><span class="s2">&quot;</span><span class="w"> </span><span class="no">=</span><span class="w"> </span><span class="s2">&quot;flounder&quot;</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">FLOUNDER</span>
<span class="nf">end</span>

<span class="c"># or</span>

<span class="nf">if</span><span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="s2">&quot;</span><span class="o">$number</span><span class="s2">&quot;</span><span class="w"> </span><span class="no">-gt</span><span class="w"> </span><span class="no">5</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="o">$number</span><span class="w"> </span><span class="no">is</span><span class="w"> </span><span class="no">greater</span><span class="w"> </span><span class="no">than</span><span class="w"> </span><span class="no">five</span>
<span class="nf">else</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="o">$number</span><span class="w"> </span><span class="no">is</span><span class="w"> </span><span class="no">five</span><span class="w"> </span><span class="no">or</span><span class="w"> </span><span class="no">less</span>
<span class="nf">end</span>

<span class="c"># or</span>

<span class="c"># This test is true if the path /etc/hosts exists</span>
<span class="c"># - it could be a file or directory or symlink (or possibly something else).</span>
<span class="nf">if</span><span class="w"> </span><span class="nf">test</span><span class="w"> </span><span class="no">-e</span><span class="w"> </span><span class="no">/etc/hosts</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">We</span><span class="w"> </span><span class="no">most</span><span class="w"> </span><span class="no">likely</span><span class="w"> </span><span class="no">have</span><span class="w"> </span><span class="no">a</span><span class="w"> </span><span class="no">hosts</span><span class="w"> </span><span class="no">file</span>
<span class="nf">else</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">We</span><span class="w"> </span><span class="no">do</span><span class="w"> </span><span class="no">not</span><span class="w"> </span><span class="no">have</span><span class="w"> </span><span class="no">a</span><span class="w"> </span><span class="no">hosts</span><span class="w"> </span><span class="no">file</span>
<span class="nf">end</span>
</pre></div>
</div>
<p><a class="reference internal" href="#tut-combiners"><span class="std std-ref">Combiners</span></a> can also be used to make more complex conditions, like</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">if</span><span class="w"> </span><span class="nf">command</span><span class="w"> </span><span class="no">-sq</span><span class="w"> </span><span class="no">fish</span><span class="p">;</span><span class="w"> </span><span class="o">and</span><span class="w"> </span><span class="nf">grep</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="no">/etc/shells</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="no">is</span><span class="w"> </span><span class="no">installed</span><span class="w"> </span><span class="no">and</span><span class="w"> </span><span class="no">configured</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>For even more complex conditions, use <a class="reference internal" href="cmds/begin.html"><span class="doc">begin</span></a> and <a class="reference internal" href="cmds/end.html"><span class="doc">end</span></a> to group parts of them.</p>
<p>There is also a <a class="reference internal" href="cmds/switch.html"><span class="doc">switch</span></a> command:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">switch</span><span class="w"> </span><span class="o">(</span><span class="nf">uname</span><span class="o">)</span>
<span class="nf">case</span><span class="w"> </span><span class="no">Linux</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Hi</span><span class="w"> </span><span class="no">Tux!</span>
<span class="nf">case</span><span class="w"> </span><span class="no">Darwin</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Hi</span><span class="w"> </span><span class="no">Hexley!</span>
<span class="nf">case</span><span class="w"> </span><span class="no">FreeBSD</span><span class="w"> </span><span class="no">NetBSD</span><span class="w"> </span><span class="no">DragonFly</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Hi</span><span class="w"> </span><span class="no">Beastie!</span>
<span class="nf">case</span><span class="w"> </span><span class="s1">&#39;*&#39;</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Hi,</span><span class="w"> </span><span class="no">stranger!</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>As you see, <a class="reference internal" href="cmds/case.html"><span class="doc">case</span></a> does not fall through, and can accept multiple arguments or (quoted) wildcards.</p>
<p>For more, see <a class="reference internal" href="language.html#syntax-conditional"><span class="std std-ref">Conditions</span></a>.</p>
</section>
<section id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Link to this heading">¶</a></h2>
<p>A fish function is a list of commands, which may optionally take arguments. Unlike other shells, arguments are not passed in “numbered variables” like <code class="docutils literal notranslate"><span class="pre">$1</span></code>, but instead in a single list <code class="docutils literal notranslate"><span class="pre">$argv</span></code>. To create a function, use the <a class="reference internal" href="cmds/function.html"><span class="doc">function</span></a> builtin:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">function</span><span class="w"> </span><span class="no">say_hello</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">Hello</span><span class="w"> </span><span class="o">$argv</span>
<span class="nf">end</span>
<span class="nf">say_hello</span>
<span class="c"># prints: Hello</span>
<span class="nf">say_hello</span><span class="w"> </span><span class="no">everybody!</span>
<span class="c"># prints: Hello everybody!</span>
</pre></div>
</div>
<p>Unlike other shells, fish does not have aliases or special prompt syntax. Functions take their place. <a class="footnote-reference brackets" href="#id4" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a></p>
<p>You can list the names of all functions with the <a class="reference internal" href="cmds/functions.html"><span class="doc">functions</span></a> builtin (note the plural!). fish starts out with a number of functions:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">functions</span>
<span class="go">N_, abbr, alias, bg, cd, cdh, contains_seq, dirh, dirs, disown, down-or-search, edit_command_buffer, export, fg, fish_add_path, fish_breakpoint_prompt, fish_clipboard_copy, fish_clipboard_paste, fish_config, fish_default_key_bindings, fish_default_mode_prompt, fish_git_prompt, fish_hg_prompt, fish_hybrid_key_bindings, fish_indent, fish_is_root_user, fish_job_summary, fish_key_reader, fish_md5, fish_mode_prompt, fish_npm_helper, fish_opt, fish_print_git_action, fish_print_hg_root, fish_prompt, fish_sigtrap_handler, fish_svn_prompt, fish_title, fish_update_completions, fish_vcs_prompt, fish_vi_cursor, fish_vi_key_bindings, funced, funcsave, grep, help, history, hostname, isatty, kill, la, ll, ls, man, nextd, open, popd, prevd, prompt_hostname, prompt_pwd, psub, pushd, realpath, seq, setenv, suspend, trap, type, umask, up-or-search, vared, wait</span>
</pre></div>
</div>
<p>You can see the source for any function by passing its name to <code class="docutils literal notranslate"><span class="pre">functions</span></code>:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">functions</span><span class="w"> </span><span class="no">ls</span>
<span class="go">function ls --description &#39;List contents of directory&#39;</span>
<span class="go">    command ls -G $argv</span>
<span class="go">end</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="language.html#syntax-function"><span class="std std-ref">Functions</span></a>.</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id4" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id3">2</a><span class="fn-bracket">]</span></span>
<p>There is a function called <a class="reference internal" href="cmds/alias.html"><span class="doc">alias</span></a>, but it’s just a shortcut to make functions. fish also provides <a class="reference internal" href="interactive.html#abbreviations"><span class="std std-ref">abbreviations</span></a>, through the <a class="reference internal" href="cmds/abbr.html"><span class="doc">abbr</span></a> command.</p>
</aside>
</aside>
</section>
<section id="loops">
<h2>Loops<a class="headerlink" href="#loops" title="Link to this heading">¶</a></h2>
<p>While loops:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">while</span><span class="w"> </span><span class="nf">true</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;Loop forever&quot;</span>
<span class="nf">end</span>
<span class="c"># Prints:</span>
<span class="c"># Loop forever</span>
<span class="c"># Loop forever</span>
<span class="c"># Loop forever</span>
<span class="c"># yes, this really will loop forever. Unless you abort it with ctrl-c.</span>
</pre></div>
</div>
<p>For loops can be used to iterate over a list. For example, a list of files:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">for</span><span class="w"> </span><span class="no">file</span><span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="o">*</span><span class="no">.txt</span>
<span class="w">    </span><span class="nf">cp</span><span class="w"> </span><span class="o">$file</span><span class="w"> </span><span class="o">$file</span><span class="no">.bak</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>Iterating over a list of numbers can be done with <code class="docutils literal notranslate"><span class="pre">seq</span></code>:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">for</span><span class="w"> </span><span class="no">x</span><span class="w"> </span><span class="nf">in</span><span class="w"> </span><span class="o">(</span><span class="nf">seq</span><span class="w"> </span><span class="no">5</span><span class="o">)</span>
<span class="w">    </span><span class="nf">touch</span><span class="w"> </span><span class="no">file_</span><span class="o">$x</span><span class="no">.txt</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>For more, see <a class="reference internal" href="language.html#syntax-loops-and-blocks"><span class="std std-ref">Loops and blocks</span></a>.</p>
</section>
<section id="prompt">
<h2>Prompt<a class="headerlink" href="#prompt" title="Link to this heading">¶</a></h2>
<p>Unlike other shells, there is no prompt variable like <code class="docutils literal notranslate"><span class="pre">PS1</span></code>. To display your prompt, fish executes the <a class="reference internal" href="cmds/fish_prompt.html"><span class="doc">fish_prompt</span></a> function and uses its output as the prompt. And if it exists, fish also executes the <a class="reference internal" href="cmds/fish_right_prompt.html"><span class="doc">fish_right_prompt</span></a> function and uses its output as the right prompt.</p>
<p>You can define your own prompt from the command line:</p>
<div class="highlight highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">function</span><span class="w"> </span><span class="no">fish_prompt</span><span class="p">;</span><span class="w"> </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;New Prompt % &quot;</span><span class="p">;</span><span class="w"> </span><span class="nf">end</span>
<span class="go">New Prompt % _</span>
</pre></div>
</div>
<p>Then, if you are happy with it, you can save it to disk by typing <code class="docutils literal notranslate"><span class="pre">funcsave</span> <span class="pre">fish_prompt</span></code>. This saves the prompt in <code class="docutils literal notranslate"><span class="pre">~/.config/fish/functions/fish_prompt.fish</span></code>. (Or, if you want, you can create that file manually from the start.)</p>
<p>Multiple lines are OK. Colors can be set via <a class="reference internal" href="cmds/set_color.html"><span class="doc">set_color</span></a> by passing it named ANSI colors, or hex RGB values:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">function</span><span class="w"> </span><span class="no">fish_prompt</span>
<span class="w">    </span><span class="nf">set_color</span><span class="w"> </span><span class="no">purple</span>
<span class="w">    </span><span class="nf">date</span><span class="w"> </span><span class="s2">&quot;+%m/%d/%y&quot;</span>
<span class="w">    </span><span class="nf">set_color</span><span class="w"> </span><span class="no">FF0000</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="o">(</span><span class="nf">pwd</span><span class="o">)</span><span class="w"> </span><span class="s1">&#39;&gt;&#39;</span><span class="w"> </span><span class="o">(</span><span class="nf">set_color</span><span class="w"> </span><span class="no">normal</span><span class="o">)</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>This prompt would look like:</p>
<pre class="highlight literal-block"><span class="purple">02/06/13</span>
<span class="red">/home/tutorial &gt;</span> _</pre>
<p>See also <a class="reference internal" href="prompt.html"><span class="doc">Writing your own prompt</span></a>.</p>
<p>You can choose among sample prompts by running <code class="docutils literal notranslate"><span class="pre">fish_config</span></code> for a web UI or <code class="docutils literal notranslate"><span class="pre">fish_config</span> <span class="pre">prompt</span></code> for a simpler version inside your terminal.</p>
</section>
<section id="path">
<h2>$PATH<a class="headerlink" href="#path" title="Link to this heading">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">$PATH</span></code> is an environment variable containing the directories that fish searches for commands. Unlike other shells, $PATH is a <a class="reference internal" href="#tut-lists"><span class="std std-ref">list</span></a>, not a colon-delimited string.</p>
<p>Fish takes care to set <code class="docutils literal notranslate"><span class="pre">$PATH</span></code> to a default, but typically it is just inherited from fish’s parent process and is set to a value that makes sense for the system - see <a class="reference internal" href="#tut-exports"><span class="std std-ref">Exports</span></a>.</p>
<p>To prepend /usr/local/bin and /usr/sbin to <code class="docutils literal notranslate"><span class="pre">$PATH</span></code>, you can write:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">PATH</span><span class="w"> </span><span class="no">/usr/local/bin</span><span class="w"> </span><span class="no">/usr/sbin</span><span class="w"> </span><span class="o">$PATH</span>
</pre></div>
</div>
<p>To remove /usr/local/bin from <code class="docutils literal notranslate"><span class="pre">$PATH</span></code>, you can write:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">PATH</span><span class="w"> </span><span class="o">(</span><span class="nf">string</span><span class="w"> </span><span class="no">match</span><span class="w"> </span><span class="no">-v</span><span class="w"> </span><span class="no">/usr/local/bin</span><span class="w"> </span><span class="o">$PATH)</span>
</pre></div>
</div>
<p>For compatibility with other shells and external commands, $PATH is a <a class="reference internal" href="language.html#variables-path"><span class="std std-ref">path variable</span></a>, and so will be joined with colons (not spaces) when you quote it:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;</span><span class="o">$PATH</span><span class="s2">&quot;</span>
<span class="go">/usr/local/sbin:/usr/local/bin:/usr/bin</span>
</pre></div>
</div>
<p>and it will be exported like that, and when fish starts it splits the $PATH it receives into a list on colon.</p>
<p>You can do so directly in <code class="docutils literal notranslate"><span class="pre">config.fish</span></code>, like you might do in other shells with <code class="docutils literal notranslate"><span class="pre">.profile</span></code>. See <a class="reference internal" href="#path-example"><span class="std std-ref">this example</span></a>.</p>
<p>A faster way is to use the <a class="reference internal" href="cmds/fish_add_path.html"><span class="doc">fish_add_path</span></a> function, which adds given directories to the path if they aren’t already included. It does this by modifying the <code class="docutils literal notranslate"><span class="pre">$fish_user_paths</span></code> <a class="reference internal" href="#tut-universal"><span class="std std-ref">universal variable</span></a>, which is automatically prepended to <code class="docutils literal notranslate"><span class="pre">$PATH</span></code>. For example, to permanently add <code class="docutils literal notranslate"><span class="pre">/usr/local/bin</span></code> to your <code class="docutils literal notranslate"><span class="pre">$PATH</span></code>, you could write:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">fish_add_path</span><span class="w"> </span><span class="no">/usr/local/bin</span>
</pre></div>
</div>
<p>The advantage is that you don’t have to go mucking around in files: just run this once at the command line, and it will affect the current session and all future instances too. You can also add this line to <a class="reference internal" href="#tut-config"><span class="std std-ref">config.fish</span></a>, as it only adds the component if necessary.</p>
<p>Or you can modify $fish_user_paths yourself, but you should be careful <em>not</em> to append to it unconditionally in config.fish, or it will grow longer and longer.</p>
</section>
<section id="startup-where-s-bashrc">
<span id="tut-config"></span><h2>Startup (Where’s .bashrc?)<a class="headerlink" href="#startup-where-s-bashrc" title="Link to this heading">¶</a></h2>
<p>Fish starts by executing commands in <code class="docutils literal notranslate"><span class="pre">~/.config/fish/config.fish</span></code>. You can create it if it does not exist.</p>
<p>It is possible to directly create functions and variables in <code class="docutils literal notranslate"><span class="pre">config.fish</span></code> file, using the commands shown above. For example:</p>
<div class="highlight-fish-docs-samples notranslate" id="path-example"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">cat</span><span class="w"> </span><span class="o">~</span><span class="no">/.config/fish/config.fish</span>

<span class="go">set -x PATH $PATH /sbin/</span>

<span class="go">function ll</span>
<span class="go">    ls -lh $argv</span>
<span class="go">end</span>
</pre></div>
</div>
<p>However, it is more common and efficient to use  autoloading functions and universal variables.</p>
<p>If you want to organize your configuration, fish also reads commands in .fish files in <code class="docutils literal notranslate"><span class="pre">~/.config/fish/conf.d/</span></code>. See <a class="reference internal" href="language.html#configuration"><span class="std std-ref">Configuration Files</span></a> for the details.</p>
</section>
<section id="autoloading-functions">
<h2>Autoloading Functions<a class="headerlink" href="#autoloading-functions" title="Link to this heading">¶</a></h2>
<p>When fish encounters a command, it attempts to autoload a function for that command, by looking for a file with the name of that command in <code class="docutils literal notranslate"><span class="pre">~/.config/fish/functions/</span></code>.</p>
<p>For example, if you wanted to have a function <code class="docutils literal notranslate"><span class="pre">ll</span></code>, you would add a text file <code class="docutils literal notranslate"><span class="pre">ll.fish</span></code> to <code class="docutils literal notranslate"><span class="pre">~/.config/fish/functions</span></code>:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">cat</span><span class="w"> </span><span class="o">~</span><span class="no">/.config/fish/functions/ll.fish</span>
<span class="go">function ll</span>
<span class="go">    ls -lh $argv</span>
<span class="go">end</span>
</pre></div>
</div>
<p>This is the preferred way to define your prompt as well:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">cat</span><span class="w"> </span><span class="o">~</span><span class="no">/.config/fish/functions/fish_prompt.fish</span>
<span class="go">function fish_prompt</span>
<span class="go">    echo (pwd) &quot;&gt; &quot;</span>
<span class="go">end</span>
</pre></div>
</div>
<p>See the documentation for <a class="reference internal" href="cmds/funced.html"><span class="doc">funced</span></a> and <a class="reference internal" href="cmds/funcsave.html"><span class="doc">funcsave</span></a> for ways to create these files automatically, and <a class="reference internal" href="language.html#syntax-function-autoloading"><span class="std std-ref">$fish_function_path</span></a> to control their location.</p>
</section>
<section id="universal-variables">
<span id="tut-universal"></span><h2>Universal Variables<a class="headerlink" href="#universal-variables" title="Link to this heading">¶</a></h2>
<p>A universal variable is a variable whose value is shared across all instances of fish, now and in the future – even after a reboot. You can make a variable universal with <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">-U</span></code>:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">-U</span><span class="w"> </span><span class="no">EDITOR</span><span class="w"> </span><span class="no">vim</span>
</pre></div>
</div>
<p>Now in another shell:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">echo</span><span class="w"> </span><span class="o">$EDITOR</span>
<span class="go">vim</span>
</pre></div>
</div>
<p>You only need to set universal variables once interactively. There is no need to add them to your <a class="reference internal" href="language.html#configuration"><span class="std std-ref">config files</span></a>. For more details, see <a class="reference internal" href="language.html#variables-universal"><span class="std std-ref">Universal Variables</span></a>.</p>
</section>
<section id="ready-for-more">
<h2>Ready for more?<a class="headerlink" href="#ready-for-more" title="Link to this heading">¶</a></h2>
<p>If you want to learn more about fish, there is <a class="reference internal" href="index.html#intro"><span class="std std-ref">lots of detailed documentation</span></a>, the <a class="reference external" href="https://gitter.im/fish-shell/fish-shell">official gitter channel</a>, an <a class="reference external" href="https://lists.sourceforge.net/lists/listinfo/fish-users">official mailing list</a>, and the <a class="reference external" href="https://github.com/fish-shell/fish-shell/">github page</a>.</p>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div> 
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
    <li><img src="_static/fish.png" alt=""
             style="width: 80px; height: 80px; vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="https://fishshell.com/">fish-shell</a> &#187;</li>
    
    <a href="index.html">fish-shell 4.2.1 documentation</a> &#187;
    

        <li class="nav-item nav-item-this"><a href="">Tutorial</a></li>
    <li class="right">
        

    <div class="inline-search" role="search">
        <form class="inline-search" action="search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    </li>
    
    <div id="old-docs-notice" style="display: none">
        This documents an old version of fish.
        <a href="../current/">See the latest release.</a>
    </div>

      </ul>
    </div>  
    <div class="footer">
    &copy; Copyright fish-shell developers.
    <br />
    <a href="https://github.com/fish-shell/fish-shell/issues">Found a bug</a>?
    <br />

    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
    </div>
</div>

<script type="text/javascript">
 FISH_DOCS_VERSION = "4.2";

 function copy_to_clipboard(it) {
     // Find the pre tag we're interested in.
     var pre = it.target;
     while (pre.tagName != "PRE") pre = pre.parentNode;
     var txt = "";
     // Cheesy: If we have a prompt,
     // we only copy prompted lines,
     // by splitting and matching and stuff
     if (pre.querySelector('span.gp')) {
         var texts= [];
         for (var line of pre.innerText.split('\n')) {
             if (line.match(/^>_?.*/)) {
                 texts.push(line.replace(/^>_?/, ""));
             }
         }
         txt = texts.join("\n");
     } else {
         // Even cheesier: If we don't have a prompt, we remove the button text from the end.
         var txt = pre.innerText.substring(0, pre.innerText.length - it.target.innerText.length).trim();
     }

     navigator.clipboard.writeText(txt).then(function() {
         // Success - set the text to indicate it,
         // then set it back after 2 seconds.
         var span = pre.querySelector("button span");
         if (span) {
             var oldText = span.innerText;
             span.innerText = "COPIED!";
             setTimeout(function() {
                 span.innerText = oldText;
             }, 2000);
         }
     }, function() {
     });
 }

  (function () {
      // Add copy buttons to all the codeblocks.
      var codeblocks = document.querySelectorAll('div > pre');

      var button = document.createElement('button');
      var span = document.createElement('span');
      span.innerText = "COPY";
      button.appendChild(span);

      for (var i of codeblocks) {
          var newButton = button.cloneNode(true);
          newButton.addEventListener('click', copy_to_clipboard);
          i.appendChild(newButton);
      }
  })();
</script>

  </body>
</html>