Bash脚本问题,我是Bash新手,无法理解语法错误



我是bash脚本的新手,我正在编写一个脚本,将新工件部署到AWS Elasticbeanstalk,而不是转到AWS UI,开发人员需要很长时间。请看看下面,让我知道,如果我做错了什么。我很担心这一部分:If ["$1"=";别人;帮助<<EOF然后读-r -d "用法:t$(basename $0) list -列出所有应用程序t$(basename $0) deploy -将工件部署到环境中EOF死,别人"美元;退出0fi

运行脚本:AWS_PROFILE=default ARTIFACT_BUCKET=myawsstudybucket ARTIFACT_NAME=artifact1.zip ./deploy.sh deploy demo-app Demoapp-env artifact.zip

#!/bin/bash
PROFILE=$(aws sts get-caller-identity --query Account)
RED='33[0;31m'
COLOR_OFF='33[0m'
if [ -z "$PROFILE" ] 
then
echo "Credentials missing"
else 
region=$(aws configure get region)
fi
if [ "$1" = "list" ]
then 
echo $(aws elasticbeanstalk describe-applications --query "Applications[].ApplicationName")
exit 0
fi
if [ "$1" = "help" ] HELP <<EOF
then
read -r -d ''
Usage:
t$(basename $0) list - list all applications
t$(basename $0) deploy <app-name> <environment-name> <local-artifact-path> - deploy artifact to an environment
EOF
die "$HELP"
exit 0
fi
die() { echo -e "$*" >&2; exit 1; }
[[ -z $EB_APP ]] && die "ERROR: Missing application name"
[[ -z $EB_ENV ]] && die "ERROR: Missing application environment"
[[ -z $EB_ARTIFACT ]] && die "ERROR: Missing application artifact location"
s3path="s3://$ARTIFACT_LOCATION/$ARTIFACT_NAME"
aws s3 cp $artifactpath $s3path
versionlabel=$(date +%s%N)
aws elasticbeanstalk create-application-version --application-name "$ebapp" --version-label $versionlabel --source-bundle S3Bucket=$ARTIFACT_LOCATION,S3Key=$ARTIFACT_NAME
aws elasticbeanstalk update-environment --environment-name $ebenv --version-label $versionlabel
echo "Deployment in progress"
while [[ "$STATUS" != OK ]] && [[ "$STATUS" != Severe ]];
do
echo "Checking environment status"
status=$(aws elasticbeanstalk describe-environment-health --environment-name $ebenv --attribute-names HealthStatus --query "HealthStatus"| tr -d '"')
echo "Current status: $status."
sleep 5
done
echo "Deployed successfully"

这部分确实很奇怪。在]后面的HELP应该做什么?

您可能想要像

这样的内容
if [ "$1" = "help" ]
then
echo Press Enter to display the help...
read
cat <<-EOF
Usage:
$(basename $0) list - list all applications
$(basename $0) deploy <app-name> <environment-name> <local-artifact-path> - deploy artifact to an environment
EOF
fi

注意,在结束EOF之前需要真正的选项卡

或者你想要这个?

die() { echo -e "$*" >&2; exit 1; }
if [ "$1" = "help" ]
then
HELP="
Usage:
$(basename $0) list - list all applications
$(basename $0) deploy <app-name> <environment-name> <local-artifact-path> - deploy artifact to an environment
"
die "$HELP"
fi

带引号的字符串可以是多行

注意在调用die之前必须声明它。

相关内容

  • 没有找到相关文章

最新更新