0

I tried this simple test

ping [SOME IP] &;ls

expecting the output of ping to overlap with the listing.

Instead, I got an error:

bash: syntax error near unexpected token `;'

It does not help adding spaces. If the semicolon is escaped, the first command starts, then error

;: command not found

It almost works to enclose the ping in brackets

(ping [SOME IP] &);ls

The ls runs to completion, then the ping starts. I could achieve that more easily by typing

ls;ping ...

Is it possible to start two processes together, when the first (or both) are in the background?

1
  • It's even simpler: ping [SOME IP] & ls. To start both in the background, append a &. Commented Feb 20 at 9:40

2 Answers 2

3

They can't be run together because they do the same thing in this context: both & and ; act as list terminators indicating the end of a command. You can start a new command after either of them, so there is no need to use both.

So, to send one command to the background and immediatey launch another, you just do:

command1 & command2 

That's it.

1

&; is not valid bash syntax. the & is use to run a command in the background, the ; is used to separate commands. & already ends the command, a ; immediately after is incorrect

Why did ; after & return an unexpected token error in bash?

Syntax error near unexpected token `;' when running a command in Bash

You can use simple:

ping [SOME IP] & ls

or with a subshell

(ping [SOME IP] &) && ls

Do parentheses really put the command in a subshell?

Start subshells with assignment and wait for that

That should also work with grouping:

{ ls & ping [SOME IP]; }

execute set of commands in group by {} vs ()

Difference between parentheses and braces in terminal?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.