Results 1 to 4 of 4

Thread: concatenate output of two commands

  1. #1
    Join Date
    Oct 2004
    Beans
    6

    concatenate output of two commands

    How do I concatenate output of two commands? For example, if I do

    $ echo "foo" && echo "bar" > tmp

    Then foo will be printed in stdout and bar in tmp. I guess I could do

    $ echo "foo" > tmp && echo "bar" >> tmp

    But what if I want to print to lp?

    $ echo "foo" && echo "bar" | lp

    will print only bar.

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: concatenate output of two commands

    Code:
    { echo "foo" && echo "bar"; } | lp
    The semicolon at the end of the group must be there, and there must be whitespace after the { and before the }.

  3. #3
    Join Date
    Oct 2004
    Beans
    6

    Re: concatenate output of two commands

    Quote Originally Posted by geirha View Post
    Code:
    { echo "foo" && echo "bar"; } | lp
    Thanks!

  4. #4
    Join Date
    Sep 2006
    Beans
    2,914

    Re: concatenate output of two commands

    Quote Originally Posted by asubedi View Post
    Thanks!
    Code:
    printf "foo\nbar" | lp

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •