在 printf 中仅转义 ansi 颜色
我想用 ansi 颜色在控制台窗口路径中打印。
像这样:
file=read -r
printf "\033[32+++Path is \\\\uncshare\\testpath\\$file++\033[0m"
我需要转义任何特殊符号,例如\n,因为如果有人输入nested.txt作为文件名,例如,它将被解释为新行,但我想保留ansi颜色。
I want to print in console windows path with ansi color.
Like this:
file=read -r
printf "\033[32+++Path is \\\\uncshare\\testpath\\$file++\033[0m"
I need to escape any special symbol like \n, because if somebody type nested.txt as a name of the file, for example, it will be interpreted as new line,but i want to preserve ansi color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
printf
根据格式说明符替换字符串,然后您可以执行类似的操作以避免解释
file
中的字符。printf
replaces strings based on format specifiers, then you can do something liketo avoid characters in
file
being interpreted.