Home > Net >  Escape only ansi color in printf
Escape only ansi color in printf

Time:04-11

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.

CodePudding user response:

printf replaces strings based on format specifiers, then you can do something like

printf '\033[32   Path is \\\\uncshare\\testpath\\%s  \033[0m' "$file"

to avoid characters in file being interpreted.

  • Related