From 9ffee9598f11c0e63c96871ff507d9514b6b7704 Mon Sep 17 00:00:00 2001 From: Philip Couling Date: Thu, 11 May 2023 11:43:15 +0100 Subject: [PATCH] Don't use pipe to replace here-string bash executes the RHS in a subshell so will break read expressions --- SC2039.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SC2039.md b/SC2039.md index f762f37..f228cc6 100644 --- a/SC2039.md +++ b/SC2039.md @@ -178,14 +178,15 @@ done Bash, ksh: ```Bash -grep aaa <<< "$g" +read aaa <<< $(grep foo bar) ``` POSIX: ```sh -# not exactly the same -- <<< adds a trailing \n if $g doesn't end with \n -printf '%s' "$g" | grep aaa +read << EOF +$(grep foo bar) +EOF ``` ### echo flags