Search code examples
bashbsd

bash show for loop variable twice


Why does this only show the entry from data.csv one time?

for i in `cat ~/Downloads/data.csv`
do
  echo $i $i
done

I have tried $i$i and the += operator and none of them seem to do what I would have expected. The goal is to create links from data.csv, which is a list of urls. So the output would ideally be

<a href='$i'>$i</a>

I am using OSX.


Solution

  • don't use bash for file content processing, awk is better suited for this.

    $ awk '{print "<a href=\"" $0 "\">" $0 "</a>"}' file