Created
March 3, 2025 15:38
-
-
Save tongyul/acae67e946bd7728e6294ad977009918 to your computer and use it in GitHub Desktop.
Shell script that runs command with network proxy variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
HELP_STR="\ | |
Usage: | |
proxied # prints this message | |
proxied _proxy_ # prints sh snippet that sets _proxy_ | |
proxied _proxy_ _cmd_... # runs _cmd_ with _proxy_ | |
Environment variables that are affected: | |
- ALL_PROXY | |
- http_proxy | |
- https_proxy | |
" | |
case "$#" in | |
0) | |
printf '%s' "$HELP_STR" | |
;; | |
1) | |
echo "export ALL_PROXY='$1';" | |
echo "export http_proxy='$1';" | |
echo "export https_proxy='$1';" | |
;; | |
*) | |
(eval "$("$SHELL" "$0" "$1")" && shift && "$@";) | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment