Linux 的 shell script 中,遇到 unexpected operator 的解決方法
2 min readFeb 27, 2019
在寫 shell script 中遇到 unexpected operator 的解決方法
#!/bin/bash
app-running=$(ps -ax | grep "[a]pp-server" | awk '{print $1}')
if [[ $app-running == "" ]];
then
cd $GOPATH/src/github.com/app
./run-script.sh backend
fi
編譯後總會發現錯誤:
restart-app.sh: 3: [: ==: unexpected operator
到 /bin 底下會發現 /bin/sh -> dash,因為 ubuntu 默認 shell 使用 dash,dash 與 bash 一些指令上有些許差異,我們要把它改回 /bin/sh -> bash
解決方法:
1、使用指令
sudo dpkg-reconfigure dash
然後選 No,就可以改回 /bin/sh -> bash
2、把 == 改成 =