Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Created January 4, 2026 02:18
Show Gist options
  • Select an option

  • Save h0tw1r3/4bae2a4526e40dc974b22b9a3fbe6c08 to your computer and use it in GitHub Desktop.

Select an option

Save h0tw1r3/4bae2a4526e40dc974b22b9a3fbe6c08 to your computer and use it in GitHub Desktop.
bash redirect all output to a script
#!/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