SET(1)

🌸 SET(1) β€” the fish-shell glow-up guide to set 🌸

okay bestie, sit down, hydrate, and let me tell you about set β€” the fish-shell command that displays and changes shell variables. she's the main character of your shell config, no cap πŸ’…


✨ NAME ✨

set β€” display and change shell variables 🫢


πŸŽ€ SYNOPSIS πŸŽ€

set [(-f | --function) (-l | --local) (-g | --global) (-U | --universal)]
    [(-x | --export) (-u | --unexport)]
set (-S | --show) (-L | --long) [NAME ...]

set [-Uflg] [-xu] [--no-event] NAME [VALUE ...]
set [-Uflg] [--no-event] NAME[[INDEX ...]] [VALUE ...]
set (-a | --append) (-p | --prepend) [-Uflg] [--no-event] NAME VALUE ...
set (-e | --erase) [-Uflg] [--no-event] NAME[[INDEX]] ...

set (-q | --query) [-Uflg] [-xu] NAME[[INDEX]] ...

like, look at her. so many forms. she contains multitudes πŸ’–


πŸ’œ DESCRIPTION πŸ’œ

set manipulates shell variables (that's the #variables section, iykyk).

If you give her both NAME and VALUE, set assigns those values to the variable NAME. Variables in fish are lists (the #variables-lists part) β€” multiple values are allowed, and that's iconic, not a bug. You can also name one or more variable INDEX values, ranges included (but not for every option, so pay attention πŸ‘€).

If you give no VALUE, the variable gets set to the empty list. empty. blank. a void. she said "clear her schedule" ✨

If you run set with no arguments at all, it prints the names and values of all shell variables in sorted order. Passing scope (see #variables-scope) or export (see #variables-export) flags filters it down to only the matching ones β€” so set --local would only show local variables. vibe check: filtered. πŸ¦‹

With --erase and optionally a scope flag, set erases the matching variable (or the variable of that name in the smallest possible scope).

With --show, set describes the variable names you gave her β€” explaining exactly how they've been defined: which scope, which values, which options. she's giving full backstory πŸ’…

The following options control variable scope:

  • -U, --universal β€” sets a universal variable. It's immediately available to all the user's fish instances on the machine, and it's persisted across restarts of the shell. she's forever, bestie πŸ‘‘
  • -f, --function β€” sets a variable scoped to the executing function. It gets erased when the function ends. gone by the time you look up 😭
  • -l, --local β€” sets a locally-scoped variable in this block. Erased when the block ends. Outside of a block, this is the same as --function.
  • -g, --global β€” sets a globally-scoped variable. Global variables are available to all functions running in the same shell, and they can be modified or erased.

These options modify how variables operate:

  • --export, -x β€” causes the specified shell variable to be exported to child processes (making it an "environment variable"). she's leaving the house πŸš—
  • --unexport, -u β€” causes the specified shell variable to NOT be exported to child processes.
  • --path β€” treats the specified variable as a path variable (see #variables-path); the variable will be split on colons (:) and will be displayed joined by colons when quoted (echo "$PATH") or exported. πŸ›£οΈ
  • --unpath β€” causes the variable to no longer be treated as a path variable (see #variables-path). Note: variables ending in "PATH" are automatically path variables. she was born a path variable, she can be un-born πŸ’€

Further options:

  • -a, --append NAME VALUE ... β€” appends VALUES to the current set of values for variable NAME. Can be used with --prepend to both append and prepend at the same time. This cannot be used when assigning to a variable slice. (both ends at once? she's flexible πŸŽ€)
  • -p, --prepend NAME VALUE ... β€” prepends VALUES to the current set of values for variable NAME. This can be used with --append to both append and prepend at the same time. This cannot be used when assigning to a variable slice.
  • -e, --erase NAME[INDEX] β€” causes the specified shell variables to be erased. Supports erasing from multiple scopes at once. Individual items in a variable at INDEX in brackets can be specified. 🧹
  • -q, --query NAME[INDEX] β€” tests if the specified variable names are defined. If an INDEX is provided, checks for items at that slot. With a given scope (like --global) or attribute (like --export or --path), it checks only variables that match. 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. silent but deadly πŸ«₯
  • -n, --names β€” lists only the names of all defined variables, not their value. The names are guaranteed to be sorted. alphabetically flawless ✨
  • -S, --show β€” 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's exported. No other flags can be used with this option. she's exclusive 🚫
  • --no-event β€” doesn'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. > ⚠️ careful bestie, this one's lowkey spicy β€” the original docs literally say "we recommend using this carefully" so I'm passing that along word for word.
  • -L, --long β€” does not abbreviate long values when printing set variables. full send, no truncation πŸ“
  • -h, --help β€” displays help about using this command.

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. math is math πŸ’œ

If the variable name is one or more list elements, such as PATH[1 3 7], 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. backwards but make it fashion πŸ’…

The scoping rules when creating or updating a variable are:

  • 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. different scope, different girl, don't touch her πŸ™…
  • If the scope of a variable is not explicitly set but a variable by that name has been previously defined, 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. smallest scope wins, periodt πŸ‘‘
  • 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 -l or --local 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. subtle but crucial, don't mix these up fr fr

The exporting rules when creating or updating a variable are identical to the scoping rules for variables:

  • Variables may be explicitly set to either exported or not exported. When an exported variable goes out of scope, it is unexported.
  • 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.
  • 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.

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. πŸ•΅οΈβ€β™€οΈ

In erase mode, if variable indices are specified, only the specified slices of the list variable will be erased.

🚨 big one, bestie: set requires all options to come before any other arguments. For example, set flags -l will have the effect of setting the value of the variable flags to '-l', not making the variable local. she is not reading your mind, she's reading left to right 😭

πŸ”₯ EXIT STATUS πŸ”₯

In assignment mode, set does not modify the exit status, but passes along whatever status (see #envvar-status) was set, including by command substitutions. This allows capturing the output and exit status of a subcommand, like in if set output (command). she's a pass-through queen πŸ’…

In query mode, the exit status is the number of variables that were not found.

In erase mode, set 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 special read-only variable (see #variables-special). πŸ’€ read-only means read-only, don't fight her


🌈 EXAMPLES 🌈

Print all global, exported variables:

> set -gx

Set the value of the variable $foo to be 'hi'.:

> set foo hi

Append the value "there" to the variable $foo:

> set -a foo there

Remove $smurf from the scope:

> set -e smurf

Remove $smurf from the global and universal scopes:

> set -e -Ug smurf

Change the fourth element of the $PATH list to ~/bin:

> set PATH[4] ~/bin

Outputs the path to Python if type -p returns true:

if set python_path (type -p python)
    echo "Python is at $python_path"
end

Setting a variable doesn't modify $status; a command substitution still will, though:

> echo $status
0
> false
> set foo bar
> echo $status
1
> true
> set foo banana (false)
> echo $status
1

VAR=VALUE command sets a variable for just one command, like other shells. This runs fish with a temporary home directory:

> HOME=(mktemp -d) fish

(which is essentially the same as):

> begin; set -lx HOME (mktemp -d); fish; end

πŸ¦‹ NOTES πŸ¦‹

  • fish versions prior to 3.0 supported the syntax set PATH[1] PATH[4] /bin /sbin, which worked like set PATH[1 4] /bin /sbin. ancient lore, but now you know it 🧚

fish-shell developers πŸ’–


and that's the whole page, bestie β€” she ate, no crumbs. this was SET(1) from the fish-shell manual, version 4.9, dated Sep 08, 2026, brought to you by the fish-shell developers (copyright and all 🌸). now go set some variables, you absolute icon ⭐

πŸ“¦ where this page comes from
  • arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms