I'm trying to get a .sh script to run on system start-up. I've tried it several ways that don't work. The closest I got was using adding a line to /home/pi/bashrc

sh /home/pi/Desktop/run.sh &

This little script just starts up feh with a few parameters and restarts feh in case it crashes (which it does all the time but that's another issue).

The above runs run.sh but only under root and in the background. I can see that in the task manager.

What do I need to do to run run.sh under the pi user account and in the foreground? I'm puzzled.

  • "adding a line to /home/pi/bashrc" -> Worst ever method (for which I'm not blaming you, it seems to be an anti-pattern that has infected the Pi user community thanks I presume to blogs written by very unqualified people, and unfortunately, the same phenomenon here). Don't use .bashrc this way, it will come back to bite you. It isn't run specifically at system boot, it's run "When an interactive shell that is not a login shell is started" (man bash), which may (or may not) happen at boot, but is likely to include other events as well.
    – goldilocks
    Aug 10, 2019 at 14:37
  • Yes, I experienced that first hand! Ain't no good. Amazing how that's repeated everywhere, often enough so I couldn't find a correct answer by bingoogling.
    – Peete
    Aug 10, 2019 at 22:35

1 Answer 1


To run the script in the foreground as PI user on startup, type the following commands in terminal to create a file run.desktop in ~/.config/autostart

cd ~/.config/autostart

nano run.desktop

Now, paste the following code in run.desktop:

[Desktop Entry]
Exec=lxterminal -e "/home/pi/Desktop/run.sh"

Save the file by pressing CTRL + O and then CTRL + X.

  • Good answer, but you don't need to include the nano usage stuff, it's at best clutter and at worst confusing. It's pretty obvious from the question the OP is capable of creating and editing text files on the Pi.
    – goldilocks
    Aug 10, 2019 at 14:40
  • Thanks for pointing me in the right direction. It didn't work at first (it just brings up the terminal, the calls inside run.sh are not executed, I cannot even see them in the task manager. The terminal window is entirely blank). However, when I changed the Exec line to bash -c "sh /home/pi/Desktop/run.sh" it worked! --- Any insights to why this worked for me and not the lxterminal -e command?
    – Peete
    Aug 10, 2019 at 23:35
  • Perhaps if the script did not have a shebang and/or was not marked executable?
    – goldilocks
    Aug 11, 2019 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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