0
#!/bin/bash
read -p "Enter first number: " num1
read -p "Enter Second number: " num2
if [$num1 > $num2] ; then
        echo $num1 is greater than $num2
if [$num1 == $num2] ; then
        echo $num1 is equal to $num2
if [$num1 < $num2] ; then
        echo $num1 is less than $num2
else
        echo goodbye
fi

Am I missing something? Whenever I execute a script with an if statement in it I get errors. The example above give me this error

./comp.sh: line 13: syntax error: unexpected end of file

erik258
  • 14,701
  • 2
  • 25
  • 31
  • 2
    Not much of basher but shouldn't these be `elseif`s? Otherwise you'd have 3 unclosed `if`s. e.g. `elif [$num1 == $num2] ; then` – user3783243 Feb 24 '22 at 21:18
  • 1
    almost, they should be `elif`. – erik258 Feb 24 '22 at 21:22
  • 2
    Run it through [ShellCheck](https://www.shellcheck.net) and fix the automatically detected problems, such as missing spaces around `[` and `]`, and use of `>` and `<` instead of `-gt` and `-lt` – that other guy Feb 24 '22 at 21:23
  • While linux and bash may seem synonymous, understanding why they are completely not synonymous will help solidify your knowledge of this ecosystem. `bash` is a program using to interpret a script. That is completely independent from `linux` which is an operating system that runs programs. So I placed with `bash` prior mentions of `linux` in title and tags . – erik258 Feb 24 '22 at 21:25
  • 1
    If you are going to use `bash` extensions like the `-p` option to `read`, you may as well use the arithmetic command as well: `if (( num1 > num2 )); then ` etc. – chepner Feb 24 '22 at 21:27

0 Answers0