For a task I have to write a function that prints the number of numbers that are factors of 12 when provided with a sequence of numbers. My problem now is that my function keeps printing 0. What am I doing wrong?
Below is my code:
#!/usr/bin/bash
#File: Num_Factor
#Write a function which prints factors of the first argument
function num_factor {
local sum=0
for element in $@; do
let factorcheck=$(( element % 2 ))
if [[ $factorcheck -eq 0 ]]; then
let sum=sum+1
fi
done
echo $sum
}
num_factor
The expected output am trying to achieve should be something similar to this:
$num_factor 12 4 6 1 5
4
Thanks.