-1

I'm trying to store in a variable the temperature of the computer. I tried this but it doesn't work:

#!/bin/bash
temp = cat "/sys/class/thermal/thermal_zone0/temp"
echo "$temp"

i tried this too:

#!/bin/bash
temp = $(cat "/sys/class/thermal/thermal_zone0/temp")
echo "$temp"

but nothing works, it always says

./temp.sh: line 2: temp: command not found
Cyrus
  • 84,225
  • 14
  • 89
  • 153

1 Answers1

-2

Spaces are crucial! This works fine:

# NO space around `=`
temp=$(cat "/sys/class/thermal/thermal_zone0/temp")
echo "$temp"
ForceBru
  • 43,482
  • 10
  • 63
  • 98
  • 2
    Consider the usual chiding (re: the *Answer Well-Asked Questions* section of [How to Answer](https://stackoverflow.com/help/how-to-answer) advising that new instances of frequently-asked questions be closed, not answered) to have taken place. – Charles Duffy Apr 22 '20 at 17:35