Home > Mobile >  When executing bash script file it shows a syntax error
When executing bash script file it shows a syntax error

Time:12-01

This is my code :

 #! /bin/bash
    
    read x 
    read y

if (( $x -lt $y  ))
then
    echo "X is less than Y "
elif (( $x -eq $y ));
then
    echo "X is equal to Y "
else
    echo "X is greater than Y" 

fi

I get this error :

Solution.sh: line 6: ((: 5 -lt 2 : syntax error in expression (error token is "2 ")
Solution.sh: line 9: ((: 5 -eq 2 : syntax error in expression (error token is "2 ")

It will show syntax error but I don't know what is error in this code?

CodePudding user response:

The correct syntax is like this:

#!/bin/bash
    
    read x 
    read y

if (( $x < $y  ))
then
    echo "X is less than Y "
elif (( $x == $y ));
then
    echo "X is equal to Y "
else
    echo "X is greater than Y" 

fi
  • Related