I am trying to create 2 scripts. One for setting local enviroment variables, and the other for unsetting local enviroment varibales.

Firstly, both scripts were created under the following commands:

touch set-proxy.sh touch unset-proxy.sh

Then I made both of them executable:

chmod 700 set-proxy.sh chmod 700 unset-proxy.sh

Then I went into the set-proxy.sh file and put the following inside:


`export HTTP_PROXY=http://nick:nick@proxy.***.***.com:****`
`export HTTPS_PROXY=http://nick:nick@proxy.***.***.com:****`
`export HTTP-PROXY=http://nick:nick@proxy.***.***.com:****`
`export HTTPS-PROXY=http://nick:nick@proxy.***.***.com:****`
`export http_proxy=http://nick:nick@proxy.***.***.com:****`
`export https_proxy=http://nick:nick@proxy.***.***.com:****`
`export http-proxy=http://nick:nick@proxy.***.***.com:****`
`export https-proxy=http://nick:nick@proxy.***.***.com:****`

Then I went inside the unset-proxy.sh file and put the following inside:


`unset HTTP_PROXY`
`unset HTTP-PROXY`
`unset http_proxy`
`unset https_proxy`
`unset http-proxy`
`unset https-proxy`

I pretty much need a quick way to unset and set all proxy configuration. I thought creating two scripts would be the simplest way.

However, when I run ./unset-proxy.sh or ./set-proxy.sh I get the following error messages:

./unset-proxy: line 5: unset: `HTTP-PROXY': not a valid identifier
./unset-proxy: line 6: unset: `HTTPS-PROXY': not a valid identifier
./unset-proxy: line 9: unset: `http-proxy': not a valid identifier
./unset-proxy: line 10: unset: `https-proxy': not a valid identifier

(Then I get the same with the set-proxy.sh as well).

If someone could help point me in the right direction of what I am doing wrong and how I can correct it, would be super appreciated. Thanks.

  • 1
    What are all those backticks for?
    – thrig
    Commented Oct 27, 2017 at 1:29
  • I thought backticks were used in shell commands to tell the script to run an exxecutable. Even when i remove the, still doesn't work and still get the same error. Thanks for the question though.
    – user257636
    Commented Oct 27, 2017 at 1:31
  • Still get the error ./unset-proxy: line 5: unset: HTTP-PROXY': not a valid identifier ./unset-proxy: line 6: unset: HTTPS-PROXY': not a valid identifier ./unset-proxy: line 9: unset: http-proxy': not a valid identifier ./unset-proxy: line 10: unset: https-proxy': not a valid identifier
    – user257636
    Commented Oct 27, 2017 at 1:32
  • Why are you using ./script (which creates its own process, which then goes away) versus . ./script (which runs the code within the context of the current process)
    – thrig
    Commented Oct 27, 2017 at 1:33
  • ah not too sure really. So when i try running ` . ./unset-proxy` i get the same error but in a different format: -bash: unset: HTTP-PROXY': not a valid identifier`
    – user257636
    Commented Oct 27, 2017 at 1:35

1 Answer 1


It looks like there are several mistakes here. First, your variable assignment expressions shouldn't be inside backticks. The backticks are a (somewhat dated) syntax for command substitution. I think what you were going for was single-quotes. Quoting variables is done to preserve string literals and prevent parameter substitution.

Also, you can't use the hyphen character in your variable names. Here is an excerpt from the Bash Manual, Chapter 2: Definitions:


A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.

Also see the following posts for more information:

Here is what your scripts might look like after removing the backticks and the hyphens:

# set_proxy.sh

export HTTP_PROXY='http://nick:nick@proxy.***.***.com:****'
export HTTPS_PROXY='http://nick:nick@proxy.***.***.com:****'
export http_proxy='http://nick:nick@proxy.***.***.com:****'
export https_proxy='http://nick:nick@proxy.***.***.com:****'


# unset_proxy.sh

unset http_proxy
unset https_proxy

One final note: executing a script causes it to run in a subshell, so the environment variables won't affect your active shell session. See, for example, the following post:

The short answer is that you can't. So if you want your scripts to modify your current shell environment then you have to "source" them, e.g.:

source set_proxy.sh

source unset_proxy.sh
  • The last part of your comment was definitely the most helpful for me. Understanding that you cannot set variables for your terminal shell from inside a subshell saved me a lot of googling. Thanks!
    – Chris S
    Commented Feb 20, 2019 at 8:30
  • 1
    If your user/pwd and proxy address are the same to all proxies type, you can use this: export {all,tcp,http,https,socks,ALL,TCP,HTTP,HTTPS,SOCKS}_proxy='nick:nick@proxy.***.***.com:****'
    – Esli Silva
    Commented May 2, 2022 at 12:20

You must log in to answer this question.

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