linux - Bash Script division -


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

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

as can see temperature t=24187 have divide 1000. script looks 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   temperature  $f 

but dosen´t work. when start script, output here:

2015-05-04-08-51 (date 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 "/  ") 

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

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

will set $s 24187

that, , removing spaces after = signs suggested chepner want.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -