我正在編寫一個 bash 腳本(如下)並使用
sudo bash ./script.bash
結果錯誤:
line 22: syntax error near unexpected token `fi'
劇本:
getent passwd myuser > /dev/null
if [ $? -eq 0 ]; then
echo "info: user myuser already exists"
else
sudo useradd -M myuser > /dev/null || { echo "ERROR: could not create user myuser."; exit 1 }
echo "info: user myuser created successfully"
fi
如果我刪除該行:
|| { echo "ERROR: could not create user fiminion"; exit 1 }
一切似乎都有效..我不明白我錯過了什麼..:/