I'm sure this has been answered before but I can't seem to find the solution that works.

I am running the latest Raspbian on an RPi 3. I created a bash script named "loop.sh" that loops through two videos. When the first video is playing, a gpio pin sends out a high signal. Once the video is over the signal goes low, it sleeps for a minute and then plays the second video with the same gpio pin going high again and low once the video is over. All of this is within an infinite loop to keep on playing the same two videos with the gpio pin going high to low.

The script works fine when I "manually" start it, but my issue comes when I try to autostart the script (where I will have the RPi installed for the project I won't have access to keyboard or mouse to "manually" start the script).

Right now I have the script at the end of .bashrc and when I power up the pi nothing happens until I open a terminal window, so I added @lxterminal to the autostart file (sudo nano ~/.config/lxsessions/LXDE-pi/autostart). When I reboot the pi like this two instances of the script run at about 5 seconds apart.

Any help to fix this issue will be appreciated as it is the last thing I need to finish this project.

You DO NOT launch scripts with .bashrc which is run EVERY TIME you launch a non-login shell and is used to configure the shell.

You need to put your script in /etc/rc.local. This script runs once when the OS starts. It runs irrespective of id any user logs into the system or not. Raspberry pi manual describes it in detail here.

The .bashrc file is used to setup your bash shell environment when you login into bash shell. .bashrc does not execute if you don't login into bash shell.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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