0

I am trying to do something simple but it's not working. I am trying to echo a stock price from a variable and follow it with text. The problem is that the text does not follow the variable and goes in front of it.

#!/bin/sh
stock=$(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=l1')
echo "$stock"

echo ".. $stock .."

the second output doesn't show correctly, what am I doing wrong?

Thx

1 Answer 1

1

The variable $stock has \r\n at its end.

$ echo $stock | hexdump -c 
0000000   1   0   2   .   9   9  \r  \n                                
0000008

You can modify your call to curl as

stock=$(curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=l1'| tr -d '\r\n')

$ echo ".. $stock .."
.. 102.99 ..
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.