If I use this link to install docker-compose, I get Not Found error:
[root@hostname ~]# curl -L "https://github.com/docker/compose/releases/download/2.9.0/docker-compose-$(uname -s)-$(uname -m)" -o here
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9 100 9 0 0 37 0 --:--:-- --:--:-- --:--:-- 37
[root@hostname ~]# cat here
Not Found
That's because the actual file is docker-compose-linux-x86_64
with small l
, while:
[root@hostname ~]# echo $(uname -s)-$(uname -m)
Linux-x86_64
It returns capital L
.
I saw man curl
but did not see any entry for checking case-insensitive link.
It's not curl that decides case-insensitivity at all link "checking" is the server's decision.
(In other words, HTTP clients do not have the opportunity to see the list of all possible URLs and choose a matching one. The only thing an HTTP client can do is give the exact URL to the server and let the server decide how to respond. Some servers are case-insensitive, some are not.)
But if you already know that you need a lowercase 'linux', you can just transform the uname
output before giving it to curl, e.g. by piping it through tr A-Z a-z
to change all uppercase letters to lowercase:
docker-$(uname -s | tr A-Z a-z)
or by using Bash's ${var,,}
expansion to return a lowercase version of $var
:
os=$(uname -s); arch=$(uname -m)
docker-${os,,}-${arch}
Finally, since there's only a small set of accepted values, and because the accepted values aren't guaranteed to be "uname but lowercase" in general, you could indirectly assign each possible value (using if
or case
blocks), for example:
case $(uname -s) in
Darwin) docker_os='darwin';;
Linux) docker_os='linux';;
Cygwin) docker_os='windows';;
Microsoft) docker_os='windows';;
*) echo "Docker is not supported on this OS!" >&2; exit 1;;
esac
(Note: The 'windows' examples are completely made up. )
The other generic syntax components are assumed to be case-sensitive unless specifically defined otherwise by the scheme (see Section 6.2.3).
And I could not find anything in the HTTP scheme definition which would override that statement. — Aug 03, 2022 at 07:26