Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was wondering how I can iterate over each line of the output of a command and pass it as command line arguments to another one. I want to do this in a non-blocking fashion as the output never reaches an EOF.

To be more precise I want to take each line of output from acpi_listen and pass it to a user-level acpi handler script similarly to what acpid does as root(eg. "button/lid LID close" where $1="button/lid" $2=LID $3=close).

share|improve this question
1  
you mean like tail -f acpi_listen | yourscript (using a readline loop)? –  Tobias Kienzler Sep 6 '12 at 9:48
    
yes kinda, but this way all the output seems to buffer until the program is terminated –  vitiv Sep 6 '12 at 9:54

1 Answer 1

up vote 2 down vote accepted

That's possible, script below will launch some_command and passing every line in the file, and launch them in background, non-blocking:

cat input | while read param; do
    some_command $param &
done
share|improve this answer
    
Yeah this one doesn't wait for EOF though I had to pass param to xargs to split it into individual arguments. Thanks! –  vitiv Sep 6 '12 at 10:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.