Hi All,
I am trying to get
curl -s ipinfo.io -o -
into a variable
X=$(curl -s ipinfo.io -o -)
But I lose all my line feeds when I
echo -e $X
How do I get my line feeds back?
Many thanks, -T
ToddAndMargo via users wrote:
I am trying to get
curl -s ipinfo.io -o -into a variable
X=$(curl -s ipinfo.io -o -)But I lose all my line feeds when I
echo -e $XHow do I get my line feeds back?
Quote the variable. You don't need -e; echo "$X" works.
But with JSON data being returned, it would seemingly make more sense to parse the data and extract what you want:
ipinfo=$(curl -s ipinfo.io) city=$(jq -r .city <<<$ipinfo)
or just:
city=$(curl -s ipinfo.io | jq -r .city)
On 1/19/22 21:59, Todd Zullinger wrote:
ToddAndMargo via users wrote:
I am trying to get
curl -s ipinfo.io -o -into a variable
X=$(curl -s ipinfo.io -o -)But I lose all my line feeds when I
echo -e $XHow do I get my line feeds back?
Quote the variable. You don't need -e; echo "$X" works.
But with JSON data being returned, it would seemingly make more sense to parse the data and extract what you want:
ipinfo=$(curl -s ipinfo.io) city=$(jq -r .city <<<$ipinfo)or just:
city=$(curl -s ipinfo.io | jq -r .city)
Cool. Thank you!
On 19Jan2022 20:32, ToddAndMargo ToddAndMargo@zoho.com wrote:
into a variable
X=$(curl -s ipinfo.io -o -)
That is robust (well, it loses trailing whitespace).
But I lose all my line feeds when I echo -e $X How do I get my line feeds back?
Quotes.
echo -e "$X"
Unquoted it is broken into "words" on whitespace, and echo prints the words with a single space between each. With quotes, echo has exactly 1 argument, the string in $X.
Oh, and try to use $lowercase variables for unexported/nonconfiguration variables.
But add tz says, if it is JSON, better to parse the JSON if you're picking things out of it.
Cheers, Cameron Simpson cs@cskk.id.au
On 1/20/22 13:42, Cameron Simpson wrote:
On 19Jan2022 20:32, ToddAndMargo ToddAndMargo@zoho.com wrote:
into a variable
X=$(curl -s ipinfo.io -o -)That is robust (well, it loses trailing whitespace).
But I lose all my line feeds when I echo -e $X How do I get my line feeds back?
Quotes.
echo -e "$X"Unquoted it is broken into "words" on whitespace, and echo prints the words with a single space between each. With quotes, echo has exactly 1 argument, the string in $X.
Oh, and try to use $lowercase variables for unexported/nonconfiguration variables.
But add tz says, if it is JSON, better to parse the JSON if you're picking things out of it.
Cheers, Cameron Simpson cs@cskk.id.au
Thank you!