How do I unset a variable in the fish shell?

Fish

Fish Problem Overview


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.

Fish Solutions


Solution 1 - Fish

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'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJ0hnG4ltView Question on Stackoverflow
Solution 1 - FishJ0hnG4ltView Answer on Stackoverflow