Inspired by this answer, I added the following code to .bashrc:

get_cpu_temperature() {
    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.


1 Answer 1


Use PROMPT_COMMAND to get PS1 updated dynamically:

PROMPT_COMMAND='PS1="$(get_cpu_temperature) \u@\h:\w\$ "'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.