This question already has an answer here:
NOTE: If anyone feel this question has been answered before please paste your answer below otherwise please don't interfere with people trying to help someone who needs help. Thanks
I am not sure why it is such an hassle trying to cat content to file when the content is indented
Can anyone point to how to close this heredoc block
UserData:
"Fn::Base64":
!Sub |
#!/bin/bash -xe
NONCE=$(cat /tmp/nonce)
cat <<-EOF > /tmp/docker-compose.yaml
version: '3.5'
services:
onboarding:
container_name: nginx
image: nginx:${BuildId}
restart: always
ports:
- 80:80
environment:
ENV: ${Env}
AWS_REGION: ${Region}
NONCE: $NONCE
EOF
source ~/.bashrc
But issue is cat is not closed properly with the closing "EOF".
Content of the file /tmp/docker-compose.yaml
version: '3.5'
services:
onboarding:
container_name: nginx
image: nginx:${BuildId}
restart: always
ports:
- 80:80
environment:
ENV: ${Env}
AWS_REGION: ${Region}
NONCE: $NONCE
EOF
source ~/.bashrc
but this is what am expecting to see
version: '3.5'
services:
onboarding:
container_name: nginx
image: nginx:${BuildId}
restart: always
ports:
- 80:80
environment:
ENV: ${Env}
AWS_REGION: ${Region}
NONCE: $NONCE
First why is this heredoc not so simple even with indentations? I know it works fine when there are no spaces at all in the content but man not sure why it is such a hassle when content has spaces
Any better alternative as am about to give up on cat because of this problem
Any help will be appreciated Thanks
You have written
<<-EOF
, when I think you meant to write<<EOF
.Bash isn't closing your heredoc because it expects
-EOF
to close it, because of how you opened the heredoc. Either change the ending fromEOF
to-EOF
, or, and this is what I'd suggest, change<<-EOF
to<<EOF
.