Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
Bash capture output of running script

I may simply not know how to phrase what I am asking but I haven't been able to get the answers that I am looking for.

So what I am trying to to is run a command or script within a bash script capture the output line by line and check it against some value.

I have tried things to the effect of

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

and

#!/bin/bash

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

both just seem to execute the script giving me the normal output. What I want is to handle each line of output from runningscript.sh from within this bash script as it is output I don't want it to wait until runningscript.sh is finished running to handle it.

Sorry I am a very occasional and simple bash user so this may be the stupidest question to ask but any help would be greatly appreciated

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Your scripts work. but the output doesn't appear until late, maybe even after the commands are done? This is typically because of buffering: runningscript.sh has to fill up a buffer, typically 4 kB, before its output is transferred through the pipe to the next process in the pipeline.

A fix is to use the unbuffer command which is part of the expect package:

unbuffer runningscript.sh | something_else

This tricks runningscript.sh into thinking it is writing to an interactive terminal. As a result, it doesn't buffer.

For more, see https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe

Alternatively, if you have GNU coreutils 7.5 or better, you can disable output buffering with the stdbuf command:

stdbuf -oO runningscript.sh | something_else
over 4 years ago · Santiago Trujillo Denunciar

0

The form I see most often is:

while read line; do
    stuff to $line
done < $(somescript.sh)
over 4 years ago · Santiago Trujillo Denunciar

0

For this you have to edit runningscript.sh and put echo or whatever action you want put it in its own loop. Piping cannot help you because first it completes its first program then puts it output to the second. If you improve your runningscript.sh, you will not need to use extra script.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda