3

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.

1

1 Answer 1

3

Use PROMPT_COMMAND to get PS1 updated dynamically:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .