shell – What Does Ampersand Mean at the End of a Shell Script Line?

shell

sh sys-snap.sh &

What is sh?
What is sys-snap.sh?
Why I should put & at the end of the line?
Can anyone explain the syntax?

Without the & the script won't go back to the prompt till I press Ctrl+C.
With & I can press enter and it works.

Best Answer

sh is the default Bourne-compatible shell (usually bash or dash)

sys-snap.sh is a shell script, which contains commands that sh executes. As you do not post its content, I can only guess from its name, what it does. I can find a script related to CPanel with the same file name, that make a log file with all current processes, current memory usage, database status etc. If the script starts with a shebang line (#!/bin/sh or similar), you can make it executable with chmod +x sys-snap.sh and start it directly by using ./sys-snap.sh if it is in the current directory.

With & the process starts in the background, so you can continue to use the shell and do not have to wait until the script is finished. If you forget it, you can stop the current running process with Ctrl-Z and continue it in the background with bg (or in the foreground with fg). For more information, see job control

Related Question