I have a shell script to set the CPU frequency to maximum on all cores on Android devices. The contents are:
#!/system/bin/sh
cpucores=`grep -c ^processor/proc/cpuinfo`
cpusint=`echo $((cpucores-1))`
littlefreq=`cat /sys/devices/system/cpu/cpu$cpusint/cpufreq/scaling_max_freq`
bigfreq=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`
cpuhalf=$((cpucores/2))
cpuhalfint=`echo $((cpufalf-1))`
if [$bigfreq -ne $littlefreq]; then
for i in `seq 0 $cpuhalfint`; do
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
echo "performance" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
echo $bigfreq > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
done
for x in `seq $cpuhalfint $cpusint`; do
chmod 0644 /sys/devices/system/cpu/cpu$x/cpufreq/scaling_governor
echo "performance" > /sys/devices/system/cpu/cpu$x/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu$x/cpufreq/scaling_min_freq
echo $littlefreq > /sys/devices/system/cpu/cpu$x/cpufreq/scaling_min_freq
done
else
for i in `seq 0 $cpusint`; do
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
echo "performance" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
echo $bigfreq > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
done
fi
The script works fine, but it returns this:
./setcpu.sh[28]: [1248000: not found
(1248000 is my CPU frequency, and setcpu.sh is the name of the shell script file)
Whereas it shouldn't output ANYTHING at all. Does someone know why this is happening?
Thanks for answering.
I have a shell script to set the CPU frequency to maximum on all cores on Android devices. The contents are:
#!/system/bin/sh
cpucores=`grep -c ^processor/proc/cpuinfo`
cpusint=`echo $((cpucores-1))`
littlefreq=`cat /sys/devices/system/cpu/cpu$cpusint/cpufreq/scaling_max_freq`
bigfreq=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`
cpuhalf=$((cpucores/2))
cpuhalfint=`echo $((cpufalf-1))`
if [$bigfreq -ne $littlefreq]; then
for i in `seq 0 $cpuhalfint`; do
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
echo "performance" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
echo $bigfreq > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
done
for x in `seq $cpuhalfint $cpusint`; do
chmod 0644 /sys/devices/system/cpu/cpu$x/cpufreq/scaling_governor
echo "performance" > /sys/devices/system/cpu/cpu$x/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu$x/cpufreq/scaling_min_freq
echo $littlefreq > /sys/devices/system/cpu/cpu$x/cpufreq/scaling_min_freq
done
else
for i in `seq 0 $cpusint`; do
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
echo "performance" > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_governor
chmod 0644 /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
echo $bigfreq > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_min_freq
done
fi
The script works fine, but it returns this:
./setcpu.sh[28]: [1248000: not found
(1248000 is my CPU frequency, and setcpu.sh is the name of the shell script file)
Whereas it shouldn't output ANYTHING at all. Does someone know why this is happening?
Thanks for answering.
Share Improve this question edited Mar 2 at 15:33 IsHacker asked Mar 2 at 14:08 IsHackerIsHacker 258 bronze badges 3 |1 Answer
Reset to default 1[
is an alias for test
. It's a command name, so it must be separated from its arguments just like test
or echo
needs.
]
must also be provided as an entire argument.
Therefore,
if [$bigfreq -ne $littlefreq]
needs to be replaced with
if [ $bigfreq -ne $littlefreq ]
Thanks to @oguz ismail.
if [$bigfreq -ne $littlefreq];
is wrong, it should beif [ $bigfreq -ne $littlefreq ];
– oguz ismail Commented Mar 2 at 14:54$((cpucores-1))
then it should also supportcpusint=$(echo $((cpucores-1)) )
(stop using back-tics (-;!). Any place where you are using back-tics cmd-substitution, you can join the late 1980s and use$( cmd )
for cmd-substituion. Better because you can nest them as much as you want without having to escape anything (nested backtics need to be escaped for each level of nesting). Learn to check your code at shellcheck.. Be sure to include#!/bin/sh
(or whatever) as the first line. Good luck. – shellter Commented Mar 3 at 20:45