New: XDA launches forum for app developers. Discuss coding, tools, marketing, and more.
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
Sin2800
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 10
Join Date: Aug 2010
Location: Canton
Default Shell Programming Error

I recently wrote a shell program to turn the front LEDs on and off for a flashlight, without having two scripts (one off, one on, which did work). Although the script seems sound to me, i get an error when I run it:
Stderr [: Not Found
Stderr [: Not Found

The script is as follows:

led_status=$(cat /sys/class/leds/flashlight/brightness);
if [ 1 ]
then
if [ "$led_status" = "0" ]
then
echo 3 > /sys/class/leds/flashlight/brightness
fi
fi

if [ "$led_status" = "3" ]
then
echo 0 > /sys/class/leds/flashlight/brightness
fi
 
k_flan
Old
(Last edited by k_flan; 10th August 2010 at 08:44 PM.) Reason: added info
#2  
k_flan's Avatar
Senior Member
Thanks Meter 45
Posts: 288
Join Date: Jul 2010
Location: Aurora, IL
I tried the script stripped down a little:

Code:
led_status=$(cat /sys/class/leds/flashlight/brightness);
if [ "$led_status" = "0" ];
then 
	echo 3 > /sys/class/leds/flashlight/brightness
else
	echo 0 > /sys/class/leds/flashlight/brightness
fi
But I get permission denied trying to run it with better terminal pro from emmc with su. I'm not going to be much help, but I'm interested to know if you get this working, and how to run it, and from where.
 
Sin2800
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 10
Join Date: Aug 2010
Location: Canton
GScript is the app I use to run scripts as su. It works fine.

But for some reason, I still get the error:

stderr: [: Not Found

I don't know what it's trying to find tbh, but that bracket seems to be a problem.
 
zerf
Old
#4  
zerf's Avatar
Member
Thanks Meter 0
Posts: 93
Join Date: Jan 2010
Code:
led_status=$(cat /sys/class/leds/flashlight/brightness);
if [ "$led_status" = "0" ];
then 
	echo 3 > /sys/class/leds/flashlight/brightness
else
	echo 0 > /sys/class/leds/flashlight/brightness
fi
I just put that code in to gscript and was able to run it fine. It turned both leds on(Really bright) and then I ran it again and it shut both of them off...

Cool script but y not just use an app like lamppu with widgets to do this? or do you have something else your putting together that this is part of?
 
Sin2800
Old
#5  
Junior Member - OP
Thanks Meter 0
Posts: 10
Join Date: Aug 2010
Location: Canton
Hmm. I wonder why mine isn't working then. And I would, but I'm trying to learn more about android and how it works, and running into an error where a bracket becomes a problem confused me to be honest.