[[::在bash中找不到

 aloneloveu2005 发布于 2023-02-05 12:37

我的bash脚本出现以下错误.

ncompile.sh: 1: ncompile.sh: ###: not found
ncompile.sh: 52: ncompile.sh: [[: not found
Chose your Operating System. {Supported OS: Debian, Ubuntu, Fedora, CentOS, FreeBSD}
Debian
ncompile.sh: 61: ncompile.sh: [[: not found
ncompile.sh: 61: ncompile.sh: [[: not found
ncompile.sh: 70: ncompile.sh: [[: not found
ncompile.sh: 70: ncompile.sh: [[: not found
ncompile.sh: 79: ncompile.sh: [[: not found
Pick a valid OS

使用此脚本:

###
### Functions to simplify stuff :)
###

debianDeps() {
    apt-get install git cmake build-essential liblua5.2-dev \
        libgmp3-dev libmysqlclient-dev libboost-system-dev
}

fedoraDeps() {
    yum install git cmake gcc-c++ boost-devel \
        gmp-devel community-mysql-devel lua-devel
}

bsdDeps() {
    cd /usr/ports/shells/bash && make install clean BATCH=yes
    cd /usr/ports/devel/git && make install clean BATCH=yes
    cd /usr/ports/devel/cmake && make install clean BATCH=yes
    cd /usr/ports/lang/gcc47 && make install clean BATCH=yes
    cd /usr/ports/lang/luajit && make install clean BATCH=yes
    cd /usr/ports/devel/boost-libs && make install clean BATCH=yes
    cd /usr/ports/math/gmp && make install clean BATCH=yes
    cd /usr/ports/databases/mysql-connector-c && make install clean BATCH=yes
}

libInstall() {
    echo "Libraries and Build Tools... Installed"
}

bsdBuild() {
    echo "Building on FreeBSD"
    mkdir build && cd build
    CXX=g++47 cmake ..
    make
}   

genBuild() {
    echo "Building..."
    mkdir build && cd build
    cmake ..
    make
}

clean() {
    mv *.cpp *.h src/ && mv *.o objs/
    echo "There might be a few leftover files."
}

###
### Script starts here
###
if [[ $EUID -ne 0 ]]; then
    echo "You must be root to use this script, press enter to exit."
    read end
    exit 1
fi

echo "Chose your Operating System. {Supported OS: Debian, Ubuntu, Fedora, CentOS, FreeBSD} "
read ans1 

if [[ $ans1 = "Fedora" ]] || [[ $nas1 = "CentOS" ]]; then
    echo -n "Should the script install dependencies? y/n"
    if [[ $ans1_1 = "y" ]]; then
        fedoraDeps
    elif [[ $ans1_1 = "n" ]]; then
        break
    else
        echo "Answer '\y\' or \'n\' "
    fi
elif [[ $ans1 = "Debian" ]] || [[ $ans1 = "Ubuntu" ]]; then
    echo -n "Should the script install dependencies? y/n"
    if [[ $ans1_1 = "y" ]]; then
        debianDeps
    elif [[ $ans1_1 = "n" ]]; then
                            break
                        else
                            echo "Answer '\y\' or \'n\' "
                        fi
elif [[ $ans1 = "FreeBSD" ]]; then
    echo -n "Should the script install dependencies? y/n"
        if [[ $ans1_1 = "y" ]]; then
            bsdDeps
        elif [[ $ans1_1 = "n" ]]; then
            break
        else
            echo "Answer '\y\' or \'n\' "
        fi

        else
            echo "Pick a valid OS"

        fi

Zulu.. 5

你应该从第一行插入bash she-bang开始:

#!/bin/bash

我认为你的脚本基本上使用sh.shell只支持简单的括号([).

1 个回答
  • 你应该从第一行插入bash she-bang开始:

    #!/bin/bash
    

    我认为你的脚本基本上使用sh.shell只支持简单的括号([).

    2023-02-05 12:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有