Here is my code: I want to create a temporary variable in a temporary directory. I create a function called read-series which reads integers until ctrl-d and then appends them to .tmp. Then it passes to even-odd which sums the product of evens and sum of odds. Reduce is then called to output the value. More or less. I'm new to Bash so please be clear on answers.
#!/bin/bash
TMPDIR=${HOME}/tmpdir
function readSeries () {
while read -p "Enter an Integer: " number ; do
echo $number
done
return 0;
} >> $$.tmp
function even-odd () {
# unsure of how to reference TMPDIR
while read $TMPDIR ; do
evenp=$(($1 % 2))
if [ $evenp -eq 0 ] ; then # if 0 number is even
return 0
else # if 1 number is odd
return 1
fi
done
}
function reduce () {
# function to take sum of odds and product of evens
# from lab 5 prompt
even-odd $input
cat $TMPDIR/$$.tmp | reduce
}
read-series
cat $TMPDIR/$$.tmp | reduce
read-seriesdefined for instance (that is on the 2nd to last line of your script), and callingreduceinside thereducefunction will lead to problems. Learning to understand the output of addingset -xnear the top of your code will be a big help for debugging your own code. Good luck.