0

I am using this line of code:

code=$(curl -ks -o /dev/null -i -w 'Status: ''%{http_code} -X GET www.goog.com

but I want to change the curl to use proxy 127.0.0.1:8080 but without changing the above code. I want to use a variable that will change it on the go.

code=$(curl -x 127.0.0.1:8080 -ks -o /dev/null -i -w 'Status: ''%{http_code} -X GET www.goog.com

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Faisal
  • 11
  • What is the problem with doing so? – CherryDT Nov 01 '21 at 02:48
  • Your quotes are unbalanced; the given code won't parse. – Charles Duffy Nov 01 '21 at 02:49
  • 1
    Anyhow -- the documentation for curl describes environment variables it honors. Have you reviewed it? – Charles Duffy Nov 01 '21 at 02:49
  • Beyond that, it's simply not clear what you're asking for. Do you want a shell function that'll wrap curl to add the proxy arguments? Do you want to configure curl to use a proxy without needing any extra arguments at all? Do you want to use a parameter expansion to optional add the `-x` argument if and only if there actually is a proxy configured? Lots of options, and which one to choose is in your court, not ours. – Charles Duffy Nov 01 '21 at 02:52
  • 1
    https://stackoverflow.com/a/9447493/14122 describes the environment variable approach; if that's what you want the question is a duplicate. – Charles Duffy Nov 01 '21 at 02:53

0 Answers0