0

I have the following bash script (test_script.sh):

#!/bin/sh
case=test

var1=90 echo "var1 = $var1"

var2=$(( var1 * 4 )) echo "var2 = $var2"

if (( var1 > 80 )) then pot=filled else pot=empty fi

cat > message.txt << EOF

Hellow world! The pot is $pot . EOF

The output of this script is:

var1 = 90
var2 = 360
./test_script.sh: 10: ./test_script.sh: var1: not found

What is the cause for this "var1: not found" message ?

Thanks.

physu
  • 199
  • Your if statement is missing the "$": if (( $var1 > 80 )) – eblock Jun 18 '20 at 08:38
  • eblock, That didn't work. when I do that the message is: "90: not found" – physu Jun 18 '20 at 08:52
  • 1
    See the question marked as duplicate, it's the same issue. You are running your script with sh, not bash. In sh scripts, (( ... )) is just a nested subshell, not an arithmetic evaluation at all. – Kusalananda Jun 18 '20 at 08:54
  • 1
    @eblock If this was running with bash (not sh), the (( ... )) introduces an arithmetic context. There is no need to use $ on variables in arithmetic contexts in bash. – Kusalananda Jun 18 '20 at 08:56

0 Answers0