Whenever I use command line tools, I like to make sure that the output can be interpreted unambiguously. On one of my other machines, I wrote a shell script that would find all of the symbolic links residing under a particular path and it would print them to the console so that it would look like "<Escaped Path To Symbolic Link>" \e[91m=>\e[0m "<Escaped Path To Target>"
. The ANSI escape codes are parsed in that script; <Escaped Path To Symbolic Link>
and <Escaped Path To Target>
are the paths to the symbolic link and its target, respectively, with any non-printable characters escaped so that they come out as \xHH
on the console (where H
is a hexadecimal digit).
In the above, there is no ambiguity. If either the symbolic link or its target path contain =>
, it will be distinguishable from the delimiter separating because the delimiter will be displayed as red text. If either path contains an ANSI escape code, then the escape character will appear on the console as \e
, eliminating any chance that there could be anything other than one red =>
. A newline would be rendered as \n
and double quotes would appear as \"
.
I am aware of three ways that further disambiguate the output of tree
in some way:
-q
will maketree
display unprintable characters as?
. Any effect they might have on the output is negated.-C
turns colorization on. If this is used in conjunction with-F
, then the appended characters will be distinguishable from the names they are affixed to by being a different color. In this way, a file whose name ends with an equal sign will be distinguishable from a socket.
Using both options still leaves it ambiguous as to what character any ?
that has been substituted for an unprintable one represents and is not distinguishable from question marks that are actually part of the file or folder's name. If the sequence ->
, which is used to indicate what a symbolic link points to, is in a path, then it is distinguishable thanks to spaces in paths being converted to \
.
How can I make the output completely unambiguous?
-N
option: "Print non-printable characters as is instead of as escaped octal numbers." – muru Sep 25 '18 at 17:55tree
for some other purpose? – Kusalananda Sep 25 '18 at 18:32