0
I am creating a function in shell script that says if the number is prime or not, but I am getting a syntax error in for loop that the function has and I could not find how to fix.
# ...
9 ehPrimo() {
10 n=$0
11 numDivisores=1
12
13 for (( i = 2; i < n/2; i++ ))
14 do
15 if [ n%2==0 ]
16 then
17 numDivisores++
18 fi
19 done
20 if [ numDivisores == 1 ]
21 then
22 return 1
23 else
24 return 0
25 fi
26 }
27
28 echo $(ehPrimo 2)
# ...
The mistake is:
./arquivo.sh: line 13: ((: ./arquivo.sh: syntax error: operand expected (error token is "./arquivo.sh")
I tidied up the logical part here but no more problems with syntax, thank you! I would like to understand what this is
*
in theecho "* primo"
, would be replaced by$1
? Why here he only prints the asterisk even so I switched the line byecho "$1 primo"
.– g-otn
echo "* prime" is just a message.... within quotation marks the "*" has no special meaning
– zentrunix