From 5f118e3f612ab4704e2e9f4dd534fa0cc2cc627a Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Mon, 3 Jan 2022 12:00:53 -0500 Subject: [bash/en] Add info on background commands with & (#4120) * Add info on background commands with & * Update bash.html.markdown --- bash.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bash.html.markdown b/bash.html.markdown index 8813464e..d7d7d584 100644 --- a/bash.html.markdown +++ b/bash.html.markdown @@ -179,6 +179,19 @@ echo "Always executed" && echo "Only executed if first command does NOT fail" # => Always executed # => Only executed if first command does NOT fail +# A single ampersand & after a command runs it in the background. A background command's +# output is printed to the terminal, but it cannot read from the input. +sleep 30 & +# List background jobs +jobs # => [1]+ Running sleep 30 & +# Bring the background job to the foreground +fg +# Ctrl-C to kill the process, or Ctrl-Z to pause it +# Resume a background process after it has been paused with Ctrl-Z +bg +# Kill job number 2 +kill %2 +# %1, %2, etc. can be used for fg and bg as well # To use && and || with if statements, you need multiple pairs of square brackets: if [ "$Name" == "Steve" ] && [ "$Age" -eq 15 ] -- cgit v1.2.3