If statement throws unexpected end of file in shell script

bash, linux, shell

Solution

Try replacing the last line (`endif`) with `fi`, which is the correct token to close an `if` statement.

Also, replace `($2 == "both")` with the correct `[ $2 == "both" ]`.

Oh, and then, actually the `if` should be written as:

   if [ "$2" = "both" ]; then
      echo 'bye'
   else
      echo 'hi'
   fi

Note the quotes around `$2`, the spaces after `[` and before `]` and the `;` before the `then`.

Problem

Whenever I run this script the find part executes but the if statement causes this error: ``` ./list_datasheets.csh: line 13: syntax error: unexpected end of file ``` this is the script: ``` find $1 -type d | while read -r dir do for f in ${dir}/* do echo ${f} | tr '[A-Z]' '[a-z]' done done if ($2 == "both") then echo 'bye' else echo 'hi' endif ```

Original source