Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbenv help: fix 'type: write error: Broken pipe' #1195

Merged

Conversation

FooBarWidget
Copy link
Contributor

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'.

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'.
Copy link
Member

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, thank you! I've never came across this, but then again, I don't have gawk installed.

Which bash version do you have?

# shellcheck disable=SC2016
$(type -p gawk awk | head -1) '
"$first_awk" '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we try some less verbose approaches? e.g.

$(type -p gawk awk 2>/dev/null | head -1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirecting all stderr to /dev/null would ignore all non-broken-pipe errors, so I don't think that's a good idea.

I'm not aware of any other way (besides foo=$(command)) to fully slurp the output of a command.

If you want shorter, I can change it into this:

  local all_awks
  all_awks=$(type -p gawk awk)

  # shellcheck disable=SC2016
  $(head -1 <<<"$all_awks") '

But imo that's not clearer.

Copy link
Member

@mislav mislav Oct 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirecting all stderr to /dev/null would ignore all non-broken-pipe errors, so I don't think that's a good idea.

That's true in general, but type -p doesn't output any useful errors in case the programs listed weren't found, so I found it acceptable to silence its stderr completely. Thank you!

@FooBarWidget
Copy link
Contributor Author

FooBarWidget commented Oct 23, 2019

@mislav mislav merged commit d38d18e into rbenv:master Oct 23, 2019
@FooBarWidget FooBarWidget deleted the fix/rbenv-help-type-broken-pipe-upstream branch October 25, 2019 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants