Created
January 4, 2026 02:18
-
-
Save h0tw1r3/4bae2a4526e40dc974b22b9a3fbe6c08 to your computer and use it in GitHub Desktop.
bash redirect all output to a script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # prefix all output with a timestamp | |
| exec > >(perl -pe 'use POSIX qw(strftime); print strftime("[%Y-%m-%d %H:%M:%S] ", localtime)') | |
| exec 2> >(perl -pe 'use POSIX qw(strftime); print strftime("[%Y-%m-%d %H:%M:%S] ", localtime)' >&2) | |
| echo "This goes to stdout :)" | |
| echo >&2 "This goes to stderr :(" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment