I am running a for loop in bash using variables which are populated from YAML file values. The variable itself contains not only the url to curl but also | jq command to parse the data, sort, and get latest version of a specific binary.
echo $version
https://api.github.com/repos/hashicorp/vault/tags | jq -r '.[].name' | sort -Vr | head -n 1 | cut -c 2-)
When I curl the whole string manually it works, and gives me version number.
curl -s https://api.github.com/repos/hashicorp/vault/tags | jq -r '.[].name' | sort -Vr | head -n 1 | cut -c 2-
1.14.2
However when passing it to curl using a variable:
curl $version
Warning: Invalid character is found in given range. A specified range MUST
Warning: have only digits in 'start'-'stop'. The server's response to this
Warning: request is uncertain.
curl 8.2.1 (x86_64-alpine-linux-musl) libcurl/8.2.1 OpenSSL/3.0.10 zlib/1.2.13 brotli/1.0.9 nghttp2/1.51.0
Release-Date: 2023-07-26
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL threadsafe TLS-SRP UnixSockets
What I tried so far is using double quotes around the adress using \ as exit characters and another set of double quotes at start and end. That did not help. I also tried using $version | $parse variable to split the curl part and parsing part but that resulted in
curl: (23) Failure writing output to destination.
EDIT: Using "$version" did not work and resulted in curl: (3) URL rejected: Malformed input to a URL function
. I have tried using double quotes surrounding the URL inside the variable as well.