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

Only first line of a function’s output gets passed through pipe #860

Open
sultanqasim opened this issue Dec 4, 2024 · 1 comment
Open

Comments

@sultanqasim
Copy link

sultanqasim commented Dec 4, 2024

When you pipe the output of a multi-line function (in a shell script), only the first line’s output goes into the pipe, and the rest goes direct to stdout. This is the second issue I had pointed out in #859. The difference between quoted and unquoted versions of the variable I pointed out earlier was a red herring because echoing an unquoted multi-line variable is supposed to replace the newlines with spaces when being displayed.

Reproduction script:

#! /bin/sh

foo() {
        printf "baa "
        printf "caa "
        printf "daa "
}

foo | tr 'a' 'z'
printf "\n"

Expected output:

bzz czz dzz

a-Shell output:

caa daa bzz
@holzschu
Copy link
Owner

holzschu commented Dec 4, 2024

Thank you for opening this issue. Unlike #859, this one is going to take a longer time to fix. I know roughly where it happens, but not why. The standard output that is piped into the command is closed after the first line of the function; trying to keep it open results in a lot of undesirable behaviour in other places. I'll keep working on it, but it's a tough one.

@sultanqasim sultanqasim changed the title Only first line of a function output gets passed through pipe Only first line of a function’s output gets passed through pipe Dec 4, 2024
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

No branches or pull requests

2 participants