Closed ademouerghi closed 7 years ago
I don't think this is correct though, you are just checking if the number is divisible by 2, not if it is a prime (try 9 for example, it is not a prime).
I could not actually try your command though, I'm guessing there is a formatting issue.
Some tips:
I would recommend you to use $()
instead of \
`for executing commands using bash, its more readable and allows you to nest expressions (for example
$(du -hs $(head -n 1 logfile))). Moreover you don't need the
inputvariable, you should simply be able to do
< random-numbers.txt`
and this one not working too
`input="random-numbers.txt"
while IFS= read -r var
do
prime=1
vari=$(($var/2))
for core in $(seq 2 $vari); do
if (($var%$core==0))
then
prime=0
fi
done
if (($prime==1));
then
echo $var
fi
done < "$input"|wc -l
Closing this as I don't think there is a real issue here.
This how i solve find_primes but it doesn't work
input="random-numbers.txt" while IFS= read -r var do if [
expr $var % 2-eq 1 ] then echo $var fi done < "$input"|wc -l