LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2024, 09:02 AM   #16
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,710

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899

Another solution is bc.
Code:
if [[ $(echo "$voltage>200" | bc) ]]; then
   echo "Less than 200"
   gpio write 6 0
else
   echo "greater than 200"
   gpio write 6 1
fi
bc outputs 0 if less than and 1 if greater. if uses 0 if true and 1 if not.
 
Old 02-14-2024, 03:54 PM   #17
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Quote:
Originally Posted by stockton View Post
grid_voltage/state also returns the voltage as a float
Pity.

Were it me, I'd simply include the period as a separator for awk, then everything you already have will should work.
 
Old 02-15-2024, 01:56 AM   #18
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,855

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
from the other hand the tool has a json output which can be easily processed with python (for example) and it has no any problem with floats and to execute additional commands (like gpio) too.
 
Old 02-16-2024, 11:41 AM   #19
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 2
Thank you NevemTeve
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help with understanding the 'with' keyword and understanding file reading and writing. vysero Programming 3 05-30-2018 02:37 PM
Understanding of set -x output when ran against Bash script JockVSJock Linux - Newbie 5 03-16-2018 03:52 AM
Simple BASH script; understanding loops and case Sinensis Linux - Newbie 1 06-17-2010 04:32 AM
Help understanding a bash script cylon Linux - Newbie 4 09-16-2009 10:04 AM
bash script, understanding variables antis Programming 5 11-15-2007 04:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration