When echoing a value and redirecting it to a file under sysfs, ash just prints an empty line but does not store the value. This only happens when ">" character is typed right after the command. For example, this works: # echo 250 > /sys/class/backlight/pwm-backlight.0/brightness # cat /sys/class/backlight/pwm-backlight.0/brightness 250 But this does not: # echo 128> /sys/class/backlight/pwm-backlight.0/brightness # cat /sys/class/backlight/pwm-backlight.0/brightness 250 Redirecting in similar way to a normal file works: # echo hello> /tmp/world # cat /tmp/world hello
Tested with busybox 1.19.4 and 1.20.2
Please strace it: strace -oLOG -s99 ash -c 'echo 128> /sys/class/backlight/pwm-backlight.0/brightness' and post the LOG file
Created attachment 4538 [details] echo 128> ...
Created attachment 4544 [details] echo 128 > ... In LOG-error, there is something interesting in line 48: fcntl64(128, F_DUPFD, 10) = -1 EBADF (Bad file descriptor) dup2(3, 128) = 128 close(3) = 0 wait4(-1, 0x7e8fa6dc, WNOHANG, NULL) = -1 ECHILD (No child processes) write(1, "\n", 1) = 1 close(128) = 0 In LOG-ok, this looks like: fcntl64(1, F_DUPFD, 10) = 10 dup2(3, 1) = 1 close(3) = 0 wait4(-1, 0x7ecc66dc, WNOHANG, NULL) = -1 ECHILD (No child processes) write(1, "128\n", 4) = 4 dup2(10, 1) = 1 close(10) = 0
Small correction, though you probably noticed it already. Problem actually occurs similarly in normal files and sysfs. Instead, there is something special in the way ash handles numbers that are not separated from ">" character with a whitespace: Both of these do not work as expected: # echo 66> /sys/class/backlight/pwm-backlight.0/brightness # echo 66>/tmp/world # cat /tmp/world #
I tested this again with bash on my PC and it seems to behave exactly the same (dealing numbers as file handles?). Nothing strange in it after all. Maybe should have given it a bit more thought before reporting :)