我有一个变量 "x" ,它包含两列和两行。我想用红色打印“hi”,所以我求助了tput
,它用红色打印了结果。但是我还需要以正确对齐的方式打印我使用的列,column -t
但这会扭曲输出。这是因为 tput 添加了一些控制字符。
x="hello $(tput setaf 1)hi $(tput sgr0) whatsup
hey howdy cya"
echo "$x"
hello hi whatsup
hey howdy cya
echo "$x"|column -t
hello hi whatsup
hey howdy cya
我期待:
hello hi whatsup
hey howdy cya
尝试调试,发现tput正在添加一些控制字符以使“hi”打印为红色。
echo "$x"|cat -A
hello ^[[31mhi ^[(B^[[m whatsup$
hey howdy cya$
问题:
如何“ column -t
”在 tput 的彩色输出上?
编辑:来自@Diego Torres Milano 的结果(ALL IN RED)
hello 31mhi Bm whatsup
hey howdy cya