[bash/en] Add info on background commands with & (#4120)

* Add info on background commands with &

* Update bash.html.markdown
This commit is contained in:
Michael Chen 2022-01-03 12:00:53 -05:00 committed by GitHub
parent 3b2974ba31
commit 5f118e3f61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -179,6 +179,19 @@ echo "Always executed" && echo "Only executed if first command does NOT fail"
# => Always executed # => Always executed
# => Only executed if first command does NOT fail # => 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: # To use && and || with if statements, you need multiple pairs of square brackets:
if [ "$Name" == "Steve" ] && [ "$Age" -eq 15 ] if [ "$Name" == "Steve" ] && [ "$Age" -eq 15 ]