0

I have script:

#!/bin/sh
PSQLPATH=$1
USER=$2
if [ -z ${PSQLPATH} ]; then
   echo "incorrect path param"
   echo "Usage: $0 psqlpath username"
   exit 1
fi
if [ -z ${USER} ]; then
   echo "incorrect username param"
   echo "Usage: $0 psqlpath username"
   exit 1
fi
${PSQLPATH}/createdb -h localhost -U ${USER} highway2
${PSQLPATH}/psql -f createDatatable.sql -h localhost -d highway2 -U ${USER}
${PSQLPATH}/psql -f insertStatements.sql -h localhost -d highway2 -U ${USER}
echo "execute passed"
exit 0

When I am trying to execute it like ./script.sh I got an error line 19: unexpected end of file. What I am doing wrong?

4
  • From my experience with bash, this error occurs if you have some minor syntax problem. Commented Feb 1, 2013 at 9:37
  • I m trying to find it, but I cant Commented Feb 1, 2013 at 9:39
  • Are you working in Cygwin, by chance? Commented Feb 1, 2013 at 9:41
  • Yes! From Windows. But connected throw ssh to host with ubuntu Commented Feb 1, 2013 at 9:42

1 Answer 1

1

Check your line endings. When I run your script (under Cygwin), with no arguments given, I get your error if I have Windows-style line endings (\r\n). When I use Unix-style line endings, by eliminating the \rs, the script runs, complaining about my not having given the correct parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

You are genius! I am editing this code in sublime, so I gone to View -> Line endings -> unix style. Tnx you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.