Consider I have a curl command:
'curl' '--noproxy' 'check' '-H' 'Authorization: token ${TOKEN}' '-H', 'Accept: application/vnd.github.v3+json' '--create-dirs' '-o' successFile.toString() "Url"
Below script is to test the working of curl command and Here I want to add long option --noproxy to the below script:
#!/bin/sh
string_matches() {
eval "
case \$1 in
$2) return 0 ;;
*) return 1 ;;
esac
"
}
FULL_COMMAND="$@"
while getopts "H:o:H:X:d:-:" OPT; do
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#$OPT}"
OPTARG="${OPTARG#=}"
fi
case "${OPT}" in
o) OUTPUT_FILE="${OPTARG}" ;;
create-dirs) CREATE_DIRS=1 ;;
?) ;;
esac
done
shift $(($OPTIND - 1))
CURL_URL=$1
if [ -n "${CREATE_DIRS:-}" ]; then
mkdir -p $(dirname ${OUTPUT_FILE})
fi
if string_matches "${CURL_URL}" '*content.properties*'; then
echo 'success' >"${OUTPUT_FILE}"
else
exit 97 #WAT
fi
I tried adding noproxy in case
case "${OPT}" in
n|noproxy) NOPROXY='check';;
but it doesn't seem to work, but if I remove the noproxy option, everything else is working perfectly. Tried using this answer but no luck https://stackoverflow.com/a/28466267/21758758