Issue
I need to set HTTP proxy in my install script like this:
HTTPS_PROXY="http://1.2.3.4:4321" bash -c "$(curl -L https://my.script.com/install.sh)"
Here:
- My install.sh also need
$HTTPS_PROXY
to download these real binary files, and - The command line
curl
are also proxyed by$HTTPS_PROXY
, but it can't read the ENV set before head. I have to write like this:
HTTPS_PROXY="http://1.2.3.4:4321" bash -c "$(HTTPS_PROXY=http://1.2.3.4:4321 curl -L https://my.script.com/install.sh)"
# or like this
HTTPS_PROXY="http://1.2.3.4:4321" bash -c "$(curl -x http://1.2.3.4:4321 -L https://my.script.com/install.sh)"
Is there any way to set ENV(here $HTTPX_PROXY
) only once for my conditon?
My bash verison:
$ bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
It seems that this is ok, I need to test it under different bash:
HTTPS_PROXY="http://1.2.2.3:4321" bash -c "curl -L https://my.script.com/install.sh | bash"
Solution
Because of the double quotes, the curl
command runs before the HTTPS_PROXY
assignment and bash -c
. I'm guessing you want
HTTPS_PROXY="http://1.2.3.4:4321" bash -c 'eval "$(curl -s -L https://my.script.com/install.sh)"'
which will set the value of HTTPS_PROXY
for Bash, which then runs curl
and evaluates its output as a command to run.
The eval
and the added double quotes around the command substitution are necessary if the output spans multiple lines (or otherwise needs to be protected from whitespace tokenization and wildcard expansion). I also added -s
to the curl
options to avoid having it output progress messages.
Answered By - tripleee Answer Checked By - Mary Flores (WPSolving Volunteer)