猫EOF压痕问题 [英] cat EOF issues with indentation

查看:155
本文介绍了猫EOF压痕问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


注意:如果有人觉得这个问题已经被回答,请在下面粘贴您的答案,否则请不要干扰试图帮助某人的人
需要帮助。谢谢

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

有人可以指出如何关闭此Heredoc块

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

但是问题是猫

文件内容 /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

但这是期望看到的

version: '3.5'
services:
onboarding:
    container_name: nginx
    image: nginx:${BuildId}
    restart: always
      ports:
      - 80:80
    environment:
      ENV: ${Env}
      AWS_REGION: ${Region}
      NONCE: $NONCE

首先,为什么这里heredoc并非如此即使有压痕也很简单?我知道当内容中完全没有空格时,它会很好地工作,但我不知道为什么当内容中包含空格时,为什么这么麻烦

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

推荐答案

您写了<-EOF ,而我认为您打算写<< EOF

You have written <<-EOF, when I think you meant to write <<EOF.

Bash不会关闭您的Heredoc,因为它希望 -EOF 关闭它,因为您如何打开Heredoc。将结尾从 EOF 更改为 -EOF ,或者,这就是我的建议,将< -EOF << 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 from EOF to -EOF, or, and this is what I'd suggest, change <<-EOF to <<EOF.

这篇关于猫EOF压痕问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆