As expected this prints every line of the 'testEmpty' file to the console.
while read i; do
echo $i
done < testEmpty
....but this:
while read i; do
name=$i
echo $name
done < testEmpty
only prints out blanks lines.
The reason I am doing this is because on each line of the 'testEmpty' file there is a URL which I am feeding to curl within this same while loop (removed for clarity) and I wish to append a file extension to part of the url to serve as a filename and I thought it would be quite neat to do this in the same loop.
BTW The 'testEmpty' file should only ever really have only 1 or maybe 2 entries so I'm not bothered about overhead etc. which I believe could well be an issue if I were processing huge files, so I have no need to worry about that.
Thank you
sed
isn't typically the right way to do an alteration; bash has native string-manipulation functionality built in. For instance,name=${i//$foo/$bar}
will save the expanded contents of$i
to$name
, replacing$foo
with$bar
. – Charles Duffy Mar 28 at 16:47