Created
January 23, 2019 20:15
-
-
Save gregjhogan/d3630f476f3d14b309c3132c82914808 to your computer and use it in GitHub Desktop.
bash log to file if not running interactively
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
| #!/usr/bin/env bash | |
| set -e | |
| # log to file if not running interactively | |
| if [[ ! -t 1 ]]; then | |
| exec >> >(tee /var/log/$(basename ${0%.*}).log) 2>&1 | |
| fi | |
| echo "hello world!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment