Inspired by this answer, I added the following code to .bashrc
:
get_cpu_temperature() {
CEL=$'\xc2\xb0C'
temp=$( cat /sys/devices/virtual/thermal/thermal_zone0/temp )
temp=`expr $temp / 1000`
echo $temp$CEL
}
PS1="$(get_cpu_temperature) \u@\h:\w\$ "
However, it appears that this function is only called once, so the temperature is not updated. How can I have an updated temperature reading in the prompt? It doesn't have to update constanty; once per prompt is fine.
PROMPT_COMMAND
. See What is the difference between PS1 and PROMPT_COMMAND.