-1

I'm a beginner in scripting. I have a temperature sensor which gives me temperature if I cat the file /sys/bus/w1/devices/28-000006c5772c/w1_slave. The output of the file looks like:

83 01 4b 46 7f ff 0d 10 66 t=24187

As you can see the temperature is t=24187 which I have to divide by 1000. My script looks like this:

#!/bin/bash
date +%Y-%m-%d-%H-%M
s= cat /sys/bus/w1/devices/28-000006c5772c/w1_slave |  grep t= | cut -d "=" -f2
x= 1000
f= echo  $(( $s / $x )) | bc -l
echo  the actually  temperature  is $f

But it dosen´t work. When I start the script, I get this output here:

2015-05-04-08-51 (date is wrong NTP not configured^^) 
23687
/home/pi/RAB.sh: line 5: 1000: command not found
/home/pi/RAB.sh: line 6: /  : syntax error: operand expected (error token is "/  ")
Anthony Geoghegan
  • 11,533
  • 5
  • 49
  • 56
Synced21
  • 13
  • 3
  • 2
    Run your code through [spellcheck.net](http://shellcheck.net). You can't put a space after the `=` in an assignment – chepner May 15 '15 at 12:12
  • 1
    You'll have a much better chance of getting answers if your question is readable. It's worth spending the time to write in standard English (correct spelling, punctuation, etc.). The Stack Overflow Markdown also provides a number of formatting options to make posts even easier to read. I've edited your question for you so you can see how it can be improved. – Anthony Geoghegan May 15 '15 at 12:13
  • 1
    The thing with scripting (especially when new) is that you need to test commands on command line before scripting them, so in this case entering `x= 1000` then `echo $x` might might have solved your issue. but live (do) and learn :) – hoss May 15 '15 at 15:50

1 Answers1

1

To assign the output of a command to a variable, you need to use the backticks or (preferably) the $() syntax.

s=$(cat /sys/bus/w1/devices/28-000006c5772c/w1_slave |  grep t= | cut -d "=" -f2)

will set $s to 24187

That, and removing the spaces after the = signs as suggested by chepner will get you what you want.

rojomoke
  • 3,765
  • 2
  • 21
  • 30
  • You're welcome, but the real way to thank someone on stackexchange is to accept their answer. Click on the tick-mark to the left. – rojomoke May 20 '15 at 08:25