我正在寻找生成在 bash 中右对齐的成功/失败消息。一个例子是 apache2 执行时产生的结果:sudo /etc/init.d/apache2 reload
etc.
在上面的例子中,apache2 产生的结果非常漂亮和简洁[OK]
or [fail]
右对齐的消息。
另外,很想知道如何将文本变为红色,以防万一我们要生成一个[fail]
信息。
#!/bin/bash
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0)
col=80 # change this to whatever column you want the output to start at
if <some condition here>; then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
fi
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)