
Nifty shell script of the day: calculating standard deviation
If you find yourself working on the command line and need to whip out a quick statistical analysis or two, you'll be glad to know that Wicked Cool Shell Scripts fan Josh Kotecha has sent in a very nice little shell script that does just that using the scriptbc script included in the book.
Here's his script, as written: #!/bin/sh # copyright(c) j. kotecha 2004 -- http://www.vidia.com/ # this file may be used without fee as long as the copyright # notice is kept the program is is "as is" and not warranted # for any purpose. Use at your own risk M="0" s="0" v="0" d="0" if [ $# -eq 0 ]; then exit 1 fi if [ $1 = "-m" ]; then M=$2 shift 2 else M=0 fi list=$* count=$# for i in $* do d=`scriptbc -p 9 $i - $M` v=`scriptbc -p 9 $d \* $d` s=`scriptbc -p 9 $s + $v` done std="`scriptbc -p 9 $s / $count`" std="`scriptbc -p 9 sqrt \( $std \)`" echo $stdThe script itself could be fine-tuned a bit, but the important thing to see here is that Wicked Cool Shell Scripts really does enable readers to get more out of the command line and shell scripting environment, to create scripts and commands that they otherwise wouldn't have been able to create. Great job, Josh!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
Shell Script Programming
(Article 3695)
Tagged: Previous: And on my doorstep today: "Creating Cool Web Sites with HTML, XHTML and CSS" Next: Changes in the login shell from Jaguar to Panther Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.
Rather amazingly, there are no comments on this article yet.
I have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|