0
num1 = 20
num2 = 20

echo $(( num1 + num2 ))
echo $(( num1 - num2 ))
echo $(( num1 * num2 ))
echo $(( num1 / num2 ))
echo $(( num1 % num2 ))

Error :

./practice.sh: line 53: num1: command not found
./practice.sh: line 54: num2: command not found
0
0
0
./practice.sh: line 59: num1 / num2 : division by 0 (error token is "num2 ")
./practice.sh: line 60: num1 % num2 : division by 0 (error token is "num2 ")

What am I missing? When I tried some number instead of num1 and num2 inside echo. I notice that it was printing correctly.. But, What is happening right here..?

  • 1
    Typo: There can be no spaces around = in an assignment. – Kusalananda Apr 06 '21 at 07:11
  • There should be no spaces either side of = on the first 2 lines. – fpmurphy Apr 06 '21 at 07:12
  • I wonder why this is off-topic? The fact that the question's title contains the word "programming" doesn't mean that it's a programming question. – berndbausch Apr 06 '21 at 07:24
  • @berndbausch It's off topic because it's a typo. "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." If you wish, I could reopen it and immediately close it as a duplicate of the question in my previous comment. – Kusalananda Apr 06 '21 at 07:36
  • @Kusalananda I agree that this is certainly not the first time the question was asked, and it is indeed a duplicate, but reopening would be a bit too much. Sorry for making you waste your time, but on the other hand I learned something. – berndbausch Apr 06 '21 at 11:31

1 Answers1

0
num1=20
num2=20

When I tried with removing spaces from num1 and num2. I notice it's working

  • Downloading from shellcheck.net is an excellent investment in your future. In this case, it says: SC1068: Don't put spaces around the = in assignments. – Paul_Pedant Apr 06 '21 at 09:06