As for what's wrong, you have several basic syntax errors here.
echo $(http://something)
attempts to run http://something
as a command, and then pass its output as a string to echo
. Of course, in your case, http://something
is not a valid command, so that's why you get the not found
error message.
echo $(http://something) tee file
is passing three arguments to echo
; two of them are tee
and file
, so it will not actually run tee
at all.
- If you fixed that, running
tee
again and again inside the loop would overwrite the output file in each iteration, ending up with only the output from the last loop iteration in the file.
- Tangentially, the superstitious backslashing in the
echo
argument is superfluous. The equals sign is not a shell metacharacter at all, and a semicolon inside a double-quoted string only represents the literal semicolon character itself.
A minimal fix would look like
while read i ; do
echo "http://uk.finance.yahoo.com/echartss=$i#symbol=$i;range=my;compare=;indicator=volume;charttype=area;crosshair=on;ohlcvalues=0;logscale=off;source=undefined;" |
tee -a stock_urls
done < awk_1
but a better fix would avoid redirecting from inside the loop;
while read i ; do
echo "http://uk.finance.yahoo.com/echartss=$i#symbol=$i;range=my;compare=;indicator=volume;charttype=area;crosshair=on;ohlcvalues=0;logscale=off;source=undefined;"
done < awk_1 | tee stock_urls
and a better solution still would be to replace this gnarly and slow loop with a one-liner (or, well, two-liner);
sed 's|.*|http://uk.finance.yahoo.com/echartss=&#symbol=&;range=my;compare=;indicator=volume;charttype=area;crosshair=on;ohlcvalues=0;logscale=off;source=undefined;|' awk_1 |
tee stock_urls
This uses the sed
command s/regex/replacement/
where the regex matches the entire input line, and &
in the replacement recalls the text which the regex matched.
Perhaps also visit https://shellcheck.net/ which should be able to point out at least some of these errors.