Elektrine lite

← Feed

@rauschma@fosstodon.org

Post #1802366

2026-04-26 17:07 UTC

Shell programming question: Consider the following shell command. pbpaste | my-script | pbcopy Problem: If an error happens the the clipboard is empty afterwards. Solution(?) If an error happens, my-script sends what it read from stdin to stdout. Not particularly elegant but it does the job. Is there anything better, more “idiomatic”?

Replies (2)

  • @bruderstein@hachyderm.io 2026-04-26 17:37

    @rauschma@fosstodon.org `set -o pipefail` then if my-script returns non-zero there is an error thrown.

    Open ##4374223

  • @pcdevil@mastodon.social 2026-04-26 17:44

    @rauschma@fosstodon.org I feel like `my-script` should execute `pbpaste` inside, transform its output, then on success, pipe it to `pbcopy` itself. it wouldn't follow the Unix's philosophy per se, but neither keeping the input on error, while running the command would have a better ergonomy with a single `my-script` call! (unless this is a greatly simplified example and the setup is much more convoluted than just two pipes)

    Open ##4374228