LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Command line - command modification (https://www.linuxquestions.org/questions/linux-software-2/command-line-command-modification-514326/)

eric2233 12-28-2006 10:34 AM

Command line - command modification
 
I want to be able to type a mathematical expression on the command line and have it evaluate. For example, to just type "5*3" in the shell and press return and it will print 15.

I found the "e" command (http://www.softnet.tuc.gr/~apdim/projects/e/) which evaluates expressions, thus you can type "e 5*3" and it prints 15. Pretty good BUT it's annoying to type in "e " all the time. Yes, I'm being picky, but I think it should be possible.

Here's my idea: every command you enter in the shell gets redirected to a script. The script runs "which" to find out if it was a valid command. If so, the command runs normally. If it's not a valid command, then it gets sent as input to "e" which tries to evaluate it as a mathematical expression. Real mathematical expressions will almost always be invalid commands so they will be evaluated by "e". Non-math typing errors will also get sent to "e", but I can recompile e so that the resulting error message is appropriate.

My one difficulty is: I don't know how to "redirect" the input to "e". That is to say, how to modify the text of commands before the shell runs them. Any ideas how to do this? My shell of preference is bash.

ppuru 12-28-2006 12:58 PM

echo <Expression>|e

or you can experiment with xargs

eric2233 12-28-2006 02:13 PM

Um, maybe I'm missing something, but I can't see how either of those help.

I'm looking for something like a wild-carded alias. Instead of aliasing one input at a time, all possible inputs would be aliased according to a set of rules.


All times are GMT -5. The time now is 06:00 AM.