jsvisa
jsvisa

Reputation: 3197

How to run shell command in background with multiple commands in one line

I want to run multiple commands in one line, and one of them have to run in background.

Script like that:

cd /tmp; python -m SimpleHTTPServer &; echo "Hello"

I want to cd to /tmp directory, and then brings up the python simplehttpserver in the background, on the same time run echo "Hello", but it turns out

 syntax error near unexpected token `;'

What should I do?

Upvotes: 1

Views: 673

Answers (1)

Luis
Luis

Reputation: 1235

  • The & is already separator in sh/bash. Does this do what you want?

    cd /tmp; python -m SimpleHTTPServer & echo "Hello"

  • You can also try eval

    cd /tmp; eval "python -m SimpleHTTPServer &" ; echo "Hello"

Upvotes: 1

Related Questions