Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got this code:

Unix+=("Stock List")
while read line; do 
  result=$(wget -O - -o /dev/null "http://finance.yahoo.com/d/quotes.csv?s=$line&f=sl1&e=.csv" | tr ',' '    ' | tr '"' ' ')
done < stock.txt

echo ${Unix[@]}
echo ${Unix[0]}
echo ${Unix[1]}
echo ${Unix[2]}

that reads a text file with only these lines in it:


And outputs this:

 QPP.L 14.2495.L 27.50
Stock List
SXX.L 27.50
QPP.L 14.2495

Why is the array[@] output missing information and messed up?

share|improve this question
up vote 6 down vote accepted

Executing with #!/bin/bash -x shows:

+ echo Stock List SXX.L $'27.50\r' QPP.L $'14.2495\r'

Those \r will likely be what's messing up the output. It moves the cursor back to the beginning of the line, and whatever follows afterward overwrites what's already there.

share|improve this answer
Good find; confirmed that stripping out the \r characters fixes it – Michael Mrozek Jan 30 '13 at 19:48
Thanks! I've added stripping the \r bits out, and as MM says, it fixes it! – user31459 Jan 30 '13 at 20:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.