Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

Is there a way I can execute an application from a shell script but not create another process. I want it to look like one process only. It doesn't matter whether my shell script is replaced by a new process or whether it will continue after a called application ends.
This should also solve my previous question: Is there a way to associate additional application launcher with an app?
Thank you very much for your help.

share|improve this question
up vote 2 down vote accepted

You can use the exec command:

$ 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.

      -a name   pass NAME as the zeroth argument to COMMAND
      -c        execute COMMAND with an empty environment
      -l        place a dash in the zeroth argument to COMMAND

    If the command cannot be executed, a non-interactive shell exits, unless
    the shell option `execfail' is set.

    Exit Status:
    Returns success unless COMMAND is not found or a redirection error occurs.


user@host:~$ PS1="supershell$ "
supershell$ bash
user@host:~$ PS1="subshell$ "
subshell$ exec echo hello

As you can see, the subshell is replaced by echo.

share|improve this answer
Thank you for your answer. I can run e.g. this: "exec -a firefox gedit &" and so gedit appears in a launcher as Firefox. But it does not work for the majority of apps. – zubozrout Jan 26 '13 at 9:49
The problem is most probably in the fact that although I created a new process it uses both names, the original one and a newly defined one. PS output: 1000 6151 0.0 0.0 13720 944 pts/2 R+ 10:49 0:00 grep --color=auto firefox | 10006153 0.0 0.0 13716 940 pts/2 S+ 10:49 0:00 grep --color=auto gedit – zubozrout Jan 26 '13 at 9:52
May I ask why are you using & at the end of your command? That will run the command in a subshell, which is exactly what you do not want. – Andrea Corbellini Jan 26 '13 at 10:04
Yes, I was just trying it in the terminal, not a shell script. – zubozrout Jan 26 '13 at 10:05
So, I read your previous question and it looks like you are misunderstanding some things. You are confusing process with zeroth argument with PID with dash launcher. And you are also asking the wrong question. What you want to ask is first: how does the dash associate launchers to processes? Once you find the answer to that question, you'll also find an answer to your original question. – Andrea Corbellini Jan 26 '13 at 10:17

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.