Created
December 28, 2020 12:35
-
-
Save wader/31181451b86fab5160b6b7ac4c6612d3 to your computer and use it in GitHub Desktop.
cli calculator with readline, history, decimal, hex, octal, binary and ascii output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # requires rlwrap and iprint | |
| # brew install rlwrap iprint | |
| # apt-get install rlwrap iprint | |
| rlwrap -C calc sh -c '(test $# -gt 0 && echo $* || cat) | while read l ; do n=$(echo $(($l))) && i $n ; done' -- | |
| # as bash alias | |
| alias c="rlwrap -C calc sh -c '(test \$# -gt 0 && echo \$* || cat) | while read l ; do n=\$(echo \$((\$l))) && i \$n ; done' --" | |
| # usage | |
| # expr as argument | |
| > c 5+5 | |
| 10 0xA 012 0b1010 '\n' | |
| # repl | |
| > c | |
| 5+5 | |
| 10 0xA 012 0b1010 '\n' | |
| ctrl-c or ctrl-d to exit | |
| # variables | |
| > c a=5,a+5 | |
| 10 0xA 012 0b1010 '\n' | |
| # hex literals | |
| > c 0xa+3 | |
| 13 0xD 015 0b1101 '\r' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment