Без массивов ваш следующий лучший вариант - определить функцию, чтобы вы могли использовать ее (неиспользуемые) позиционные параметры в качестве псевдомассива.
В качестве примера я буду притворяться заголовок передается как аргумент, а не как глобальная переменная, такая как хост, порт и путь.
run_curl () {
# save any arguments first
curl_host_header=$1
# Repurpose $@ for use when you call curl
set -- '--noproxy' '*' '--verbose' '--silent' '--include' '--write-out' '%{http_code}'
if [ -n "$curl_host_header" ]; then
set -- "$@" --header "$curl_host_header"
fi
set -- "http://$CURL_HOST:$CURL_PORT$CURL_PATH"
n=0
until [ "$n" -ge 5 ]
do
n=$(($n+1))
curl_response=$(curl "$@")
page=${curl_response:0:-3}
http_status=${curl_response : -3}
if [ "$http_status" != "200" ]
then
echo "Curl failed with http status $HTTP_STATUS. Retrying shortly if attempts remain"
sleep 15
else
break
fi
done
if [ "$http_status" != "200" ]
then
logfile=curlable-error-page-$(date +%s).html
{
echo "CURL CMD:"
echo "curl $*" # $* is fine for embedding in a larger string
echo "STATUS:"
echo "$http_status"
echo "RESPONSE:"
echo "$page"
} > "$logfile"
exit 1
fi
}
run_curl # No extra headers
run_curl "$CURL_HOST_HEADER" # Extra header