From ff4b3db9cbdc15b3d3ffc854be867d88e4cff0da Mon Sep 17 00:00:00 2001 From: CoolOppo Date: Wed, 27 Jun 2018 21:39:04 -0400 Subject: [PATCH 1/3] Added background commands The syntax looks ugly, but this is the optimal way to do it. It doesn't have any extraneous output due to the parenthesis surrounding the command, and also sends error output to /dev/null. --- manuscript/chapter19.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/manuscript/chapter19.txt b/manuscript/chapter19.txt index f575993..c903ef0 100644 --- a/manuscript/chapter19.txt +++ b/manuscript/chapter19.txt @@ -186,5 +186,16 @@ ls command ls ``` - +## Run a command in the background +This will run the given command and keep it running even after the terminal is closed. + +```sh +bkr() { + (nohup "$@" &>/dev/null &) +} + +bkr ./some_script.sh # some_script.sh is now running in the background +``` + + From dd9a4ee4383957eaa347bc27e37be8b8efa6238e Mon Sep 17 00:00:00 2001 From: CoolOppo Date: Thu, 28 Jun 2018 04:35:32 -0400 Subject: [PATCH 2/3] Update README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 82a4813..6754b39 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ See something that is incorrectly described, buggy or outright wrong? Open an is * [Get the list of functions in a script](#get-the-list-of-functions-in-a-script) * [Bypass shell aliases](#bypass-shell-aliases) * [Bypass shell functions](#bypass-shell-functions) + * [Run a command in the background](#run-a-command-in-the-background) * [AFTERWORD](#afterword) @@ -1978,6 +1979,18 @@ ls command ls ``` +## Run a command in the background + +This will run the given command and keep it running, even after the terminal or SSH connection is terminated. All output is ignored. + +```sh +bkr() { + (nohup "$@" &>/dev/null &) +} + +bkr ./some_script.sh # some_script.sh is now running in the background +``` + # AFTERWORD From 5f0c65e7a3e9a88fe7590302ddce0a60c9d7d76f Mon Sep 17 00:00:00 2001 From: CoolOppo Date: Thu, 28 Jun 2018 04:40:27 -0400 Subject: [PATCH 3/3] properly built manuscript --- manuscript/chapter1.txt | 2 +- manuscript/chapter10.txt | 4 ++-- manuscript/chapter19.txt | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/manuscript/chapter1.txt b/manuscript/chapter1.txt index 157ae20..6bfb4f4 100644 --- a/manuscript/chapter1.txt +++ b/manuscript/chapter1.txt @@ -366,7 +366,7 @@ if [[ "$var" == *sub_string ]]; then printf '%s\n' "var ends with sub_string." fi -# Inverse (var does not start with sub_string). +# Inverse (var does not end with sub_string). if [[ "$var" != *sub_string ]]; then printf '%s\n' "var does not end with sub_string." fi diff --git a/manuscript/chapter10.txt b/manuscript/chapter10.txt index d7d7ac4..d24cb26 100644 --- a/manuscript/chapter10.txt +++ b/manuscript/chapter10.txt @@ -32,8 +32,8 @@ | Expression | What does it do? | | ---------- | ---------------- | | `file -ef file2` | If both files refer to the same inode and device numbers. -| `file -nt file2` | If `file` is newer than `file2` (*uses modification ime*) or `file` exists and `file2` does not. -| `file -ot file2` | If `file` is older than `file2` (*uses modification ime*) or `file2` exists and `file` does not. +| `file -nt file2` | If `file` is newer than `file2` (*uses modification time*) or `file` exists and `file2` does not. +| `file -ot file2` | If `file` is older than `file2` (*uses modification time*) or `file2` exists and `file` does not. ## Variable Conditionals diff --git a/manuscript/chapter19.txt b/manuscript/chapter19.txt index c903ef0..ade89b2 100644 --- a/manuscript/chapter19.txt +++ b/manuscript/chapter19.txt @@ -188,7 +188,7 @@ command ls ## Run a command in the background -This will run the given command and keep it running even after the terminal is closed. +This will run the given command and keep it running, even after the terminal or SSH connection is terminated. All output is ignored. ```sh bkr() { @@ -199,3 +199,4 @@ bkr ./some_script.sh # some_script.sh is now running in the background ``` +