This question already has an answer here:

So I have an executable (output of gcc compiling a C program), that I would like to run after login so it is the first thing a user sees upon login. It is a graphical menu that displays system information (read only).

After experimenting around with /.profile, by simply adding the following bash command with the path to the executable

exec /home/TUI/bin/main 

I was able to get my program to run and display the UI after login, but then upon exiting, I am continually prompted to login again in a loop and the process repeats over and over. I believe I am not putting the script in the right location. Would it go in /etc/rc.local? ~/.bashrc ... ?

What would be the best way to go about getting the program to run after a user logs in? Please bare with me, I'm not very experienced with shell scripting and the initialisation process of ubuntu. Thanks in advance!

marked as duplicate by Byte Commander, David Foerster, Eric Carvalho, amc, Zanna Jul 20 '16 at 18:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    exec is used to replace the current shell with a command! Omit the exec and only run the script. – Byte Commander Jul 19 '16 at 18:10
  • Thanks! It was the exec! Is there a difference in doing something like this vs the command line approach to the link above? It seems to me doing the autostart approach would involve making a .desktop file, whereas this is one line... – Funsaized Jul 19 '16 at 18:19
  • The startup-application tool only wants a command, not a .desktop launcher. I don't know about the differences, maybe it's described in one of the answers in the duplicate question? – Byte Commander Jul 19 '16 at 18:21

The problem in your approach is that you use exec.

$ help exec
exec: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
    Replace the shell with the given command.

    Execute COMMAND, replacing this shell with the specified program.
    ARGUMENTS become the arguments to COMMAND.  If COMMAND is not specified,
    any redirections take effect in the current shell.


If you omit the exec and simply run your executable as shown below, your login session should not terminate when you close the application.

exec /home/TUI/bin/main 

However, see How do I start applications automatically on login? for alternative (and possibly easier) approaches to autostart applications on login.

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