Echoing to system files in Ubuntu through sudo

As I was setting up the TrackPoint on my Z60t, I came across a problem:

sudo echo -n 1 > /sys/devices/platform/i8042/serio1/serio2/press_to_select
bash: /sys/devices/platform/i8042/serio1/serio2/press_to_select: Permission denied

I found an old message board post that said:
That's because bash tries to redirect the output of 'sudo echo' to the
/sys/... file, but since bash runs without elevated privileges, it
cannot do so.
His solution was:

echo -n 1| sudo tee /sys/devices/platform/i8042/serio1/serio2/press_to_select

Which worked like a charm. I've never run across the problem of having to echo something to a file that didn't needed root permissions to be edited. It makes sense, but it took me a couple of minutes to figure out, so I thought I'd post it in case anyone else comes across this problem. Also, `tee` may turn out to be a useful program: it reads from stdin and writes to stdout and files.

Unfortunately, I got kind of distracted, and my TrackPoint still doesn't work.

No comments: