I'm currently trying to write a simple bash script that connects to my webapi downloads 1 line and uses this line on as a variable. The retrieving itself works just fine:
#!/bin/bash
exec 5<>/dev/tcp/me2stats.eu/5005 # No worries this is a public API ;)
printf "GET /gethighscore?level=1 HTTP/1.1\r\n\r\n" >&5
cat <&5
But I'm having trouble storing the output into a variable, this just outputs a blank line:
output=$(cat <&5)
echo $output
while read line skips the last line (the one I want!):
while read line; do
echo $line
done <&5
I'm not willing to use wget or curl because I don't want to bloat my docker images even further (they are already around 6GBs).
In short:
How do I store the last line of the http response into a bash variable?
readto have a non-zero exit status, thereby skipping the body of the loop. Another issue is the combination of CR/LF line endings with your failure to quote the parameter expansion. Compareecho $outputwithecho "$output".