bash - Redirect terminal stdout through command -


all want redirect executed command's stdout pipe. example explain better do.

$ echo "hello world" | cowsay 

outputs "hello world" in cowsay, want preprocess terminal's / bash stdout pass through cowsay

$ echo "hello world" 

this should output same first command.

thanks in advance.

you can use process substitution:

#!/bin/bash exec >  >(cowsay) echo "hello world" 

however, there caveats. if start in background, cow wait finish:

#!/bin/bash exec >  >(cowsay) echo "hello world" sleep 30 &           # runs in background exit                 # script exits no cow appears 

in case, script exit no output. 30 seconds later, when sleep exits, cow shows up.

you can fix telling programs write somewhere else, cow doesn't have wait them:

#!/bin/bash exec >  >(cowsay) echo "hello world" sleep 30 > /dev/null & # runs in background , doesn't keep cow waiting exit                   # script exits , cow appears immediately. 

if don't start in background, 1 of tools or programs do. find ones, redirect or comment them out 1 one until cows appear.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -