gpt4 book ai didi

linux - 意外标记附近的语法错误

转载 作者:太空狗 更新时间:2023-10-29 11:15:34 25 4
gpt4 key购买 nike

./csf_install.sh: line 30: syntax error near unexpected token `CHECK_distro'
./csf_install.sh: line 30: `CHECK_distro()'

我的代码:

    if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then
$BIN_ECHO " must be root to run this script "
exit 1
else
$BIN_ECHO -e " permission check passed "
fi
CHECK_architecture()
CHECK_distro()
...
CHECK_architecture()
{
architecture=`uname -m`
if [ "$architecture" != "x86_64" ] && [ "$architecture" != "ia64" ]; then
architecture="x86"
else
architecture="x86_64"
fi
}

CHECK_distro()
{
DISTRO="";
if [ `uname -r | egrep '(6.2-RELEASE|6.1-RELEASE|5.5-RELEASE|6.1-STABLE|5.4-RELEASE|6.0-RELEASE|5.3-RELEASE|4.10-RELEASE|4.11-RELEASE)'` ]; then
DISTRO="FreeBSD";
$BIN_ECHO " System is running FreeBSD"
elif [ -f /etc/debian_version ]; then
$BIN_ECHO " System is running Debian Linux"
DISTRO=DEBIAN;
elif [ -f /etc/SuSE-release ]; then
$BIN_ECHO " System is running SuSE Linux"
DISTRO=SUSE;
elif [ -f /etc/fedora-release ]; then
$BIN_ECHO " System is running Fedora Linux"
DISTRO=FEDORA;
elif [ -f /etc/redhat-release ]; then
$BIN_ECHO " System is running Red Hat Linux"
DISTRO=REDHAT;
else
$BIN_ECHO -e " no supported distribution found running "
exit 1
fi
}

是不是我的校验码错了?还是我如何履行职责?功能是否需要放在第一位?

还有

是否有更好的方法来检查和设置操作系统的分布?

最佳答案

要调用函数,请不要使用 ()(您可以像调用任何其他 shell 命令一样调用它们):

CHECK_architecture
CHECK_distro

您可能还想在使用函数之前声明它们以避免任何麻烦。

关于linux - 意外标记附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12788296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com