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

Resolving the “[!: command not found” Error in the Shell

Error in Shell: [!: command not found

1. Error in Shell: [!: command not found, as shown in Figure 1

Error in Shell: [!: command not found
Figure 1
Plaintext
2020/5/6 下午2:56:57 PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH=/var/log/pcs
2020/5/6 下午2:56:57 /config/init/console_init.sh: line 40: [!: command not found
2020/5/6 下午2:56:57 running chown -R nginx:nginx /var/log/pcs
2020/5/6 下午2:56:57 /config/init/cronlog.sh: line 4: LOG_NAME: unbound variable
2020/5/6 下午2:56:58 Unlinking stale socket /var/run/supervisor/supervisor.sock

2. Edit /build/c_files/config/init/console_init.sh. Add spaces before and after []. As shown in Figure 2

Edit /build/c_files/config/init/console_init.sh. Add spaces before and after [].
Figure 2
ShellScript

env | grep PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH || export PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH="/var/log/pcs"
if [[ $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH != "" ]]
then
    if [! -d $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH]
    then
        mkdir -p $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH
    fi
    chown -R nginx:nginx $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH
    echo "running chown -R nginx:nginx $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH"
else
    echo "please set environment variable PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH can not be empty"
fi

ShellScript

env | grep PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH || export PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH="/var/log/pcs"
if [[ $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH != "" ]]
then
    if [ ! -d $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH ]
    then
        mkdir -p $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH
    fi
    chown -R nginx:nginx $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH
    echo "running chown -R nginx:nginx $PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH"
else
    echo "please set environment variable PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH can not be empty"
fi

3. The error no longer appears in the Shell. The error: Unlinking stale socket /var/run/supervisor/supervisor.sock has also disappeared. As shown in Figure 3

The error no longer appears in the Shell. The error: Unlinking stale socket /var/run/supervisor/supervisor.sock has also disappeared.
Figure 3
Plaintext
2020/5/8 下午2:17:09 PCS_API_CFG_ACTION_LOG_ABSOLUTE_PATH=/var/log/pcs
2020/5/8 下午2:17:09 running chown -R nginx:nginx /var/log/pcs
2020/5/8 下午2:17:09 /config/init/cronlog.sh: line 4: LOG_NAME: unbound variable

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

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

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

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

关于我  ·  GitHub  ·  邮件联系