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 $std
The 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!