Why do I get a "Permission denied" error with the following script:


if [ -z $1 ]; then
    echo "no argument given"
    exit 1

for i in /sys/class/rc/rc*; do
    if [ -e "$i/device/driver/$1" ]; then
      number=echo $i | sed 's%/sys/class/rc/rc([0-9]+)%$0%'
      echo "found $number"

What I would expect to happen is that $number contains the "digit" value of the path /sys/class/rc/rc[0-2], instead, the "echo" command seems to try to cat the file /sys/class/rc/rc[0-2].

In particular, if /sys/class/rc/rc1/device/driver/pwm-ir-transmitter exists, the output of

lircprobe pwm-ir-transmitter


/usr/local/sbin/lircprobe: 10: /usr/local/sbin/lircprobe: /sys/class/rc/rc1: Permission denied

(lircprobe is the name of the script, above)

  • Which OS are you using? Are you sure you hare read permissions on /sys/class/rc/rc1? – Scottie H Jun 4 at 22:46

Something I see right off:
number=echo $i | sed 's%/sys/class/rc/rc([0-9]+)%$0%' The shell does not know to execute that as a command and store the output in the variable number. Try this instead:
number=`echo $i | sed 's%/sys/class/rc/rc([0-9]+)%$0%' `
number=$( echo $i | sed 's%/sys/class/rc/rc([0-9]+)%$0%' )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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