11
$ echo "$?"
0
$ echo 'q' | dc || echo "$?"
1

Why is using q to quit dc considered an error?

(The test was run on Ubuntu 20.4.)

don_crissti
  • 79,330
  • 30
  • 216
  • 245
Ray Butterworth
  • 426
  • 1
  • 5
  • 14
  • That's probably related to the source code of the `bc` or `dc` package provided by Ubuntu. In my case I have Opensuse and using `q` actually exits with `0` (EXIT_SUCCESS) – Edgar Magallon Jan 27 '23 at 06:55

1 Answers1

23

This appears to be a bug in dc code, go to the bottom of dc/eval.c, line 817:

reset_and_exit_quit:
reset_and_exit_fail:
    signal(SIGINT, sigint_default);
    return DC_FAIL;
reset_and_exit_success:
    signal(SIGINT, sigint_default);
    return DC_SUCCESS;

the label reset_and_exit_quit should come after reset_and_exit_fail not before... and that explains why user Edgar Magallon does not experience this behavior since the folks @ Suse actually have a patch for this: correct-return-value
A quick search on gnu-utils mailing list doesn't return anything related to this issue so if anyone has the time, run a thorough search and if nothing comes up, report it.

don_crissti
  • 79,330
  • 30
  • 216
  • 245