How to set proxy in Bash and Zsh
To set proxy in bash and zsh, we need to code the bash script or zsh script.
We will edit the .bashrc or .zshrc dot file in your home path like:1
2
3/home/yourname/.bashrc
or
/home/yourname/.zshrc
Then, use neovim (maybe you can chose your favourite editor whatever :D ) to edit:1
$ nvim ~/.bashrc
or1
$ nvim ~/.zshrc
Add the proxy and noproxy function:1
2
3
4
5
6
7
8proxy(){
export all_proxy=socks5://localhost:7890
echo "All proxy On!"
}
noproxy(){
unset all_proxy
echo "All proxy Off!"
}
After the bash command source ~/.bashrc
, you can use proxy
command to set the proxy on. Also use noproxy
command to set the proxy off.
You can echo "proxy" > ~/.zshrc
if you like to set proxy when open the terminal (Just like python haha).
How to set proxy in Bash and Zsh
http://blog.inverseda.top/2023/02/01/Linux/Bash and Zsh/How to set proxy in Bash and Zsh/