Reply
Thread Tools
Posts: 11 | Thanked: 7 times | Joined on Dec 2009
#1
Hi everyone!

I've been looking for the Shell documentation of BusyBox which I know has been made from a light Debian Almquist Shell.

I'm trying to make for fun a tiny shell script for a desktop-command widget on my n900 which extract the data from cpu_curfreq:


#!/bin/sh

#Freq extraction, formating and wrinting result into userfrec file
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq|tr -d "\n">/userfreq

#extracting data
Varcurfreq= cat '/userfreq'
result=$(( $Varcurfreq / 1000 ))
echo -n $result
echo " Mhz"

I've found that Dash may be restricted on some operation and I switched to Bash... Anyway I 've got the same problem with the arithmetic division operator "/"

output in dash : 249600./cpu_curfreq.sh: line 8: syntax error: / 1000

I'm kind of a noob and I would really appreciate anyone's help about how to make a division whether in Dash or Bash... or even better if someone has the documentation for BusyBox.

Thank you all Maemoers and future Meegos

Last edited by SneakyC4; 2010-05-30 at 16:33.
 
Posts: 539 | Thanked: 165 times | Joined on Feb 2010 @ Berlin, Germany
#2
Originally Posted by SneakyC4 View Post
#!/bin/bash
I assume, bash is properly installed? By default, bash is not part of the system.

cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq|tr -d "\n">/userfreq
Uuuu. Very bad style! Cat-ing to a file sould be avoided at all, especially to a file at root directory! If you really think you have to use a temporary file, create one in /tmp or /home/user/temp or similar.

output : 249600./cpu_curfreq.sh: line 8: 0: command not found
Which line is number 8?

... or even better if someone has the documentation for BusyBox.
Try this one:
http://busybox.net/downloads/BusyBox.html#expr
 

The Following User Says Thank You to x-lette For This Useful Post:
Posts: 29 | Thanked: 7 times | Joined on May 2010 @ Frankfurt, Germany
#3
To assign the output from a command to a shell variable' you'll need to use '$()' as in
Code:
VAR=$(cmd)
As x-lette pointed out, neither an intermediate file nor an intermediate var are necessary in your case. The following one-liner does the trick:
Code:
echo $(( $(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) / 1000 )) MHz
 

The Following User Says Thank You to Manul For This Useful Post:
Posts: 11 | Thanked: 7 times | Joined on Dec 2009
#4
Thank you X-lette I know it was crapy way for formating data but as I said I'm noob haha... thank for note.

Manul you indeed did the trick $(()) seems to be a very useful command I didn't know. This is an example of how powerful basic mameo shell is !!!!

Just need one line code Wahooo!!!!

Great!!!

Last edited by SneakyC4; 2010-05-30 at 19:06.
 
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#5
Don't forget simple redirection. < and > works, you know.
 
Reply


 
Forum Jump


All times are GMT. The time now is 17:54.