I'm doing something along these lines:
declare -Ft handle_format_output &>/dev/null && exit 1 # test if this function name is already present in this scope
handle_format_output() {
case $1 in
domain) ./scripts/idn_to_punycode.pl >>"${2}_${1}.txt" ;;
ipv4)
# read doesn't bother w/ pipe input as its undefined: guessing it's leading to pipe breaks
# therefore open stdin as a separate file and read from it to close the previous pipe
while IFS= read -r line <&3; do
case $line in
*/*) printf "%s\n" "$line" >>"${2}_${1}_cidr.txt" ;; # cidr block
*-*) ipcalc "$line" >>"${2}_${1}_cidr.txt" ;; # deaggregate ip range
*) printf "%s\n" "$line" >>"${2}_${1}.txt" ;; # ip address
esac
done 3< /dev/stdin
;;
ipv6) cat -s >>"${2}_${1}.txt" ;;
esac
}
... |
mawk '!seen[$0]++' | # filter duplicates and blank lines
handle_format_output "$format" "$color"
Where the input is linear text that's either a web domain, IPv4 address, IPv4 CIDR block, or IPv6 address. The format is either "domain," "ipv4," or "ipv6." The color is either "white" or "black."
This error keeps being thrown no matter what I'm trying:
mawk: write failure (Broken pipe)
mawk: close failed on file /dev/stdout (Broken pipe)
Error: Process completed with exit code 2.
What am I doing wrong?
$formatand$color? (please double check these and mention them in the question).$formatis actually exactly the stringipv4and nothing else (no trailing spaces or newline etc.)? You seem to think there's something wrong with yourreadcall, so the first step is to make sure that the code actually gets there. If$formatis a string that is not one of the three that you test for, the code will fall through thatcasestatement and you'll get the behavior that you describe. You may therefore want to add a*)case that just printserror!or something, for debugging.