5

I have this piece of code using Process Substitution.

When I run it, it works fine, but it does not exit - just hangs there waiting for input.

Why and how to overcome?

prepro() { 
        in=$(< <(cat) )         # capture input
        echo -e "$in"
}

echo -e "some words" > >(prepro)
echo "FINISHED"

Instead if I do this, it exits immediately.

echo -e "$in" >>"test.log"

What am I missing here?

CLARIFICATION: BASH 4.4.19(1)-release

On my pc, I see a difference between running echo -e "$in" and running echo -e "$in" >>"test.log".

The former does not give me a prompt (but I can run commands normally). I get:

user@server:~$ ./test.sh
FINISHED
user@server:~$ some words
█

I have to press ENTER to get my prompt back.

The latter gives me the prompt normally.

user@server:~$ ./test.sh
FINISHED
user@server:~$ █

I am curious if I am doing something wrong here.

conanDrum
  • 457
  • 3
    So it doesn't hang. Look closely: your prompt is before some words. I'm sure this has been asked before, hang on. – Gilles 'SO- stop being evil' Jun 12 '19 at 21:08
  • 1
    I closed this question as a duplicate of an earlier question that explains why this happens. If you can't figure out how to solve your actual problem, post your actual code, because in this toy example, the obvious fix is not to use process substitution. – Gilles 'SO- stop being evil' Jun 12 '19 at 21:10

0 Answers0