Reputation: 391
Context: I have a script in that long lines are being striped.
In bash, I could do this
CURL=/usr/bin/curl
declare -a ARGS=(
--silent
--location
--output /dev/null
--write-out "%{http_code}"
--request GET
--max-time 30
--retry 3
"https://httpbin.org/status/200"
)
http_code=$("$CURL" "${ARGS[@]}")
However, ash does not have arrays. Is there another alternative to avoid long lines like I can do on bash in ash
or in sh
?
Upvotes: 0
Views: 31
Reputation: 16817
Long lines can be split with backslashes:
CURL=/usr/bin/curl
curlWithArgs(){
"$CURL" \
--silent \
--location \
--output /dev/null \
--write-out "%{http_code}" \
--request GET \
--max-time 30 \
--retry 3 \
"https://httpbin.org/status/200" \
;
}
http_code=$(curlWithArgs)
Upvotes: 2