Work the Shell - Solve: a Command-Line Calculator Redux
Here's where the script stands at this point, in its entirety:
#!/bin/sh if [ $# -gt 0 ] ; then bc << EOF scale=4 $@ quit EOF else /bin/echo -n "solve: " while read expression do if [ "$expression" = "quit" -o "$expression" = "exit" ] ; then exit 0 fi bc << EOF scale=4 $expression quit EOF /bin/echo -n "solve: " done echo "" echo "solved." fi exit 0
Neat and darn useful, I'd say. If I were to continue hacking on it, the next thing I would do is write a simple help page that I'd store in some library folder and display on entry of ? or help. It simply would explain the syntax of the expressions understood by bc (though as we're invoking bc iteratively, we can't have persistent variables and so forth, so unfortunately, this approach won't let us access the full power of the binary calculator).
To learn what type of sophisticated expressions you can enter, simply type man bc. Then, let that be your inspiration for further tweaks and mods to this script!
Next month, I'll go back to the numerology script and see what strange things we can ascertain about the apparently benign world around us. Remember, just because I got out of sequence, doesn't mean we're not out to get you, dear reader!
Dave Taylor is a 26-year veteran of UNIX, creator of The Elm Mail System, and most recently author of both the best-selling Wicked Cool Shell Scripts and Teach Yourself Unix in 24 Hours, among his 16 technical books. His main Web site is at www.intuitive.com, and he also offers up tech support at AskDaveTaylor.com.
Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
|Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi||Apr 20, 2017|
|CodeLathe's Tonido Personal Cloud||Apr 19, 2017|
|Wrapping Up the Mars Lander||Apr 18, 2017|
|MultiTaction's MT Canvus-Connect||Apr 17, 2017|
|Android Candy: Facebook Everything?!?!||Apr 14, 2017|
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi
- The Weather Outside Is Frightful (Or Is It?)
- Simple Server Hardening
- Understanding Firewalld in Multi-Zone Configurations
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- Non-Linux FOSS: Control Web-Based Music!
- Bash Shell Script: Building a Better March Madness Bracket
- Buddy Platform Limited's Parse on Buddy Service