首页 > 解决方案 > Shell 脚本 - 如何将脚本导出为字符串?

问题描述

我有一个大型 shell 脚本,我试图在 VM 启动时附加到 bashprofile:

我希望将此脚本附加bashrc文件中。我尝试了以下方法:

read -d '' load_script << EOF
// code here
EOF

但它会自动开始评估变量,我只想将此脚本推送到 bashrc 文件中。我怎样才能做到这一点?

脚本

writer_endpoint=$(aws neptune describe-db-clusters --db-cluster-identifier redacted | jq .DBClusters[0] | jq .Endpoint | tr -d '"')
reader_endpoint=$(aws neptune describe-db-clusters --db-cluster-identifier redacted | jq .DBClusters[0] | jq .ReaderEndpoint| tr -d '"')
writer_endpoint_status=$(awscurl https://$writer_endpoint:8182/status --service neptune-db | jq .status)
reader_endpoint_status=$(awscurl https://$reader_endpoint:8182/status --service neptune-db | jq .status)
cat << EOF

                +==========+===============+
                | Endpoint | Health Status |
                +==========+===============+
                | Reader   | $writer_endpoint_status     |
                +----------+---------------+
                | Writer   | $reader_endpoint_status     |
                +----------+---------------+

********************************************************************************************************
Welcome to the bastion host, used to debug connectivity and queries against the Neptune graph DB.
********************************************************************************************************

[Reader Endpoint]:
$reader_endpoint

[Writer Endpoint]:
$writer_endpoint

[Example - Check status of reader replica]:
awscurl https://$writer_endpoint:8182/status --service neptune-db

*******************************************************************************************************

标签: bashshell

解决方案


推荐阅读