How to pipe all bash terminal output through command [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
5
down vote

favorite













This question already has an answer here:



  • How do I pipe each command given to the shell?

    2 answers



I would like to be able to pipe all bash terminal commands through a certain command (for no good reason other than to play a prank on someone). I just want to pipe the stdout of any executed command into a predetermined program without doing anything special.



For example:
If that predetermined program was cowsay



echo "Hello World"


should output



 _____________
< Hello World >
-------------
^__^
(oo)_______
(__) )/
||----w |
|| ||


How can I achieve this? (Some of the fun programs I'd like to use to play pranks on others include rev, cowsay, and lolcat)







share|improve this question











marked as duplicate by dessert command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 1 at 19:51


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    5
    down vote

    favorite













    This question already has an answer here:



    • How do I pipe each command given to the shell?

      2 answers



    I would like to be able to pipe all bash terminal commands through a certain command (for no good reason other than to play a prank on someone). I just want to pipe the stdout of any executed command into a predetermined program without doing anything special.



    For example:
    If that predetermined program was cowsay



    echo "Hello World"


    should output



     _____________
    < Hello World >
    -------------
    ^__^
    (oo)_______
    (__) )/
    ||----w |
    || ||


    How can I achieve this? (Some of the fun programs I'd like to use to play pranks on others include rev, cowsay, and lolcat)







    share|improve this question











    marked as duplicate by dessert command-line
    Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Jun 1 at 19:51


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      5
      down vote

      favorite









      up vote
      5
      down vote

      favorite












      This question already has an answer here:



      • How do I pipe each command given to the shell?

        2 answers



      I would like to be able to pipe all bash terminal commands through a certain command (for no good reason other than to play a prank on someone). I just want to pipe the stdout of any executed command into a predetermined program without doing anything special.



      For example:
      If that predetermined program was cowsay



      echo "Hello World"


      should output



       _____________
      < Hello World >
      -------------
      ^__^
      (oo)_______
      (__) )/
      ||----w |
      || ||


      How can I achieve this? (Some of the fun programs I'd like to use to play pranks on others include rev, cowsay, and lolcat)







      share|improve this question












      This question already has an answer here:



      • How do I pipe each command given to the shell?

        2 answers



      I would like to be able to pipe all bash terminal commands through a certain command (for no good reason other than to play a prank on someone). I just want to pipe the stdout of any executed command into a predetermined program without doing anything special.



      For example:
      If that predetermined program was cowsay



      echo "Hello World"


      should output



       _____________
      < Hello World >
      -------------
      ^__^
      (oo)_______
      (__) )/
      ||----w |
      || ||


      How can I achieve this? (Some of the fun programs I'd like to use to play pranks on others include rev, cowsay, and lolcat)





      This question already has an answer here:



      • How do I pipe each command given to the shell?

        2 answers









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jun 1 at 16:29









      vikarjramun

      227212




      227212




      marked as duplicate by dessert command-line
      Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jun 1 at 19:51


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by dessert command-line
      Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jun 1 at 19:51


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          exec > >(COMMAND)


          Where COMMAND is rev, lolcat or other. This won't work with cowsay.



          E.g.



          bash-4.3$ exec > >(rev)
          bash-4.3$ echo hello
          olleh


          Explanation:




          • exec normally replaces the current shell with another process, but if you just give it a redirection like in this case, the redirection will take place for the current shell.


          • > redirect stdout


          • >(COMMAND) input into COMMAND

          Note that if you have a PROMPT_COMMAND, you should direct it to stderr to avoid the redirected stdout.






          share|improve this answer























          • Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
            – vikarjramun
            Jun 1 at 17:12











          • @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
            – wjandrea
            Jun 1 at 17:13






          • 2




            @wjandrea Perhaps the unbuffer command from expect could help.
            – PerlDuck
            Jun 1 at 17:16










          • @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
            – vikarjramun
            Jun 1 at 17:30










          • @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
            – wjandrea
            Jun 1 at 18:57

















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          exec > >(COMMAND)


          Where COMMAND is rev, lolcat or other. This won't work with cowsay.



          E.g.



          bash-4.3$ exec > >(rev)
          bash-4.3$ echo hello
          olleh


          Explanation:




          • exec normally replaces the current shell with another process, but if you just give it a redirection like in this case, the redirection will take place for the current shell.


          • > redirect stdout


          • >(COMMAND) input into COMMAND

          Note that if you have a PROMPT_COMMAND, you should direct it to stderr to avoid the redirected stdout.






          share|improve this answer























          • Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
            – vikarjramun
            Jun 1 at 17:12











          • @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
            – wjandrea
            Jun 1 at 17:13






          • 2




            @wjandrea Perhaps the unbuffer command from expect could help.
            – PerlDuck
            Jun 1 at 17:16










          • @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
            – vikarjramun
            Jun 1 at 17:30










          • @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
            – wjandrea
            Jun 1 at 18:57














          up vote
          6
          down vote



          accepted










          exec > >(COMMAND)


          Where COMMAND is rev, lolcat or other. This won't work with cowsay.



          E.g.



          bash-4.3$ exec > >(rev)
          bash-4.3$ echo hello
          olleh


          Explanation:




          • exec normally replaces the current shell with another process, but if you just give it a redirection like in this case, the redirection will take place for the current shell.


          • > redirect stdout


          • >(COMMAND) input into COMMAND

          Note that if you have a PROMPT_COMMAND, you should direct it to stderr to avoid the redirected stdout.






          share|improve this answer























          • Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
            – vikarjramun
            Jun 1 at 17:12











          • @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
            – wjandrea
            Jun 1 at 17:13






          • 2




            @wjandrea Perhaps the unbuffer command from expect could help.
            – PerlDuck
            Jun 1 at 17:16










          • @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
            – vikarjramun
            Jun 1 at 17:30










          • @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
            – wjandrea
            Jun 1 at 18:57












          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          exec > >(COMMAND)


          Where COMMAND is rev, lolcat or other. This won't work with cowsay.



          E.g.



          bash-4.3$ exec > >(rev)
          bash-4.3$ echo hello
          olleh


          Explanation:




          • exec normally replaces the current shell with another process, but if you just give it a redirection like in this case, the redirection will take place for the current shell.


          • > redirect stdout


          • >(COMMAND) input into COMMAND

          Note that if you have a PROMPT_COMMAND, you should direct it to stderr to avoid the redirected stdout.






          share|improve this answer















          exec > >(COMMAND)


          Where COMMAND is rev, lolcat or other. This won't work with cowsay.



          E.g.



          bash-4.3$ exec > >(rev)
          bash-4.3$ echo hello
          olleh


          Explanation:




          • exec normally replaces the current shell with another process, but if you just give it a redirection like in this case, the redirection will take place for the current shell.


          • > redirect stdout


          • >(COMMAND) input into COMMAND

          Note that if you have a PROMPT_COMMAND, you should direct it to stderr to avoid the redirected stdout.







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jun 1 at 18:59


























          answered Jun 1 at 16:39









          wjandrea

          7,02542054




          7,02542054











          • Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
            – vikarjramun
            Jun 1 at 17:12











          • @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
            – wjandrea
            Jun 1 at 17:13






          • 2




            @wjandrea Perhaps the unbuffer command from expect could help.
            – PerlDuck
            Jun 1 at 17:16










          • @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
            – vikarjramun
            Jun 1 at 17:30










          • @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
            – wjandrea
            Jun 1 at 18:57
















          • Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
            – vikarjramun
            Jun 1 at 17:12











          • @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
            – wjandrea
            Jun 1 at 17:13






          • 2




            @wjandrea Perhaps the unbuffer command from expect could help.
            – PerlDuck
            Jun 1 at 17:16










          • @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
            – vikarjramun
            Jun 1 at 17:30










          • @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
            – wjandrea
            Jun 1 at 18:57















          Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
          – vikarjramun
          Jun 1 at 17:12





          Thanks for the explanation, two questions: 1. It works great for tools like lolcat or rev which operate on a line by line basis. But for cowsay, it waits until I press ctrl-d, then outputs everything. How can we make it add an EOF to each command, and spawn a new cowsay each time?
          – vikarjramun
          Jun 1 at 17:12













          @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
          – wjandrea
          Jun 1 at 17:13




          @vikarjramun Yeah, I'm having the same problem. Must be a buffering thing. I'm researching it now
          – wjandrea
          Jun 1 at 17:13




          2




          2




          @wjandrea Perhaps the unbuffer command from expect could help.
          – PerlDuck
          Jun 1 at 17:16




          @wjandrea Perhaps the unbuffer command from expect could help.
          – PerlDuck
          Jun 1 at 17:16












          @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
          – vikarjramun
          Jun 1 at 17:30




          @wjandrea my first thought was xargs cowsay but that didn't work. Maybe xargs bash -c "echo | cowsay"? I'll try that and see.
          – vikarjramun
          Jun 1 at 17:30












          @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
          – wjandrea
          Jun 1 at 18:57




          @PerlDuck I couldn't get it to work. I tried it with and without the -p flag.
          – wjandrea
          Jun 1 at 18:57


          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491