在 Shell 中报错:[!: command not found 的分析解决

1、在 Shell 中报错:[!: command not found,如图1

图1

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、编辑 /build/c_files/config/init/console_init.sh。在 [] 前后添加空格。如图2

图2

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
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、在 Shell 中未再报错。且报错:Unlinking stale socket /var/run/supervisor/supervisor.sock 也已经消失。如图3

图3

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
永夜