Skip to content

Instantly share code, notes, and snippets.

@Enchan1207
Created September 17, 2022 01:25
Show Gist options
  • Save Enchan1207/d09767c1c409fd482c195a3d88a3a4f4 to your computer and use it in GitHub Desktop.
Save Enchan1207/d09767c1c409fd482c195a3d88a3a4f4 to your computer and use it in GitHub Desktop.
いい感じにANSIエスケープを除去してくれるログ出力関数 for bash
#!/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