0

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

#!/bin/sh

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

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"
    fi
done

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

is:

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

(lircprobe is the name of the script, above)

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

1 Answer 1

0

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%' `
or
number=$( echo $i | sed 's%/sys/class/rc/rc([0-9]+)%$0%' )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .