From 3748ffe6d12eafef1d99358f434eb9667bfabf3f Mon Sep 17 00:00:00 2001 From: dunatotatos Date: Sun, 18 Sep 2016 18:50:50 +0300 Subject: [PATCH] Add a POSIX solution without a subshell --- SC2013.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SC2013.md b/SC2013.md index f5b5c88..74c2818 100644 --- a/SC2013.md +++ b/SC2013.md @@ -27,6 +27,17 @@ do done < <(grep -v '^ *#' < file) ``` +or without a subshell, with a pipe (more portable, but write a file on the filesystem): + +```sh +mkfifo mypipe +while IFS= read -r line +do + echo "Line: $line" +done < mypipe +rm mypipe +``` + ### Rationale: For loops by default (subject to `$IFS`) read word by word. Additionally, glob expansion will occur.