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

tee doesn't work within a loop #12862

Closed
YuanYuYuan opened this issue May 14, 2024 · 5 comments
Closed

tee doesn't work within a loop #12862

YuanYuYuan opened this issue May 14, 2024 · 5 comments
Labels
question the issue author asks something

Comments

@YuanYuYuan
Copy link

YuanYuYuan commented May 14, 2024

Question

Hi there! I have a question about tee's behavior

echo "hello" | tee { save -a hello.log }

produces

───┬───────
 0 │ hello
───┴───────

But

for idx in 1..5 { echo "hello" | tee { save -a hello.log } }

prints nothing.

Both of them do save the message(s) into hello.log. Any advice would be greatly appreciated!

Additional context and details

No response

@YuanYuYuan YuanYuYuan added the question the issue author asks something label May 14, 2024
@fdncred
Copy link
Collaborator

fdncred commented May 14, 2024

Any ideas/thoughts @devyn?

@devyn
Copy link
Contributor

devyn commented May 14, 2024

I believe this is an issue with expressions in for, as they don't print (even on the REPL) in that case. If you use an explicit print, it should work:

> for idx in 1..5 { echo "hello" | tee { save -a hello.log } | print }
╭───┬───────╮
 0  hello 
╰───┴───────╯

╭───┬───────╮
 0  hello 
╰───┴───────╯

╭───┬───────╮
 0  hello 
╰───┴───────╯

╭───┬───────╮
 0  hello 
╰───┴───────╯

╭───┬───────╮
 0  hello 
╰───┴───────╯

Of course, at the moment, the tee command expects a stream, so your input gets converted to a list to make that happen. I will probably patch that sometime soon, as there really shouldn't be any difference between a text stream and a string.

@fdncred
Copy link
Collaborator

fdncred commented May 14, 2024

Right, for uses blocks and each uses closures. So, with each you can do this similar pipeline.

1..5 | each { echo "hello" | tee { save -a hello.log } }

@arnfaldur
Copy link

This issue can be closed.

@fdncred
Copy link
Collaborator

fdncred commented May 20, 2024

Thanks, ping us on discord if this needs to be reopened.

@fdncred fdncred closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question the issue author asks something
Projects
None yet
Development

No branches or pull requests

4 participants