我有一个脚本在我的桌面上触发时,工作正常curl -sL https://sentry.io/get-cli/ | bash
。
当我curl
从嵌入式设备调用上面相同的命令时,我得到:
bash: line 22: !DOWNLOAD_URL_LOOKUP: unbound variable
为什么这种情况只发生在较旧的嵌入式设备上?(Ubuntu 14.04、GNU bash、版本 4.3.11(1)-release (arm-unknown-linux-gnueabihf))
相关脚本:
#!/bin/bash
set -eu
SENTRY_DOWNLOAD_Darwin_x86_64="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Darwin-x86_64"
SENTRY_DOWNLOAD_Linux_i686="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Linux-i686"
SENTRY_DOWNLOAD_Linux_x86_64="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Linux-x86_64"
SENTRY_DOWNLOAD_Windows_i686="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Windows-i686.exe"
SENTRY_DOWNLOAD_Windows_x86_64="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Windows-x86_64.exe"
VERSION="1.26.0"
PLATFORM=`uname -s`
ARCH=`uname -m`
# If the install directory is not set, set it to a default
if [ -z ${INSTALL_DIR+x} ]; then
INSTALL_DIR=/usr/local/bin
fi
if [ -z ${INSTALL_PATH+x} ]; then
INSTALL_PATH="${INSTALL_DIR}/sentry-cli"
fi
DOWNLOAD_URL_LOOKUP="SENTRY_DOWNLOAD_${PLATFORM}_${ARCH}"
DOWNLOAD_URL="${!DOWNLOAD_URL_LOOKUP}"
echo "This script will automatically install sentry-cli ${VERSION} for you."
echo "Installation path: ${INSTALL_PATH}"
if [ "x$(id -u)" == "x0" ]; then
echo "Warning: this script is currently running as root. This is dangerous. "
echo " Instead run it as normal user. We will sudo as needed."
fi
if [ -f "$INSTALL_PATH" ]; then
echo "error: sentry-cli is already installed."
exit 1
fi
if [ x$DOWNLOAD_URL == x ]; then
echo "error: your platform and architecture (${PLATFORM}-${ARCH}) is unsupported."
exit 1
fi
if ! hash curl 2> /dev/null; then
echo "error: you do not have 'curl' installed which is required for this script."
exit 1
fi
TEMP_FILE=`mktemp "${TMPDIR:-/tmp}/.sentrycli.XXXXXXXX"`
cleanup() {
rm -f "$TEMP_FILE"
}
trap cleanup EXIT
curl -SL --progress-bar "$DOWNLOAD_URL" > "$TEMP_FILE"
chmod 0755 "$TEMP_FILE"
if ! mv "$TEMP_FILE" "$INSTALL_PATH" 2> /dev/null; then
sudo -k mv "$TEMP_FILE" "$INSTALL_PATH"
fi
echo 'Done!'
答案1
这里没有太多信息,但是您是否获取了变量?如果是这样,则尝试通过在set +u
源文件之前调用来禁用源文件的变量严格性,然后立即启用它set -u
答案2
我想我明白发生了什么。DOWNLOAD_URL_LOOKUP
被设置为SENTRY_DOWNLOAD_Linux_armv7l
.
然后是行:
DOWNLOAD_URL="${!DOWNLOAD_URL_LOOKUP}"
尝试DOWNLOAD_URL
根据开始时设置的变量来映射:
SENTRY_DOWNLOAD_Darwin_x86_64="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Darwin-x86_64"
SENTRY_DOWNLOAD_Linux_i686="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Linux-i686"
SENTRY_DOWNLOAD_Linux_x86_64="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Linux-x86_64"
SENTRY_DOWNLOAD_Windows_i686="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Windows-i686.exe"
SENTRY_DOWNLOAD_Windows_x86_64="https://github.com/getsentry/sentry-cli/releases/download/1.26.0/sentry-cli-Windows-x86_64.exe"
由于这些不包括SENTRY_DOWNLOAD_Linux_armv7l
返回错误。如果我为我的版本添加 url,脚本将运行:
SENTRY_DOWNLOAD_Linux_arm7l="https://google.com"
此外,似乎脚本对于这种情况有一条错误消息,但它set -u
导致程序在引用未设置的变量时退出。