Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying

for i in {4..100}
do
  is_prime=true
  a=$(($i-1))
  for divider in {2..$a}
  do  
    b=$(($i % $divider)) # <-- line 9
    [ $b -eq 0 ] && echo 'y' #is_prime=false
  done
  [ is_prime == true ] && print "${i} is prime!"
done

but I get

$ ./3_largest_prime.sh 
./3_largest_prime.sh: line 9: 4 % {2..3}: syntax error: operand expected
(error token is "{2..3}")
share|improve this question

marked as duplicate by don_crissti, jordanm, 1_CR, jasonwryan, slm Jan 1 at 6:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

If you put

set -xv  

in your script, you might be able to detect why there is an error.

In your script, it will output this line:

+for divider in '{2..$a}'

Notice the expansion did not occur. Read through the linked duplicates to identify how to fix it.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.