我想要得到一個if或在bash中工作,但它不工作。收到以下錯誤Bash腳本if或
./install.sh: line 33: conditional binary operator expected
./install.sh: line 33: syntax error near `$CURRENT_OS'
./install.sh: line 33: `elif [[ $CURRENT_OS =~ "CYGWIN" || [ $CURRENT_OS =~ "MSYS" ]]; then'
這裏是我當前的腳本
#!/bin/bash
CURRENT_OS=$(uname)
echo "Installing dotfiles"
echo "Initializing submodule(s)"
#git submodule update --init --recursive
# Used for setting up a mac
if [ $CURRENT_OS == "Darwin" ]; then
echo "Running OSX"
elif [[ $CURRENT_OS =~ "CYGWIN" || [ $CURRENT_OS =~ "MSYS" ]]; then
echo $CURRENT_OS
fi
我甚至試過這種
elif [ $CURRENT_OS =~ "CYGWIN" || [ $CURRENT_OS =~ "MSYS" ]; then
而且我得到這個錯誤
./install.sh: line 33: [: missing `]'
./install.sh: line 33: [: =~: binary operator expected
你的'elif'有不平衡的括號。還有一個'[''而不是'''''你試過,'elif [$ CURRENT_OS =〜「CYGWIN」|| $ CURRENT_OS =〜「MSYS」];'? – lurker
在發佈有關簡單語法錯誤之前,您應該嘗試http://shellcheck.net/。 – tripleee