![](/img/trans.png)
[英]How to use output of Laravel-(artisan)-command in bash-script?
[英]Format bash-script output
我現在正在尋找一段時間,如果這是一個特殊的printf
或echo
格式參數。 當我啟動我的ubuntu時,我總是看到這種輸出。 我的目標是打印這樣的文字:
Setting up locals [DONE]
Starting simulation [DONE]
Receiving Data [FAIL]
Retry operation [OK]
括號中的信息應始終在終端的右邊框上對齊並着色。
有人可以給我一個提示,我該如何安排?
謝謝你和BR
以下bash會將Severity與終端右側對齊。
log_msg() {
MSG="$1"
SEVERITY="[$2]"
let COL=$(tput cols)-${#MSG}
printf "%s%${COL}s" "$MSG" "$SEVERITY"
}
用法:
log_msg "Setting up locals" "DONE"
log_msg "Starting simulation" "DONE"
log_msg "Receiving Data" "FAIL"
log_msg "Retry operation" "OK"
你可以嘗試這樣的事情:
### Config ###
red="\033[91m"
green="\033[92m"
yellow="\033[93m"
blue="\033[94m"
viol="\033[95m"
cyan="\033[96m"
none="\033[0m"
printf "$viol%40s$none" "$testMessage..."
# execute test here
/path/test > output 2>&1
ret=$?
if [ $ret -eq 0 ]; then
printf "$green%10s$none\n" "[PASS]"
else
printf "$red%10s$none\n" "[FAILED]"
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.