bashdig

The dig command changes its behaviour regarding umlauts if used with a pipe


I want to query a domain with dig and store the result in a file by redirecting the output. But dig seems to change its behaviour regarding umlauts if executed in pipe (or redirect) context.

Without pipe:

jump@serv:~$ dig münchen.de
; <<>> DiG 9.18.28-0ubuntu0.20.04.1-Ubuntu <<>> münchen.de
[...]
;; QUESTION SECTION:
;münchen.de.                    IN      A
;; ANSWER SECTION:
münchen.de.             3600    IN      A       194.246.148.58
[...]

With pipe:

jump@serv:~$ dig münchen.de | cat
; <<>> DiG 9.18.28-0ubuntu0.20.04.1-Ubuntu <<>> münchen.de
[...]
;; QUESTION SECTION:
;m\195\188nchen.de.             IN      A
[no answer section]

Although münchen.de is repeated correctly in the first line of both outputs it differs in the QUESTION and therefore in the ANSWER section. How can I avoid this?

I would expect the same behaviour with and without using a pipe.


Solution

  • dig convert or not convert UTF-8 (=IDN) domains to puny code. Extract from man dig:

    +idnin, +noidnin
      This option processes [or does not process] IDN domain names on input.  This
      requires IDN SUPPORT to have been enabled at compile time.
    
      The  default is to process IDN input when standard output is a tty.  The IDN
      processing on input is disabled when dig output is redirected to files, pipes,
      and other non-tty file descriptors.
    

    Old versions of dig haven't IDN support. So for compatibility with scripts, IDN is disabled if not output to a tty.