Skip to content
shellmap

setToggle shell options like errexit/xtrace and set positional parameters across all 5 shells

Equivalents in every shell

Bashunix
set -euo pipefail

Bash builtin. With no args, `set` lists all shell variables. With `-` flags, toggles options. With positional args, assigns `$1`, `$2`, …. Variable assignment is `var=value`, NOT `set var value`.

Zshunix
set -euo pipefail

Bash-compatible. Zsh also offers named option syntax via `setopt`/`unsetopt` (`setopt err_exit` ≡ `set -e`), which is more readable in long scripts.

Fishunix
set -gx PATH /opt/bin $PATH

CRITICAL DIFFERENCE: in fish, `set` is *variable assignment*. `set name value` creates a variable. There is no `set -e` for errexit — fish has no global errexit option; check `$status` per command.

PowerShellwindows
Set-StrictMode -Version Latest

No `set -e` global; closest is `$ErrorActionPreference = "Stop"`. `Set-Variable name value` is variable assignment; `Set-PSDebug -Trace 1` is the `set -x` equivalent.

cmd.exewindows
set VAR=value

Cmd `set` is variable assignment (`set VAR=value`) and listing (`set` with no args). No shell options. Spaces around `=` are taken literally — `set VAR = value` makes a variable literally named `VAR ` with value ` value`.

Worked examples

Enable strict error handling at the top of a script

Bash
set -euo pipefail
Zsh
set -euo pipefail
PowerShell
$ErrorActionPreference = "Stop"; Set-StrictMode -Version Latest

Trace each command before it runs (debugging)

Bash
set -x
Zsh
set -x
Fish
fish -x script.fish
PowerShell
Set-PSDebug -Trace 1

Set an environment variable for child processes

Bash
export FOO=bar
Fish
set -gx FOO bar
PowerShell
$env:FOO = "bar"
cmd.exe
set FOO=bar

Gotchas

  • Fish's `set` is the #1 porting footgun from bash. `set -x foo` in bash enables xtrace and ignores `foo`; in fish it EXPORTS a variable named `foo` with no value. Always check the shell before pasting `set` lines.
  • `set -e` (errexit) is famously leaky in bash: it does not trigger inside subshells in command substitution, inside functions called via `&&`/`||`, or for the last command of a pipe (without `pipefail`). Treat it as a hint, not a guarantee.
  • `set -- arg1 arg2` resets the positional parameters `$1`/`$2`/… — useful for re-parsing args. `set -- $(cmd)` is the bash idiom for splitting command output on IFS.
  • Cmd's `set VAR=value` does not trim whitespace: `set VAR =hi` creates `VAR ` (with trailing space). Always write `set VAR=value` with no spaces around `=`, or use `set "VAR=value"` to be explicit.
  • PowerShell has both `Set-Variable` (shell-only) and `$env:VAR = ...` (process environment, inherited by children). `set` in PowerShell is an *alias* for `Set-Variable`, NOT bash-style options — `set -e` errors out as an unknown parameter.

WSL & PowerShell Core notes

pwshPowerShell Core has no errexit. The portable pattern is `$ErrorActionPreference = "Stop"` at script top (treats every cmdlet error as terminating), plus explicit `if ($LASTEXITCODE -ne 0) { throw }` after every external-command call (since `$ErrorActionPreference` did not apply to non-zero exit codes from native binaries before PowerShell 7.3).
WSLInside WSL `set` is the bash builtin; behaviour matches native Linux. The interop binary `set.exe` does not exist — `set` only ever means the current shell's builtin.

Common tasks using set

Related commands