From 5999174bfcf877fcafc4161c49428010607573fe Mon Sep 17 00:00:00 2001 From: Jordan Christiansen Date: Wed, 1 Sep 2021 11:10:08 -0500 Subject: [PATCH] Add normal pipes as a possible alternative --- SC3001.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SC3001.md b/SC3001.md index cfb7008..132653f 100644 --- a/SC3001.md +++ b/SC3001.md @@ -39,6 +39,16 @@ rm "$tmp" If streaming is important, the temporary file can be a named pipe, and the producer or consumer can be run as a background job. +If the reading command accepts input from standard input, the process substitution can be replaced with a regular pipe: + +```sh +#!/bin/sh +program | while IFS= read -r n +do + sum=$((sum+n)) +done +``` + ### Rationale: Process substitution is a ksh and bash extension. It does not work in sh or dash scripts.