2
#!/bin/bash

f=1
c=$1
while [[ $c != 0 ]]
do
        $f=$(($c*$f))
        $c=$(($c-1))
done
echo $c

I keep getting the error

./process.sh: line 8: 1=0: command not found
./process.sh: line 7: 5=5: command not found

When running ./process.sh 5

2
  • Your loop starts with c=1 and then runs while c!=0 and it subtracts 1 from c each time? That's not much of a loop. Commented Mar 10, 2013 at 0:37
  • I changed the mistake Commented Mar 10, 2013 at 0:38

2 Answers 2

5

The $ means "value of" so $f gets evaluated to the string literal 1. So...

    $f=$(($c*$f))
    $c=$(($c-1))

should be

    f=$(($c*$f))
    c=$(($c-1))
Sign up to request clarification or add additional context in comments.

Comments

1

in the loop, it should be

f=$(($c*$f))
c=$(($c-1))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.