Like /bin/echo but ANSI-escapes the output # $Header: /CVSROOT/printansi/DESCRIPTION,v 1.2 2009-08-27 18:28:27 tino Exp $ # # $Log: DESCRIPTION,v $ # Revision 1.2 2009-08-27 18:28:27 tino # Warning added # # Revision 1.1 2009-07-31 22:26:28 tino # First version Printansi echos the arguments to stdout (or a file) ANSI-escaped. The arguments are separated by spaces and ends the line with LF. This way you can preserve the arguments between shell sessions, by reading them in again. Example:
a='arg with newline' b="arg with shell '"'" shell' printansi "$a" "$b" > /tmp/preserve.file.$$ read -r c d < /tmp/preserve.file.$$ eval c="\$'$c'" eval d="\$'$d'" if [ ".$a" = ".$c" ] || [ ".$b" != ".$d" ]; then echo "fail"; fiPlease note that the "read" and "eval" completely runs in the shell without any forks, so it's quick. If you invoke it with -f it automatically creates and locks the file. Options -l when combined with option -f are a quick version of following line:
while read -r a; do printansi -f "file" "$a"; doneOption -z is the same with NUL as line terminator. I want to stress, that you must use read -r. If you forget the option -r you will see strange effects.