0
#!/bin/bash


# This is a comment
clear
echo "----------------------------------------"
read -p "please enter the first number" a
read -p "please enter the second number" b

sum = $(($a + $b))
sub = $(($a - $b))

echo "$a + $b = $sum"
echo "$a -$b = $sub"
echo "------------------------------------------"

This is my shell script(test3.sh), When i run by using

bash test3.sh

I am getting the following error error

Bhargav
  • 454
  • 1
  • 6
  • 15

1 Answers1

2

Fix the syntax issues in variable assignment which should have been

sum=$(($a + $b))
sub=$(($a - $b))

Since you haven't specified that, bash tried to execute the sum as an executable with = and $(($a + $b)) as its arguments.

Also you could get rid of the $ symbol inside the arithmetic evaluation context and just do

sum=$((a + b))
sub=$((a - b))

Always use http://www.shellcheck.net to fix the syntax issues from the script.

Inian
  • 80,270
  • 14
  • 142
  • 161