这段代码有什么问题?
#!/bin/bash
ARCH=$(uname -m)
if ["$ARCH" = "i686"]; then
zenity --info --title="Architechture Checker" --text="Your Architechture is 32-Bit"
if ["$ARCH" = "x86_64"];then
zenity --info --title="Architechture Checker" --text= "Your Architechture is 64-Bit"
答案1
没有与“if”匹配的“fi”
您需要在“[”和“]”周围添加空格
“--text=”后的空格会导致参数丢失。
工作版本:
#!/bin/bash
ARCH=$(uname -m)
if [ "$ARCH" = "i686" ]; then
zenity --info --title="Architechture Checker" --text="Your Architechture is 32-Bit"
fi
if [ "$ARCH" = "x86_64" ]; then
zenity --info --title="Architechture Checker" --text="Your Architechture is 64-Bit"
fi
答案2
或者,使用 case 代替(也可以使用函数来稍微缩短它)。
#!/bin/bash
zinfo() { zenity --info --title="Architecture Checker" --text="$1"; }
case $(uname -m) in
i686) zinfo "Your architecture is 32-bit" ;;
x86_64) zinfo "Your architecture is 64-bit" ;;
*) zinfo "Your architecture is unknown to me" ;;
esac