I'm trying to figure out how to pass an argument with a function call from one function to another in the same bash script. Here's what I've got so far:
#!/usr/bin/env bash
# File: nevens.sh
function isiteven {
if (( "$element%2"=="0" ))
then
echo 1
fi
}
function nevens {
local result=0
for element in $@
do
if (( $(isiteven) == 1 )) # $(isiteven "$element")
then
result=$result+1
fi
done
echo $result
}
I've tried calling $(isiteven)
and hard-coding $element
in front of %2==0
inside the isiteven function. And I've tried passing the argument with the function call, either $(isiteven $element)
or $(isiteven "$element")
, but then I'm not sure what I should code in front of %2==0
to do the math.
I'm using Ubuntu 18.04 on a dedicated machine.