I'm trying to build a function that returns arguments for curl:
get_common_curl_headers() {
local crash_path="$1"
echo -n \
"-H 'Accept: text/plain'" \
"-F 'model=<$crash_path/model'" \
"-F 'version=<$crash_path/fw_version'"
echo -n ' '
}
I'd like the returned file paths to be quoted as $crash_path variable might contain spaces. I then use this function like this:
send_app_crash() {
local crash_path="$1"
local common_headers
common_headers=$(get_common_curl_headers "$crash_path")
[ $? -ne 0 ] && return 1
curl -vk -X POST \
$common_headers\
"$SERVER_URL"
}
I use the variable $common_headers unquoted here, as I want the arguments to be expanded, which to my understanding should work. However, the command results in this error:
curl: (6) Couldn't resolve host 'text'
curl: (26) couldn't open file "/tmp//model'"
Weirdly, there's an extra single quote at the end of the file name, which should have been removed by the shell. I'm not sure what the first error means as well, as Accept: text/plain seems to be properly quoted (see below).
Running the command manually (i.e. doing set -x before the command appears inside the script and piping it to sh) works as intended:
curl -vk -X POST -H 'Accept: text/plain' -F 'model=</tmp//model' -F 'version=</tmp//fw_version' 192.168.2.100:8888