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

bash script passed to stdin fails after first gum call, unless wrapped in other control flow #447

Open
taigrr opened this issue Nov 3, 2023 · 2 comments

Comments

@taigrr
Copy link

taigrr commented Nov 3, 2023

To Reproduce
Steps to reproduce the behavior:
put the following into script.sh:

#!/usr/bin/env bash

A=$(gum input --prompt='AAA: > ' --value='aaa')
B=$(gum input --prompt='BBB: >' --value='bbb')

then run cat script.sh | bash and see that only the first prompt runs.
(if you just run ./script.sh the script behaves as expected.)

Expected behavior
Both prompts should run, and the script should behave the same way when piped as when executed directly.

Similarly:

#!/usr/bin/env bash

A=$(gum input --prompt='AAA: > ' --value='aaa')
echo $A
echo "you won't see $A or this line print out"

Desktop (please complete the following information):

  • OS: Linux

Additional context
The script will work if you wrap it in additional control flow:

#!/usr/bin/env bash
if true; then
A=$(gum input --prompt='AAA: > ' --value='aaa')
B=$(gum input --prompt='BBB: >' --value='bbb')
fi

Relevant discord thread

@piero-vic
Copy link
Contributor

This happens because gum input also reads from stdin to set the value. In this case it's reading the part of the content of script.sh. Try run the script without setting the value of gum input.

#!/usr/bin/env bash

A=$(gum input --prompt='AAA: > ')
B=$(gum input --prompt='BBB: >')

You will probably see this.

out

You can use process substitution if you really need the redirection. It works for me.

bash <(cat script.sh)

@taigrr
Copy link
Author

taigrr commented Nov 4, 2023

Thanks, but I think you might be describing a different issue. I'm not seeing STDIN eaten. In the coming days I can post a gif.

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