From d38d18ec25736bfdf4c8739c7b40ec96c10fd0f3 Mon Sep 17 00:00:00 2001 From: Hongli Lai Date: Wed, 23 Oct 2019 08:19:16 +0200 Subject: [PATCH] rbenv help: fix 'type: write error: Broken pipe' Sometimes the command fails with a 'type: write error: Broken pipe'. This is because 'head -1' only reads the first line, then exits. If 'type' writes the second line after 'head -1' has already exited, then the aforementioned error is triggered. We fix this by buffering the entire output of 'type' before invoking 'head -1'. --- libexec/rbenv-help | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-help b/libexec/rbenv-help index 0b7e926a..d1296d62 100755 --- a/libexec/rbenv-help +++ b/libexec/rbenv-help @@ -42,8 +42,13 @@ extract_initial_comment_block() { } collect_documentation() { + local all_awks + local first_awk + all_awks=$(type -p gawk awk) + first_awk=$(head -1 <<<"$all_awks") + # shellcheck disable=SC2016 - $(type -p gawk awk | head -1) ' + "$first_awk" ' /^Summary:/ { summary = substr($0, 10) next