226

I have tried the following command to set Proxy on yaourt:

export ALL_PROXY=http://proxy.example.com:8080

The question is how to unset the proxy on yaourt? In general, how can I unset the value of a variable in the current shell?

4
  • 13
    Try unset ALL_PROXY
    – Vombat
    Commented Dec 3, 2013 at 20:43
  • @coffeMug might as well make that into an answer, you could also consider stealing some info from here: stackoverflow.com/a/12263914/1081936
    – terdon
    Commented Dec 3, 2013 at 22:21
  • 2
    in addition to the accepted answer, if there's a command you often run that uses an environment variable that you'd rather not set or change for the rest of your shell session, you can run it like: $ ALL_PROXY=http://proxy.example.com:8080 yaourt that will set the envvar only for the command run. You can put as many FOO=bar BAZ=bat variables as you want prior to the command to run.
    – onlynone
    Commented Oct 13, 2017 at 19:20
  • 2
    LAUGHING OUT LOAD ..
    – Tom
    Commented Oct 17, 2021 at 19:39

2 Answers 2

304

To remove an environment variable, run

unset ALL_PROXY

Note that an environment variable only takes effect in a program and the program it launches. If you set an environment variable in one shell window, it doesn't affect other shell windows.

If you've added export ALL_PROXY=… to an initialization file, remove it from there.

You can run export with no arguments to see what environment variables are set in the current shell.

Remember that to make a shell variable available to the programs started by that shell, you need to export it, either by running export VAR after the assignment VAR=VALUE or by combining the two (export VAR=VALUE).

2
  • 1
    I think it's not essential that the export VAR occur after the assignment. Observe: sh -c 'export F; F=2; sh -c "echo F2=\$F"; echo F1=$F' prints "F2=2\nF1=2".
    – dubiousjim
    Commented Oct 30, 2020 at 8:56
  • unset is also required to clear associative bash arrays (ie: bash "hash tables", or "dicts"), as this tutorial explains under the section titled "Clearing": artificialworlds.net/blog/2012/10/17/…. Commented Jan 30, 2021 at 5:26
41

To unset a bound variable in bash use unset VARIABLE (unset ALL_PROXY in your case). This command actually deletes the variable. You can also set the value of a variable to empty by

VARIABLE=

or

VARIABLE=""

The difference is that the two latter commands don't delete the variable. You can see the difference by using the -u flag with set to force it to treat the unset variables as an error while substituting:

/home/user1> var=""
/home/user1> echo $var

/home/user1> set -u
/home/user1> echo $var

/home/user1> unset var
/home/user1> echo $var
-bash: var: unbound variable

In the above example, bash complains about var is unbound (after unsetting its value) which is the expected error (note that this does not happen in second echo command, meaning that var has a value which is empty or null).

2
  • what if I have a variable in my shell script file and I source that file, then how am I going to unset that?
    – Abhinav
    Commented Jul 30, 2018 at 20:43
  • 3
    @Abhinav use unset in the script. Same applies.
    – Vombat
    Commented Jul 31, 2018 at 10:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .