Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I call:

execl("/bin/sh", "/bin/sh", (void *) NULL);

The /bin/sh/ program is started, which opens a shell in which I can type commands. However, if I call:

execl("/bin/sh", "/bin/sh", "~/", (char *) 0 );

The /bin/sh program is also started and runs the given shell script but then closes afterwards.

Why doesn't the shell stay open after running a shell script? Is there anyway to keep it open after running the script?

Thanks in advance!

share|improve this question

This is a normal shell behaviour that doesn't have anything in common with the fact that you run it from C - it happens even if you run the shell with the script from command line:

$ sh ~/

It might be difficult to force shell to stay in interactive mode after that. I found only the --rcfile [file] option to do that:

Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below).

I.e. you would do

$ sh --rcfile ~/

But your system rc files like /etc/bash.bashrc and ~/.bashrc will not be run in this case.

share|improve this answer

How about running an interactive shell at the end of your script?


echo STUFF
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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