From b08fc0727a7086560b9cd9217fdab5d07ffee45f Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Tue, 13 Feb 2024 00:36:48 +0100 Subject: bash: cmd grouping --- src/tools/bash.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/tools/bash.md b/src/tools/bash.md index a2b7944..e12d8c0 100644 --- a/src/tools/bash.md +++ b/src/tools/bash.md @@ -112,6 +112,22 @@ once. vim -d <(grep foo bar) <(grep foo moose) ``` +## Command grouping + +Execute commands in a group with or without subshell. Can be used to easily +redirect stdout/stderr of all commands in the group into one file. +```bash +# Group commands without subshell. +v=abc ; { v=foo; echo $v; } ; echo $v +# foo +# foo + +# Group commands with subshell. +v=abc ; ( v=foo; echo $v; ) ; echo $v +# foo +# abc +``` + ## Argument parsing with `getopts` The `getopts` builtin uses following global variables: -- cgit v1.2.3