#!/bin/bash # this script does an operation on every element in stdin # specify operation = add, sub, +, -, /, *, and, or, not, eor # ==> escape the * ! case $1 in add) skip=0;result=0;; sub) skip=1;; \*) skip=0;result=1;; /) skip=1;; esac cat | while read arg ;do if [[ $skip == 0 ]] ;then result=`dc $result $arg "$1"` echo $result else result=$arg skip=0 fi done | tail -n1