summaryrefslogtreecommitdiffhomepage
path: root/bash.html.markdown
diff options
context:
space:
mode:
authorMichael Chen <flamingdescent@gmail.com>2022-01-03 12:00:53 -0500
committerGitHub <noreply@github.com>2022-01-04 01:00:53 +0800
commit5f118e3f612ab4704e2e9f4dd534fa0cc2cc627a (patch)
treef963e6678695a5e2650e0284f464e656498cbd55 /bash.html.markdown
parent3b2974ba31afb6363e54678546d6742aadd34076 (diff)
[bash/en] Add info on background commands with & (#4120)
* Add info on background commands with & * Update bash.html.markdown
Diffstat (limited to 'bash.html.markdown')
-rw-r--r--bash.html.markdown13
1 files changed, 13 insertions, 0 deletions
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 ]