How to perform addition of two numbers in shell scripting in Solaris-10

Hi,

I have a sh script which contains the following line

TOTAL=$((e4-s4)) -> Where e4 and s4 are input got from the user.

At the time of execution of this line the following error occurs

test.sh: syntax error at line 8: `TOTAL=$' unexpected

How to solve this issue?. Can any one help me please?.........................

Regards
Revathi

We need to see the rest of the script to tell why that statement was unexpected.

I don't know the $((...)) syntax, but it could be from a more exotice shell and not recognised by the Bourne shell.
This should work (for integer arithmetic):
let total=e4-s4

The following is more portable:

TOTAL=`expr $e4 - $s4`

From the syntax $((expression)) it looks like your script was probably written to take advantage of
specific features in the bash shell. As a result your shell script will not be very portable to
non-Linux/GNU systems unless bash is available on these systems.

Below is my script

#!/bin/bash
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=$(($e4 - $s4))
echo "Total is $TOTAL"

Any idea

You suggestion does not work.
Below is my script

#!/bin/bash
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=$(($e4 - $s4))
echo "Total is $TOTAL"

Any idea

You suggestion does not work.
Below is my script

#!/bin/bash
echo "Enter the start IP"
IFS="."
read s1 s2 s3 s4
echo "Enter the End IP"
IFS="."
read e1 e2 e3 e4
TOTAL=$(($e4 - $s4))
echo "Total is $TOTAL"

Any idea

Your script is fine. Can you let us know how you are running it? As in, is the script an executable and are you running as: ./test.sh? Or are you running the script as: sh test.sh?

My guess is that it is the latter. In that case, the first line (#!/bin/bash) does not matter, and you are running the script using /bin/sh - which does not support $(( )).

Suggest that you follow fpmurphy's suggestion or make the script executable and run as ./test.sh

Thanks for ur valuable reply.........

TOTAL=`expr $e4 - $s4`
The above works fine..............
The error i did is i din leave space between the variables(i.e TOTAL=`expr $e4-$s4`)

Thanks
Revathi

Works fine for me as test.sh with a chmod +x on it (bash shell)