113

In bash I can unset a variable with

unset myvar

In fish I get

fish: Unknown command 'unset'

What's the equivalent for unset in fish.

J0hnG4lt
  • 4,337
  • 5
  • 24
  • 40

1 Answers1

177

Fish uses options on the set command to manipulate shell variables.

Unset a variable with the -e or --erase option.

set -e myvar 

Additionally you can define a function

function unset
  set --erase $argv
end

funcsave unset

or an abbreviation

abbr --add unset 'set --erase'

or an alias in ~/.config/fish/config.fish

alias unset 'set --erase'
Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
J0hnG4lt
  • 4,337
  • 5
  • 24
  • 40
  • 4
    Note that the function will not be able to erase local variables because it starts a new variable scope. Add `--no-scope-shadowing` to the function definition to fix this. – faho Aug 30 '16 at 17:52
  • Added an abbreviation method and a `funcsave` so the `unset` function sticks around. – Elijah Lynn Apr 04 '19 at 02:57