From f7fb4c7303a5776ddb421d182a92f679a8b0f868 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Thu, 25 Jan 2024 08:32:42 +0100 Subject: bash/zsh/fish: add process substitution --- src/tools/bash.md | 9 +++++++++ src/tools/fish.md | 6 ++++++ src/tools/zsh.md | 12 ++++++++++++ 3 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/tools/bash.md b/src/tools/bash.md index 9150963..a2b7944 100644 --- a/src/tools/bash.md +++ b/src/tools/bash.md @@ -104,6 +104,14 @@ command 2>&1 >file 1. duplicate `fd 1` to `fd 2`, effectively redirecting `stderr` to `stdout` 2. redirect `stdout` to `file` +## Process substitution ([ref][psub]) + +Process substitution allows to redirect the stdout of multiple processes at +once. +```bash +vim -d <(grep foo bar) <(grep foo moose) +``` + ## Argument parsing with `getopts` The `getopts` builtin uses following global variables: @@ -227,3 +235,4 @@ complete -F _foo foo ``` [dup2]: http://man7.org/linux/man-pages/man2/dup.2.html +[psub]: https://tldp.org/LDP/abs/html/process-sub.html diff --git a/src/tools/fish.md b/src/tools/fish.md index 117ead2..fd1b2f7 100644 --- a/src/tools/fish.md +++ b/src/tools/fish.md @@ -87,6 +87,12 @@ echo "ls output: "(ls) echo foo >? log ``` +### Process substitution +Redirect output of multiple processes. Same as `<(..)` in bash. +```sh +diff (sort a | psub) (sort b | psub) +``` + ## Control Flow ### `if` / `else` ```sh diff --git a/src/tools/zsh.md b/src/tools/zsh.md index a1302a4..f702655 100644 --- a/src/tools/zsh.md +++ b/src/tools/zsh.md @@ -174,6 +174,18 @@ echo ${(kv)vec} # a aa b bb for k v in ${(kv)vec)}; do ...; done ``` +## I/O redirections + +See [bash - I/O redirection](bash.md#io-redirection) + +## Process substitution + +Process substitution allows to redirect the stdout of multiple processes at +once. +```bash +vim -d <(grep foo bar) <(grep foo moose) +``` + ## Argument parsing with `zparseopts` ```zsh -- cgit v1.2.3