File: set.html

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (403 lines) | stat: -rw-r--r-- 31,495 bytes parent folder | download | duplicates (2)
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
<!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>set - display and change shell variables &#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="set_color - set the terminal color" href="set_color.html" />
    <link rel="prev" title="return - stop the current inner function" href="return.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-1"><a href="../commands.html" accesskey="U">Commands</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">set - display and change shell variables</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 current"><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"><a class="reference internal" href="../tutorial.html">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="#">set - display and change shell variables</a><ul>
<li><a class="reference internal" href="#synopsis">Synopsis</a></li>
<li><a class="reference internal" href="#description">Description</a></li>
<li><a class="reference internal" href="#exit-status">Exit status</a></li>
<li><a class="reference internal" href="#examples">Examples</a></li>
<li><a class="reference internal" href="#notes">Notes</a></li>
</ul>
</li>
</ul>

</div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="set-display-and-change-shell-variables">
<h1>set - display and change shell variables<a class="headerlink" href="#set-display-and-change-shell-variables" title="Link to this heading">¶</a></h1>
<section id="synopsis">
<h2>Synopsis<a class="headerlink" href="#synopsis" title="Link to this heading">¶</a></h2>
<div class="highlight-fish-synopsis notranslate"><div class="highlight"><pre><span></span><span class="nf">set</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-f</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--function</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-l</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--local</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-g</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--global</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-U</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--universal</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">--no-event</span><span class="g g-Other">]</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">-Uflg</span><span class="g g-Other">]</span><span class="w"> </span><span class="no">NAME</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">VALUE</span><span class="w"> </span><span class="g g-Other">...]</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">-Uflg</span><span class="g g-Other">]</span><span class="w"> </span><span class="no">NAME</span><span class="g g-Other">[[</span><span class="no">INDEX</span><span class="w"> </span><span class="g g-Other">...]]</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">VALUE</span><span class="w"> </span><span class="g g-Other">...]</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-x</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--export</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-u</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--unexport</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">-Uflg</span><span class="g g-Other">]</span><span class="w"> </span><span class="no">NAME</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">VALUE</span><span class="w"> </span><span class="g g-Other">...]</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-a</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--append</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-p</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--prepend</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">-Uflg</span><span class="g g-Other">]</span><span class="w"> </span><span class="no">NAME</span><span class="w"> </span><span class="no">VALUE</span><span class="w"> </span><span class="g g-Other">...</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-q</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--query</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-e</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--erase</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">-Uflg</span><span class="g g-Other">]</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">NAME</span><span class="g g-Other">][[</span><span class="no">INDEX</span><span class="g g-Other">]]</span><span class="w"> </span><span class="g g-Other">...]</span>
<span class="nf">set</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-S</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--show</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">(</span><span class="no">-L</span><span class="w"> </span><span class="g g-Other">|</span><span class="w"> </span><span class="no">--long</span><span class="g g-Other">)</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">NAME</span><span class="w"> </span><span class="g g-Other">...]</span>
</pre></div>
</div>
</section>
<section id="description">
<h2>Description<a class="headerlink" href="#description" title="Link to this heading">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">set</span></code> manipulates <a class="reference internal" href="../language.html#variables"><span class="std std-ref">shell variables</span></a>.</p>
<p>If both <em>NAME</em> and <em>VALUE</em> are provided, <code class="docutils literal notranslate"><span class="pre">set</span></code> assigns any values to variable <em>NAME</em>.
Variables in fish are <a class="reference internal" href="../language.html#variables-lists"><span class="std std-ref">lists</span></a>, multiple values are allowed.
One or more variable <em>INDEX</em> can be specified including ranges (not for all options.)</p>
<p>If no <em>VALUE</em> is given, the variable will be set to the empty list.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">set</span></code> is ran without arguments, it prints the names and values of all shell variables in sorted order.
Passing <a class="reference internal" href="../language.html#variables-scope"><span class="std std-ref">scope</span></a> or <a class="reference internal" href="../language.html#variables-export"><span class="std std-ref">export</span></a> flags allows filtering this to only matching variables, so <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">--local</span></code> would only show local variables.</p>
<p>With <code class="docutils literal notranslate"><span class="pre">--erase</span></code> and optionally a scope flag <code class="docutils literal notranslate"><span class="pre">set</span></code> will erase the matching variable (or the variable of that name in the smallest possible scope).</p>
<p>With <code class="docutils literal notranslate"><span class="pre">--show</span></code>, <code class="docutils literal notranslate"><span class="pre">set</span></code> will describe the given variable names, explaining how they have been defined - in which scope with which values and options.</p>
<p>The following options control variable scope:</p>
<dl class="simple">
<dt><strong>-U</strong> or <strong>--universal</strong></dt><dd><p>Sets a universal variable.
The variable will be immediately available to all the user’s <code class="docutils literal notranslate"><span class="pre">fish</span></code> instances on the machine, and will be persisted across restarts of the shell.</p>
</dd>
<dt><strong>-f</strong> or <strong>--function</strong></dt><dd><p>Sets a variable scoped to the executing function.
It is erased when the function ends.</p>
</dd>
<dt><strong>-l</strong> or <strong>--local</strong></dt><dd><p>Sets a locally-scoped variable in this block.
It is erased when the block ends.
Outside of a block, this is the same as <strong>--function</strong>.</p>
</dd>
<dt><strong>-g</strong> or <strong>--global</strong></dt><dd><p>Sets a globally-scoped variable.
Global variables are available to all functions running in the same shell.
They can be modified or erased.</p>
</dd>
</dl>
<p>These options modify how variables operate:</p>
<dl class="simple">
<dt><strong>--export</strong> or <strong>-x</strong></dt><dd><p>Causes the specified shell variable to be exported to child processes (making it an “environment variable”).</p>
</dd>
<dt><strong>--unexport</strong> or <strong>-u</strong></dt><dd><p>Causes the specified shell variable to NOT be exported to child processes.</p>
</dd>
<dt><strong>--path</strong></dt><dd><p>Treat specified variable as a <a class="reference internal" href="../language.html#variables-path"><span class="std std-ref">path variable</span></a>; variable will be split on colons (<code class="docutils literal notranslate"><span class="pre">:</span></code>) and will be displayed joined by colons when quoted (<code class="docutils literal notranslate"><span class="pre">echo</span> <span class="pre">&quot;$PATH&quot;</span></code>) or exported.</p>
</dd>
<dt><strong>--unpath</strong></dt><dd><p>Causes variable to no longer be treated as a <a class="reference internal" href="../language.html#variables-path"><span class="std std-ref">path variable</span></a>.
Note: variables ending in “PATH” are automatically path variables.</p>
</dd>
</dl>
<p>Further options:</p>
<dl class="simple">
<dt><strong>-a</strong> or <strong>--append</strong> <em>NAME</em> <em>VALUE</em> …</dt><dd><p>Appends <em>VALUES</em> to the current set of values for variable <strong>NAME</strong>.
Can be used with <strong>--prepend</strong> to both append and prepend at the same time.
This cannot be used when assigning to a variable slice.</p>
</dd>
<dt><strong>-p</strong> or <strong>--prepend</strong> <em>NAME</em> <em>VALUE</em> …</dt><dd><p>Prepends <em>VALUES</em> to the current set of values for variable <strong>NAME</strong>.
This can be used with <strong>--append</strong> to both append and prepend at the same time.
This cannot be used when assigning to a variable slice.</p>
</dd>
<dt><strong>-e</strong> or <strong>--erase</strong> <em>NAME</em>[<em>INDEX</em>]</dt><dd><p>Causes the specified shell variables to be erased.
Supports erasing from multiple scopes at once.
Individual items in a variable at <em>INDEX</em> in brackets can be specified.</p>
</dd>
<dt><strong>-q</strong> or <strong>--query</strong> <em>NAME</em>[<em>INDEX</em>]</dt><dd><p>Test if the specified variable names are defined.
If an <em>INDEX</em> is provided, check for items at that slot.
Does not output anything, but the shell status is set to the number of variables specified that were not defined, up to a maximum of 255.
If no variable was given, it also returns 255.</p>
</dd>
<dt><strong>-n</strong> or <strong>--names</strong></dt><dd><p>List only the names of all defined variables, not their value.
The names are guaranteed to be sorted.</p>
</dd>
<dt><strong>-S</strong> or <strong>--show</strong></dt><dd><p>Shows information about the given variables.
If no variable names are given then all variables are shown in sorted order.
It shows the scopes the given variables are set in, along with the values in each and whether or not it is exported.
No other flags can be used with this option.</p>
</dd>
<dt><strong>--no-event</strong></dt><dd><p>Don’t generate a variable change event when setting or erasing a variable.
We recommend using this carefully because the event handlers are usually set up for a reason.
Possible uses include modifying the variable inside a variable handler.</p>
</dd>
<dt><strong>-L</strong> or <strong>--long</strong></dt><dd><p>Do not abbreviate long values when printing set variables.</p>
</dd>
<dt><strong>-h</strong> or <strong>--help</strong></dt><dd><p>Displays help about using this command.</p>
</dd>
</dl>
<p>If a variable is set to more than one value, the variable will be a list with the specified elements.
If a variable is set to zero elements, it will become a list with zero elements.</p>
<p>If the variable name is one or more list elements, such as <code class="docutils literal notranslate"><span class="pre">PATH[1</span> <span class="pre">3</span> <span class="pre">7]</span></code>, only those list elements specified will be changed.
If you specify a negative index when expanding or assigning to a list variable, the index will be calculated from the end of the list.
For example, the index -1 means the last index of a list.</p>
<p>The scoping rules when creating or updating a variable are:</p>
<ul class="simple">
<li><p>Variables may be explicitly set as universal, global, function, or local.
Variables with the same name but in a different scope will not be changed.</p></li>
<li><p>If the scope of a variable is not explicitly set <em>but a variable by that name has been previously defined</em>, the scope of the existing variable is used.
If the variable is already defined in multiple scopes, the variable with the narrowest scope will be updated.</p></li>
<li><p>If a variable’s scope is not explicitly set and there is no existing variable by that name, the variable will be local to the currently executing function.
Note that this is different from using the <code class="docutils literal notranslate"><span class="pre">-l</span></code> or <code class="docutils literal notranslate"><span class="pre">--local</span></code> flag, in which case the variable will be local to the most-inner currently executing block, while without them the variable will be local to the function as a whole.
If no function is executing, the variable will be set in the global scope.</p></li>
</ul>
<p>The exporting rules when creating or updating a variable are identical to the scoping rules for variables:</p>
<ul class="simple">
<li><p>Variables may be explicitly set to either exported or not exported.
When an exported variable goes out of scope, it is unexported.</p></li>
<li><p>If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept.</p></li>
<li><p>If a variable is not explicitly set to be either exported or unexported and has never before been defined, the variable will not be exported.</p></li>
</ul>
<p>In query mode, the scope to be examined can be specified.
Whether the variable has to be a path variable or exported can also be specified.</p>
<p>In erase mode, if variable indices are specified, only the specified slices of the list variable will be erased.</p>
<p><code class="docutils literal notranslate"><span class="pre">set</span></code> requires all options to come before any other arguments.
For example, <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">flags</span> <span class="pre">-l</span></code> will have the effect of setting the value of the variable <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">flags</span></code> to ‘-l’, not making the variable local.</p>
</section>
<section id="exit-status">
<h2>Exit status<a class="headerlink" href="#exit-status" title="Link to this heading">¶</a></h2>
<p>In assignment mode, <code class="docutils literal notranslate"><span class="pre">set</span></code> does not modify the exit status, but passes along whatever <span class="target" id="index-1"></span><a class="reference internal" href="../language.html#envvar-status"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">status</span></code></a> was set, including by command substitutions.
This allows capturing the output and exit status of a subcommand, like in <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">set</span> <span class="pre">output</span> <span class="pre">(command)</span></code>.</p>
<p>In query mode, the exit status is the number of variables that were not found.</p>
<p>In erase mode, <code class="docutils literal notranslate"><span class="pre">set</span></code> exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if any of the variables did not exist or was a <a class="reference internal" href="../language.html#variables-special"><span class="std std-ref">special read-only variable</span></a>.</p>
</section>
<section id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
<p>Print all global, exported variables:</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">-gx</span>
</pre></div>
</div>
<p>Set the value of the variable _$foo_ to be ‘hi’.:</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">foo</span><span class="w"> </span><span class="no">hi</span>
</pre></div>
</div>
<p>Append the value “there” to the variable $foo:</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">-a</span><span class="w"> </span><span class="no">foo</span><span class="w"> </span><span class="no">there</span>
</pre></div>
</div>
<p>Remove _$smurf_ from the scope:</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">smurf</span>
</pre></div>
</div>
<p>Remove _$smurf_ from the global and universal scopes:</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">-Ug</span><span class="w"> </span><span class="no">smurf</span>
</pre></div>
</div>
<p>Change the fourth element of the $PATH list to ~/bin:</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[4]</span><span class="w"> </span><span class="o">~</span><span class="no">/bin</span>
</pre></div>
</div>
<p>Outputs the path to Python if <code class="docutils literal notranslate"><span class="pre">type</span> <span class="pre">-p</span></code> returns true:</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">set</span><span class="w"> </span><span class="no">python_path</span><span class="w"> </span><span class="o">(</span><span class="nf">type</span><span class="w"> </span><span class="no">-p</span><span class="w"> </span><span class="no">python</span><span class="o">)</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="s2">&quot;Python is at </span><span class="o">$python_path</span><span class="s2">&quot;</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>Setting a variable doesn’t modify $status; a command substitution still will, though:</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">$status</span>
<span class="go">0</span>
<span class="gp">&gt; </span><span class="nf">false</span>
<span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">foo</span><span class="w"> </span><span class="no">bar</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>
<span class="gp">&gt; </span><span class="nf">true</span>
<span class="gp">&gt; </span><span class="nf">set</span><span class="w"> </span><span class="no">foo</span><span class="w"> </span><span class="no">banana</span><span class="w"> </span><span class="o">(</span><span class="nf">false</span><span class="o">)</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><code class="docutils literal notranslate"><span class="pre">VAR=VALUE</span> <span class="pre">command</span></code> sets a variable for just one command, like other shells.
This runs fish with a temporary home directory:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="no">HOME</span><span class="o">=(</span><span class="nf">mktemp</span><span class="w"> </span><span class="no">-d</span><span class="o">)</span><span class="w"> </span><span class="nf">fish</span>
</pre></div>
</div>
<p>(which is essentially the same as):</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">begin</span><span class="p">;</span><span class="w"> </span><span class="nf">set</span><span class="w"> </span><span class="no">-lx</span><span class="w"> </span><span class="no">HOME</span><span class="w"> </span><span class="o">(</span><span class="nf">mktemp</span><span class="w"> </span><span class="no">-d</span><span class="o">)</span><span class="p">;</span><span class="w"> </span><span class="nf">fish</span><span class="p">;</span><span class="w"> </span><span class="nf">end</span>
</pre></div>
</div>
</section>
<section id="notes">
<h2>Notes<a class="headerlink" href="#notes" title="Link to this heading">¶</a></h2>
<ul class="simple">
<li><p>Fish versions prior to 3.0 supported the syntax <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">PATH[1]</span> <span class="pre">PATH[4]</span> <span class="pre">/bin</span> <span class="pre">/sbin</span></code>, which worked like <code class="docutils literal notranslate"><span class="pre">set</span> <span class="pre">PATH[1</span> <span class="pre">4]</span> <span class="pre">/bin</span> <span class="pre">/sbin</span></code>.</p></li>
</ul>
</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-1"><a href="../commands.html" >Commands</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">set - display and change shell variables</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>