[SOLVED] Problems with function on Shell Script

Issue

Trying to test functions on ShellScript, but I keep receiving the answer: "Command not found"

# Trying to create functions that receives arguments e have returns
# The function will receive two values and say hwo is bigger

bigger () {
if [$1 -gt $2]
then
   return $1
else
   return $2
fi
}

echo "Size does matter!!!!"
echo " "
printf "Enter the first number: - "
read data1
echo " "
printf "Enter the second number: - "
read data2
echo " "
printf "The bigger number is: - "
bigger $data1 $data2

The result I get is:

enter image description here

Solution

You have a syntax error and bash tries to interpret [1 as a command.
Add spaces to fix this

Change

if [$1 -gt $2]

to

if [ "$1" -gt "$2" ]

Answered By – Tolis Gerodimos

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.