I have the following simple example of which I don't understand how it comes to the output:
#!/bin/bash
function wtf() {
echo -e "test1" >&1
sleep 2
echo -e "test2" >&1
}
a=$(wtf)
echo $a
The output on the terminal is AFTER 2 seconds test1 test2
When I change the last two lines just to wtf then the output is
test1
test2 #after 2 seconds
- Why is in the first version the
test1 test2in the same line? - Why does the output of the line
test1 test2need 2 seconds to show up since only the secondtest2should show up after 2 seconds?