Skip to main content
2 of 3
added 9 characters in body
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

The $1 in the sh -c script will expand to the first command line argument of that script, not to the first command line argument of the calling script (since the sh -c script is single quoted).

The correct solution is not to inject the value of $1 from the calling script into the sudo script (this would allow for various interesting code injection vulnerabilities), but to pass $1 from the outer script to the inner:

sudo sh -c 'printf "%s\n" "$1" > /sys/class/backlight/intel_backlight/brightness' sh "$1"

Alternatively, use sudo tee to write to the file as root:

printf '%s\n' "$1" | sudo tee /sys/class/backlight/intel_backlight/brightness >/dev/null
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k