4

How can I run a command at the background in Bash without ampersand (&) at the end of a command?

Update: I want to do it so I can do while inotifywait -e modify app.py; do killall -9 python; python app.py &; done, but that isn't possible because of the syntax.

2
  • Please edit and explain what you are trying to do. The & is the way to run a command in the background. Why don't you want to use it? Do you want to send an already launched command to the background? – terdon Oct 25 '15 at 16:41
  • @Jos my & key isn't broken and @terdon I updated the question – wb9688 Oct 26 '15 at 6:17
4

Use coproc python app.py

From man bash

Coprocesses

A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the & control operator, with a two-way pipe estab‐ lished between the executing shell and the coprocess.

The format for a coprocess is:

coproc [NAME] command [redirections]

2

Your syntax is slightly off:

while inotifywait -e modify app.py; do killall -9 python; python app.py &; done

It should be:

while inotifywait -e modify app.py; do killall -9 python; python app.py & done

Unlike C-like languages, you cannot have an empty statement before ; or &.

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