I have defined a bash script to prepare gpio27 for setting it to 0 or 1 through additional scripts on a RaspberryPi Zero 2 with Buster installed.
The script is the following one:
#!/bin/bash
echo "27" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio27/direction
1- If I run this script as user "pi", I get a permission denied error (NOK):
/home/pi/bin/prep27: line 3: /sys/class/gpio/gpio27/direction: Permision denied
2- If I run the conflictive line ‘echo "out" > /sys/class/gpio/gpio27/direction’ as user pi (no sudo), I get no error (OK):
echo "out" > /sys/class/gpio/gpio27/direction
3- if I replace in the script the third line by ‘sudo echo "out" > /sys/class/gpio/gpio27/direction’ and I execute the script as pi, I also get a permission denied error (NOK):
#!/bin/bash
echo "27" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio27/direction
4- if i sudo execute the script as user pi, I get no error (OK)
sudo /home/pi/bin/prep27
Could you help me understand these permission issues with the script and its contents ?
Thanks very much