Paddy
Paddy

Reputation: 195

& after bash command

I'm not sure what the & after the command in this bash script is doing.

    python alt_pg ${args} &

Also the original version of the script that I'm modifying does not use 'python' at the start of the command is that something to do with the '&'?

Upvotes: 0

Views: 327

Answers (3)

user743382
user743382

Reputation:

No, they're two separate things.

Running python alt_pg ... means python will be looked up in $PATH, and alt_pg ... will be passed as arguments to python. Python then looks for a file named alt_pg. Running alt_pg ... means alt_pg will be looked up in $PATH. The latter may cause python to run anyway, depending on what alt_pg does.

Adding a & after the command means the command runs in the background, and the shell can continue with commands that follow even when alt_pg is still running.

Upvotes: 3

Mike Pennington
Mike Pennington

Reputation: 43077

& at the end of the line runs python alt_pg ${args} in the "background" under your linux shell; however, the script is still associated with the shell. Therefore, if the shell stops, so does the script.

Side note: You can disassociate the script from your shell by using nohup python alt_pg ${args} &. If you spawn the script like this, the script persists after logging out of the shell.

Upvotes: 7

Kevin Mangold
Kevin Mangold

Reputation: 1155

The ampersand runs the process in a forked/background process.

Upvotes: 3

Related Questions