2014-01-08 40 views
0

我有這個劇本,但在第51行,當我回答「Y」時,bash跳過並告訴我「回答是或否」(跳到第58行):Bash認爲輸入不正確時它是?

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 .. 
    echo "Build on $cpuCores threads with $coreBuild processes? (experimental but loads faster) y or n " 
     read $ans1_4 
      if [[ $ans1_4 = "y" ]]; then 
       echo -e $greenText"Building on $cpuCores threads with $coreBuild ."$none 
       make -j $coreBuild 
      elif [[ $ans1_4 = "n" ]]; then 
       echo -e $blueText"Building on a single thread."$none 
       make 
      else 
       echo "answer y or n" 
       echo -e $redText"Answer y or n"$none 
      fi 
} 

genBuild() { 
    echo "Building..." 
    mkdir build && cd build 
    cmake .. 
     echo "Build on $cpuCores threads with $coreBuild processes? (experimental but loads faster) y or n " 
     read $ans1_4 
      if [[ $ans1_4 = "y" ]]; then 
       echo -e $greenText"Building on $cpuCores threads with $coreBuild ."$none 
       make -j $coreBuild 
      elif [[ $ans1_4 = "n" ]]; then 
       echo -e $blueText"Building on a single thread."$none 
       make 
      else 
       echo -e $redText"Answer y or n"$none 
      fi    
} 

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

### 
### Script starts here 
### 

#check if root 
if [[ $EUID -ne 0 ]]; then 
    echo "You must be root to use this script, press enter to exit." 
    read end 
    exit 1 
fi 
#OS dependencies and other stuff 
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 or n" 
    read ans1_1 
    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 or n" 
    read ans1_1 
    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 or n" 
    read ans1_1 
     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 

#Compiling here 

echo -n "Are we on FreeBSD? y or n" 
read ans1_2 
    if [[ $ans1_2 = "y" ]]; then 
     bsdbuild 
    elif [[ $ans1_2 = "n" ]]; then 
     genBuild 
    else 
     echo "Answer y or n" 
    fi 

echo "Should the folder be cleaned? y or n" 
    read ans1_3 
    if [[ $ans1_3 = "y" ]]; then 
     clean 
    elif [[ $ans1_3 = "n" ]]; then 
     echo "Exiting..." 
     exit 1 
    else 
     echo "Answer y or n" 
    fi 
+2

爲什麼在讀''時在變量的前面輸入$? – tabstop

+0

我們鼓勵您將問題的相關部分添加到您的問題中,鏈接消失,並且人們可能希望在其搜索中找到答案。但簡而言之:'讀$ ans1_4' =>'讀ans1_4'。請注意,使用'set -x'確實有助於調試bash腳本。 – Wrikken

回答

1

read $ans1_4應該read ans1_4我在那裏犯了一個小錯誤。