Created
September 17, 2022 01:25
-
-
Save Enchan1207/d09767c1c409fd482c195a3d88a3a4f4 to your computer and use it in GitHub Desktop.
いい感じにANSIエスケープを除去してくれるログ出力関数 for bash
This file contains 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 | |
# ログを出力する. | |
# 第一引数がメッセージとして扱われ、 | |
# stdoutがttyでなければカラーエスケープシーケンスを除去する | |
function log(){ | |
if [ -t 1 ]; then | |
printf "$1\n" | |
else | |
printf "$1\n" | sed -r 's/\x1b\[[0-9]*(;[0-9]*)*m//g' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment