Bash prints script output

I just don’t know how to talk about what I ask, but I could not get the answers that I am looking for.

So I'm trying to execute a command or script in a bash script, output line by line and check for some value.

I tried things under action

#!/bin/bash
./runningscript.sh | while read line; do
echo "output $line"
done

and

#!/bin/bash

./runningscript.sh | {read line echo "output $line"}

both just execute the script, giving me a normal output. I want to process every line of output from runningscript.sh from this bash script, since it is being output, I do not want it to wait for runningscript.sh to complete to process it.

Sorry I'm a very casual and simple bash user, so this might be the dumbest question to ask, but any help would be greatly appreciated.

+4
3

. , , ? - : runningscript.sh , 4 kB, , .

unbuffer, expect:

unbuffer runningscript.sh | something_else

runningscript.sh, , . .

. https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe

, GNU coreutils 7.5 , stdbuf:

stdbuf -oO runningscript.sh | something_else
+7

:

while read line; do
    stuff to $line
done < $(somescript.sh)
+1

To do this, you need to edit runningscript.sh and put echoor any other action that you want to put in your own loop. The pipeline cannot help you, because first it completes its first program, and then displays it on the second. If you improve your runningscript.sh, you will not need to use additional scripts.

0
source

All Articles