while read line in bash

I always forget about this thing and the only reason I do not remember is because I have not written it down somewhere. And it is so embarrassing to ecosia it. At least now I can look it up on my own blog, slightly reducing the amount of embarrassment

The problem is simple: You have some command which does multiple lines of output and you need to do a little bit more complex operation with each of the lines, so you can't just use xarg.

Now, one could work around with for and some IFS magic, but I never get this working right.

And the pattern is really simple:

  command | while read line
  do
    some_other_command $line
  done

The command of course could be a longer pipe of commands. Note that line is just some arbitrary variable name and is not some sort of directive.

In particular, with some awk magic we can quickly build more complex commands.

blogroll

social