prefix command output in bash
When I write scripts that call other programs, like to prefix their output for the user to make it easier to see what's going on. There's a pretty simple way to do this with perl:
prefix_echo () {
perl -sne '$|=1; print "[$pre]\t$_"' -- -pre="$1"
}
# usage
long_command "1" "2" | prefix_echo "long_command"
# example output
[long_command] run completed in 0.2s
[long_command] run completed in 0.8s
Written by Nick Jacob
Related protips
1 Response
Fantastic tip!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Terminal
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#