[Possible bug?] column command not ignoring escape sequences.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greetings,

I have a working script checking mimetypes i.e. `text/x-diff`;
`image/svg+xml` etc.

=================================
  1   #!/bin/bash
  2
  3   _Bold="\e[1m"
  4   _unBold="\e[22m"
  5   _Blue="\e[34m"
  6   _uC="\e[39m"
  7
  8   mimetype="$1"
  9   output="${_Bold}Testing MimeType${_unBold}:\t${mimetype}\n\t-------------"
 10
 11   get_default()
 12   {
 13       xdg-mime query default "$1"
 14   }
 15
 16   alias_of=`grep "^$mimetype " /usr/share/mime/aliases | cut -d' ' -f2`
 17   if [ -n "$alias_of" ]; then
 18       default=`get_default $alias_of`
 19       output="$output\nWhich is an alias of:\t$alias_of\t->
${default:-"none"}"
 20   else
 21       output="$output\nWhich is not an alias."
 22       alias_of=$mimetype
 23   fi
 24
 25   while : ; do
 26       subclass_of=`grep "^$alias_of " /usr/share/mime/subclasses |
cut -d' ' -f2`
 27       if [ -n "$subclass_of" ]; then
 28         default=`get_default $subclass_of`
 29         output="$output\nWhich is a subclass of:\t$subclass_of\t->
${default:-"none"}"
 30
 31         alias_of=$subclass_of
 32       else
 33         output="$output\nWhich is not a subclass"
 34         break
 35       fi
 36   done
 37
 38   echo -e $output | column -t -s $'\t'
=================================

Output without bold (line 8) is as expected but with bold, the column
is widened/broken.

I have removed the rest of the formatting in my example, but with
colors added it gets much worse.

I think I have narrowed it down to the `column` somehow including the
escape sequences in its spacing calculation? The same thing happens in
xterm, gnome-terminal and urxvt.

Is this expected behaviour? I'm learning a lot but sometimes I get a
headscratcher like this one.

Thank you for your time.

Sincerely,
Michael Heyns
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux