shell脚本中的文件意外结束

时间:2013-02-01 09:30:30

标签: shell

我有脚本:

#!/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

当我尝试像./script.sh那样执行它时,我得到一个错误行19:意外的文件结束。我做错了什么?

1 个答案:

答案 0 :(得分:1)

检查您的行结尾。当我运行你的脚本(在Cygwin下),没有给出参数时,如果我有Windows样式的行结尾(\r\n),我会收到你的错误。当我使用Unix风格的行结尾时,通过消除\r,脚本运行,抱怨我没有给出正确的参数。