You can use process substitution:
#!/bin/bash exec > >(cowsay) echo "Hello world"
However, there are reservations. If you start something in the background, the cow will wait for completion:
#!/bin/bash exec > >(cowsay) echo "Hello world" sleep 30 &
In this case, the script will exit without output. After 30 seconds, when sleep ends, the cow suddenly appears.
You can fix this by telling programs to write somewhere else so that the cow does not have to wait for them:
#!/bin/bash exec > >(cowsay) echo "Hello world" sleep 30 > /dev/null &
If you are not running anything in the background, make one of your tools or programs. To find which ones, redirect or comment on them one by one until a cow appears.
source share