Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my embedded system, I can toggle a user led with: echo > 1 sys/class/leds/beaglebone:green:usr2/value.

Similarly, I can find the value of a GPIO (gpio60) (set to input), with more sys/class/gpio/gpio60/value

I've been trying to write a script to set the state of the user led based on that of the input. The following produces no errors, but doesn't actually work.

#!/bin/bash
cd ../../../
if [ sys/class/gpio/gpio60/value = 0 ]; then
echo 1 > sys/class/leds/beaglebone:green:usr2/brightness;
[else echo 0 > sys/class/leds/beaglebone:green:usr2/brightness;]
fi
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Maybe like this?

if [ $(cat sys/class/gpio/gpio60/value) -eq 0 ]; then
 echo 1 > sys/class/leds/beaglebone:green:usr2/brightness
else
 echo 0 > sys/class/leds/beaglebone:green:usr2/brightness
fi
share|improve this answer
    
Worked perfectly, thanks very much. –  Alex Feb 10 at 0:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.