为什么我会收到"意外的文件结束"?

Env*_*vin 1 bash

我正在按照教程解析参数.当我使用或不使用参数运行脚本时,我得到"第45行:语法错误:意外的文件结束".这是脚本中最后一行之后的行.我只是没有看到错误(bash脚本新...).

#!/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
Run Code Online (Sandbox Code Playgroud)

dou*_*own 8

这是因为你缩进了EOF这里

argumentUsage(){
     ...
     OPTIONS:
       -h    Show this message
       -s    Source location
       -d    Destination location
     EOF
}
Run Code Online (Sandbox Code Playgroud)

由于缩进,bash没有"看到"终止EOF,所以有效地你的here-doc没有终止,这导致"意外的文件结束".