Is this the correct syntax for parameterized functions?
#!/bin/bash
twoPow()
{
prod=1
for((i=0;i<$1;i++));
do
prod=$prod*2
done
return prod
}
echo "Enter a number"
read num
echo `twoPow $num`
Output:
bash sample.sh
Enter a number
3
sample.sh: line 10: return: prod: numeric argument required
Part 2:
I removed the return, but what should I do if I want to run multiple times and store results like below? How can I make this work?
#!/bin/bash
tp1=1
tp2=1
twoPow()
{
for((i=0;i<$1;i++));
do
$2=$(($prod*2))
done
}
twoPow 3 tp1
twoPow 2 tp2
echo $tp1+$tp2