Multiple Pipes (shell scripting)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spacecoyote
    New Member
    • Nov 2006
    • 15

    Multiple Pipes (shell scripting)

    I have a script which starts out with:

    ls -lhagG | grep ^d
    ls -lhagG | grep ^-

    but I would like to be able to do something like this:

    ls -lhagG ls's output to grep ^d and then ls's output to grep ^-

    so I don't have to run ls twice. I can't find a howto I can understand. I think what I need to use is named pipes but I'm not sure.
  • spacecoyote
    New Member
    • Nov 2006
    • 15

    #2
    For now I'm using the "write to a file in /tmp/" method...it works pretty good.

    Comment

    • spacecoyote
      New Member
      • Nov 2006
      • 15

      #3
      Ok...I figured it out. You have to make everything that accesses that pipe run at the same time with &.

      Kind of obvious now that I think about it :)

      [resolved]

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by spacecoyote
        Ok...I figured it out. You have to make everything that accesses that pipe run at the same time with &.

        Kind of obvious now that I think about it :)

        [resolved]
        To clarify, the solution was:

        ls -lhagG | grep ^d & grep ^-

        Comment

        Working...