There is no practical way for your shell script to access loop data directly, best solution I can think of is to write a custom service bound to the NEW_LOOP_PACKET event that writes the required data to a text file that you then read as you currently do. The service will be very basic, but unlike a template (which uses the cheetah template engine to do the hard work) your service will need to write the data to a file itself. Fairly straightforward, any of the loop based services that write data to a file (eg crt - https://github.com/weewx/weewx/wiki/crt) have all the building blocks you need, they are just a bit more complex.
Gary
[CumulusRealTime_outTemp]
filename = /var/www/weewx/temperature.txt
temperature_units = degree_F