它应该是这样的:
locate -bir pdf | some_command_to_color_the_result
着色不应仅限于locate命令:我需要一个通用解决方案,使用管道为文本着色,例如将其输入grep或cat的输出.
如果没有内置的linux命令,那么任何关于如何创建一个linux命令的提示都会受到赞赏.
解决方法norm="$(printf '3[0m')" #returns to "normal"bold="$(printf '3[0;1m')" #set boldred="$(printf '3[0;31m')" #set redboldred="$(printf '3[0;1;31m')" #set bold,and set red.somecommand | sed -e "s/someregexp/${boldred}&${norm}/g" # will color any occurence of someregexp in Bold redprintf "%s" "$red" ; locate something ; printf "%s" "$norm" # will color output of locate something in red #I (ab)use printf "%s" "something",as it's more portable than echo,and easy to modify
还有很多其他方法(创建一个可以为正则表达式着色的函数/脚本,例如,然后:somecommand | colorize -c green’foo.* bar”other’)
总结以上是内存溢出为你收集整理的Color Linux命令输出全部内容,希望文章能够帮你解决Color Linux命令输出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)