Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 853 Bytes

SC3001.md

File metadata and controls

46 lines (34 loc) · 853 Bytes

Pattern: Use of process substitution

Issue: -

Description

Process substitution is a ksh and bash extension. It does not work in sh or dash scripts.

The easiest fix is to switch to a shell that does support process substitution, by changing the shebang to #!/bin/bash or ksh.

Example of incorrect code:

#!/bin/sh
while IFS= read -r n
do
  sum=$((sum+n))
done < <(program)

Example of correct code:

#!/bin/bash
while IFS= read -r n
do
  sum=$((sum+n))
done < <(program)

Alternatively, process substitution can often be replaced with temporary files:

#!/bin/sh
tmp="$(mktemp)"
program > "$tmp"
while IFS= read -r n
do
  sum=$((sum+n))
done < "$tmp"
rm "$tmp"

Further Reading