In a bash script I use the following:


calc=$(concalc "$*")

printf "%s\n" "$calc"

I do get the result I want, but allways with this error message:
tcsetattr error: Inappropriate ioctl for device

Does anyone know how to get rid of this? When I use concalc on its own it is no problem but as soon as I use it within a command-substitution or a pipe I get this message.


It seems to insist on setting some terminal attributes, like disabling echo, regardless of the mode it runs in (interactive or not). I assume it's somehow useful for scripts, since it doesn't do anything on the terminal between setting and resetting it otherwise.

Apart from fixing the code, you could just redirect the errors away:

calc=$(concalc "$*" 2>/dev/null)
  • Yes, what concalc does with its standard output seems pointless, and the assumptions that it makes, wrong. It's worth looking at tools such as expr, dc, and bc in these circumstances. – JdeBP Jan 16 '18 at 10:45
  • @JdeBP thanks for mentioning expr I did not know this. The only problem with expr as well as with dc and bc is that they do not support decimal values, so the only solution for this case in bash as far as I know is awk. – nath Jan 19 '18 at 1:49
  • Who told you that dc and bc don't support decimal? Was it someone who hadn't read about the scale factor setting? (-: – JdeBP Jan 19 '18 at 19:37
  • 1
    bc -l supports decimals, plus some oddly named functions (trig, exp, log). e.g. echo '1/7; s(3.14159265358979/2)' |bc -l You can set the number of digits after the decimal point with scale=123 in the program. – ilkkachu Jan 19 '18 at 19:41
  • @ilkkachu; Thanks for the lesson! I finally found your commend (by chance though) ;-) – nath Jan 29 '18 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.