If I run in the CLI:
curl time.com | sed -n 's/.*href="\([^"]*\).*/\1/p' | tr " " "\n"
then, as expected, I get a list of sanitized links from the page to STDOUT
, each on new line.
However, when I save that to a variable and try to echo
that from a script.sh
:
PAGE_LINKS=$(curl time.com | sed -n 's/.*href="\([^"]*\).*/\1/p' | tr " " "\n")
echo $PAGE_LINKS
I get all links on one line, space separated. So as if the tr
was ignored.
I tried multiple things including something like
HREFS=$(tr " " "\n" < "{PAGE_LINKS}")
echo $HREFS
But then I get file too long
error. Any suggestions?