Why can't I use
echo $1 > /sys/class/backlight/acpi_video0/brightness in a simple bash script?
It gives me the error:
echo: write error: Invalid argument.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
That file is a special file. It cannot be written to if what is written is not solely a number. If you try writing a number with
echo, you will get a newline character at the end.
echo -n solves the problem.
EDIT: Also, you might having the problem which I just had; that you need to be root and
sudo won't help you for whatever reason, making it very tedious to type
su; <your command>;
exit all the time. For this I made an (overly ambitious) python script:
#!/usr/bin/python from sys import * PATH = "/sys/class/backlight/intel_backlight/brightness" if len(argv) != 2: print("Usage: bright.py <brightness>") exit() try: brightness = int(argv) if not 0 <= brightness <= 825: raise Exception() except: print("<brightness> must be an integer between 0 and 825.") exit() if brightness == 0: readString = raw_input("A value of 0 will turn off your screen. Are you sure you want to continue? [y/N] ") if readString != "y": exit() elif brightness <= 5: with open(PATH, "r") as f: oldBrightness = int(f.read()) if brightness < oldBrightness: readString = raw_input("A value of %i will make your screen very dark. Are you sure you want to continue? [y/N] " % brightness) if readString != "y": exit() try: with open(PATH, "w") as f: f.write(str(brightness)) except: print("Failed to write to file. Are you root?") exit()