How do I get the state of a pin and store it in a variable in a script?
You could try something like this if you are wired to pin 0 (as referred to in this site https://projects.drogon.net/raspberry-pi/wiringpi/pins/), which will read the pin once, set the variable "b", echo to console and exit.
#!/bin/bash # Set the pin for input gpio mode 0 in # Set the variable through command substitution b=$(gpio read 0) # Echo the value to the console echo "$b"
This gives examples of how to read the value of a GPIO pin.
I am not sure how to set a value in a script I would try
export PIN=`cat /sys/class/gpio/gpio7/value`
I don't know why you would want to do this, as it would seem more logical to read the current value each time.
The section following in the link shows how to use gpio, which is much easier to use.