Issue
I have a simple nginx server serving a test.sh
file
#!/bin/bash
gum input
echo hello
echo world
ls -l
If I'm doing ./test.sh
it is working file.
I can see the gum input
> Type something...
and only after I entered something and pressed enter, I can see my entered string and the script continues
Hi
hello
world
...
If I'm doing curl 127.0.0.1/test.sh | bash
, it is not working.
I have
> echo hello echo world ls -l *
ps : I replaced the caret with *
and after entering something the script does not continue
echo hello echo world ls -l hi
I don't understand what's the problem. I don't know if it is coming from nginx, from curl or from gum.
Solution
Your bash
is receiving its stdin from the pipeline and not your terminal, so you can't interact with it like a script that you run directly. You have to read from somewhere other than stdin since you are already using that for something else.
The best option is for your gum
command to read from a different file descriptor. Usually something like this would work:
#!/bin/bash
gum input <&3
echo hello
echo world
ls -l
And then you invoke with curl 127.0.0.1/test.sh | bash 3<&1
Another option if you don't like playing with file descriptors is to use a process substitution:
bash <( curl 127.0.0.1/test.sh )
This frees up the stdin for bash
by replacing the pipeline with a special temporary file containing the output of curl
.
Answered By - tjm3772 Answer Checked By - David Goodson (WPSolving Volunteer)