0

When some invalid or undefined commands are executed in dc, it usually just prints a warning. Example:

cp
dc: stack empty

This is nice most of the time, however, there are cases where this is annoying as the desired action actually works. Consider this example:

5 6+sИlИp
dc: 0230 unimplemented
dc: 0230 unimplemented
11

See? Even if I try to use another register than those in the manual it still works. ("officially" 256, but how are you even supposed to use the NUL byte?)

Even if perhaps not always a good idea, I would like dc to now show me such warnings in some scripts.

How can I make dc not print warnings?

  • 4
    If you want to suppress warnings, I guess you can always redirect stderr to the bit bucket, but it sounds more like dc's warning in this case is authentic and important. – Celada Apr 15 '17 at 17:07

1 Answers1

2

The errors are because of the multibyte characters, Gnu (and I thing all modern Unixes) uses utf-8.

Therefore

dc <<< "5 6+s¢l¥p" is equivalent to dc <<< "5 6+s¢l¢p". The first byte of ¢ and ¥ are the same, and is used as the address of the register. The 2nd byte produces the error.

see output of od

#↳ od -ta -to1 <<< "5 6+s¢l¥p"
0000000   5  sp   6   +   s   B   "   l   B   %   p  nl
        065 040 066 053 163 302 242 154 302 245 160 012

Therefore the error is valid, and should not be ignored.


Try this test case, dc <<< "4s¢11s¥l¢p" what output are you expecting? (dc warns that there is a problem.) What output does it produce?

dc is not utf-8 aware, it work on bytes. Utf-8 is almost, but not quite compatible with 8 bit (ascii like) encodings.

see: https://www.youtube.com/watch?v=MijmeoH9LT4 (computerphile on utf-8).