I have a script that is something like
#!/bin/bash
echo -n "User: "
read -e username
echo -n "Password: "
read -es password
export http_proxy="http://$username:$password@localhost:40080"
export https_proxy="http://$username:$password@localhost:40080"
$@
unset http_proxy
unset https_proxy
It reads the user/pass, export the proxy, run the command I need the proxy then clean it.
It works. But I tried making this:
#!/bin/bash
echo -n "User: "
read -e username
echo -n "Password: "
read -es password
export http_proxy="http://$username:$password@localhost:40080"
export https_proxy="http://$username:$password@localhost:40080"
So I could source proxyscript
(and be able to use the proxy for a whole session without needing to put user/pass everytime), it waits for input, but exports http://:@localhost:40080
---
So, what I'm doing wrong or how can I make it work?
(I know I can make it as args and use $1
/$2
, or something like that, but I would like to avoid having to have the password open in the history)
---
Edit/Solution:
Building on the answers, a small change was enough to make it compatible with both bash
and zsh
:
#!/bin/bash
echo -n "User: "
read username
echo -n "Password: "
read -s password
export http_proxy="http://$username:$password@localhost:40080"
export https_proxy="http://$username:$password@localhost:40080"
Basically, just removed the e
flag.
Asked by Noriller
(111 rep)
Sep 14, 2022, 01:17 PM
Last activity: Sep 14, 2022, 02:26 PM
Last activity: Sep 14, 2022, 02:26 PM