Search code examples
linuxshellterminalraspberry-piraspbian

Raspbian: start program from .sh file


I want to do this:

  • Execute an executable from a .sh file
  • Keep this executable open in terminal

I tried to write a .sh file with "./program" but "program" closes automatically after flashing a console, but I want that terminal to keep open!


Solution

  • I assume you are in a graphical environment, and want to execute a script by double-clicking the ".sh" file, then keep the terminal window open to see any result.

    At the end of your script, add something like this :

    echo "Hit the [return] key to exit"
    read
    

    This will cause execution to pause until you hit [return].

    Note : you cannot keep a program running when it has finished executing. So the program you are calling from your script finishes, but then you give the terminal (which is also a program) something to do (waiting for input) to prevent it from closing.