roll is a C software to parse dice notation grammar like 1D6 and roll a die accordingly.
$ ./roll 3D12 20 $ ./roll -v 3D12 d12 -> 1 d12 -> 2 d12 -> 11 14
Repository: https://github.com/matteocorti/roll
Man page: https://linux.die.net/man/1/roll
Apparently not packaged for FreeBSD, repository contains instructions for Debian and Fedora.