I'm diving headfirst into bash with no prior experience and have hit a bit of a snag: I wrote a small bash script to determine the average of values (it's just a total right now) being returned by a c executable.
#Sample value of #s1total: 0+0.000117+0.000149+0.000106
printf "\n%s" $s1total
#The following line works
printf "\nTotal: %s\n" $(bc <<< $s1total)
#the following also works
echo
echo -n "Total: "
echo $s1total | bc
#The following line does not work
printf "\nTotal: %s\n" $($s1total|bc)
I did eventually find that the last line can be made to work by changing it to $(echo $s1total|bc)
but i don't understand why that works ...
If I run as-is, I get an error:./sievetest.sh: line 25: 0+0.000117+0.000149+0.000106: command not found
Is the string being run before the pipe? Why? Why does adding "echo" fix it? How is the third method different than the first and second?
(as an aside, I thought the heredoc redirection operator was << , why the extra < ?)
You have this:
which is basically
e.g. run a command named
0+....
and pipe it tobc
.It should be