Reputation: 1523
I was following this tutorial on parsing arguments. When I run my script with or without arguments I get "line 45: syntax error: unexpected end of file". This is the line after the last line in the script. I simply don't see the error though (new to bash scripting...).
#!/bin/bash
#Explain arguments that can be passed in
argumentUsage(){
cat << EOF
usage: $0 options
This script configures rsync to backup SOURCE to DESTINATION and provide notifications on status.
OPTIONS:
-h Show this message
-s Source location
-d Destination location
EOF
}
DESTINATION=
SOURCE=
while getopts "hs:d:" OPTION
do
case $OPTION in
h)
argumentUsage()
exit1
;;
s)
SOURCE=$OPTARG
;;
d)
DESTINATION=$OPTARG
;;
?)
argumentUsage()
exit
;;
esac
done
Upvotes: 1
Views: 959
Reputation: 8408
It's because you indented the EOF
here
argumentUsage(){
...
OPTIONS:
-h Show this message
-s Source location
-d Destination location
EOF
}
Due to the indentation, bash doesn't "see" the terminating EOF
, so effectively your here-doc is unterminated, which leads to “unexpected end of file”.
Upvotes: 8