Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Having the same issue while trying to do the same thing. I've tried things like function brightness { bright=$1; sudo su -c 'echo "$bright" > /sys/class/backlight/acpi_video0/brightness'; } too, but I still haven't figured it out. – hangtwenty Nov 2 '12 at 12:15
up vote 1 down vote accepted

Try echo "$1" > /sys/class/backlight/acpi_video0/brightness.

I bet the shell is expanding $1 and thus echo thinks it is receiving a bunch of arguments, rather than a string.

share|improve this answer

You should check what the actual value of $1 is. This error means you are trying to write an invalid value -- either it's out of range or just in general not a meaningful value.

At a glance, it appears that it accepts an integer in the range 0 to 8 (for me at least).

share|improve this answer

Try using let



if [ $# -eq "0" ]
        echo 100 > $POLKU
        let gg=$1
        echo $gg > $POLKU
share|improve this answer

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:


from sys import *

PATH = "/sys/class/backlight/intel_backlight/brightness"

if len(argv) != 2:
    print("Usage: <brightness>")

    brightness = int(argv[1])
    if not 0 <= brightness <= 825:
        raise Exception()
    print("<brightness> must be an integer between 0 and 825.")

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":
elif brightness <= 5:
    with open(PATH, "r") as f:
        oldBrightness = int(
        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":

    with open(PATH, "w") as f:
    print("Failed to write to file. Are you root?")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.