Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-28-2006, 11:34 AM   #1
LQ Newbie
Registered: Dec 2006
Location: St. Louis, MO
Distribution: Fedora
Posts: 7

Rep: Reputation: 0
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 ( 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.
Old 12-28-2006, 01:58 PM   #2
Senior Member
Registered: Mar 2003
Location: Beautiful BC
Distribution: RedHat & clones, Slackware, SuSE, OpenBSD
Posts: 1,791

Rep: Reputation: 50
echo <Expression>|e

or you can experiment with xargs
Old 12-28-2006, 03:13 PM   #3
LQ Newbie
Registered: Dec 2006
Location: St. Louis, MO
Distribution: Fedora
Posts: 7

Original Poster
Rep: Reputation: 0
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 08:19 PM
Command line 'dictionary' access command. swiadek Linux - Software 3 02-23-2006 09:53 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 05:35 PM
Command to display whole filestructure hierarchy f/ command line? mjewell Linux - Newbie 10 01-19-2004 11:48 AM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 01:24 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration