What do the two ampersands in the following command do:
(make foo&)&
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
(and)run the command in a subshell. This means that a separate shell is spawned off and the command is run. This is probably because they wanted to use shell specific operation (backgrounding – other examples are redirection etc.). The first&in the command backgrounds the command run in the subshell (ie.make foo). The second ampersand backgrounds the subshell itself so that you get back your command prompt immediately.You can see the effects here
Foreground on the current shell
Background on the current shell
Using a subshell (Foreground)
In this case, the current shell waits for the subshell to finish even though the job in the subshell itself is backgrounded.
Using a subshell (BAckground)
The foreground shell returns immediately (Doesn’t wait for the subshell which itself doesn’t wait for the ls to finish). Observe the difference the command executed.
A sidenote on the need to run some commands in a subshell. Suppose you wanted to run a “shell command” (ie. One that uses shell specific stuff like redirects, job ids etc.), you’d have to either run that command in a subshell (using
(,)) or using the-coption to shells like bash. You can’t just directlyexecsuch things because the shell is necessary to process the job id or whatever. Ampersanding that will have the subshell return immediately. The second ampersand in your code looks (like the other answer suggests) redundant. A case of “make sure that it’s backgrounded”.