没有不值得去解决的问题,也没有不值得去学习的技术!

How to Avoid the $APPID$ Error in Shell Scripts: Analyzing the “unbound variable” Issue in /config/init/config0.sh

At runtime, the error no longer occurs. Checking the runtime log confirms no further errors.

1. In a Shell script, the following runtime error occurred: /config/init/config0.sh line 184 APPID unbound variable. See Figure 1.

In the Shell script, a runtime error occurred: configinitconfig0.sh line 184 APPID unbound variable.
Figure 1
Plaintext
<br>/config/init/config0.sh: line 184: APPID: unbound variable<br><br>

2. Inspecting the Shell script, the assignment is: https://console.${RMT_MAIN_DOMAIN}/ccpauth/wx-msg-event/$APPID$/receive. ${RMT_MAIN_DOMAIN} needs to be replaced with dev.xxx.cn. $APPID$ should not be replaced and must remain as is, but it is now being treated as a variable. This causes the error.

ShellScript

if [[ `echo $RMT_MAIN_DOMAIN` == '' ]]
then
    echo "需要设置 RMT_MAIN_DOMAIN"
    exit 1
else
    echo "设置的 RMT_MAIN_DOMAIN 为:$RMT_MAIN_DOMAIN"
fi

env | grep "CHANNEL_PUB_API_CFG_WX_OPEN_COMPONENT_MSG_EVENT_RECEIVE" || export CHANNEL_PUB_API_CFG_WX_OPEN_COMPONENT_MSG_EVENT_RECEIVE="https://console.${RMT_MAIN_DOMAIN}/ccpauth/wx-msg-event/$APPID$/receive"

3. Edit the Shell script to change $APPID$ to \$APPID\$. Add an escape character before each $. The code is as follows:

ShellScript

env | grep "CHANNEL_PUB_API_CFG_WX_OPEN_COMPONENT_MSG_EVENT_RECEIVE" || export CHANNEL_PUB_API_CFG_WX_OPEN_COMPONENT_MSG_EVENT_RECEIVE="https://console.${RMT_MAIN_DOMAIN}/ccpauth/wx-msg-event/\$APPID\$/receive"

4. At runtime, the error no longer occurs. Checking the runtime log confirms no further errors. See Figure 2.

At runtime, the error no longer occurs. Checking the runtime log confirms no further errors.
Figure 2
ShellScript

CHANNEL_PUB_API_CFG_WX_OPEN_COMPONENT_MSG_EVENT_RECEIVE replace https://console.dev.xxx.cn/ccpauth/wx-msg-event/$APPID$/receive -> /mcloud/www/ccp_api/environments/dev/common/config/params-local.php

5. Check the final replacement result in /mcloud/www/ccp_api/environments/dev/common/config/params-local.php. ${RMT_MAIN_DOMAIN} has been replaced with dev.xxx.cn. $APPID$ was not replaced and remains as is. This matches the expected outcome. See Figure 3.

Check the final replacement result in /mcloud/www/ccp_api/environments/dev/common/config/params-local.php. ${RMT_MAIN_DOMAIN} has been replaced with dev.xxx.cn. $APPID$ was not replaced and remains as is. This matches the expected outcome.
Figure 3

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系