2016-03-03 91 views
0

我有一個腳本,在Mac上本地執行時可以正常運行。Bash腳本在本地工作,但不是從服務器

# Ask to make system changes 
read -p "Would You Like to make system changes? (Finder, etc...) ? (y/n)?" CONT 
if [ "$CONT" == "y" ]; then 

# Keep-alive: update existing `sudo` time stamp until `mac.sh` has finished 
echo "Keep this mac alive while ding this task..." 
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & 
# Show Date on menubar 
echo "Showing Date on menubar..." 
defaults write com.apple.menuextra.clock.plist DateFormat "EEE dd MMM h:mm:ss a" 
killall "SystemUIServer"; 

else 
    echo "Done makng system changes" 
fi 

但是當我嘗試遠程像這樣:

curl -s https://192.168.63.23/mac.sh --insecure | sh 

我得到這個錯誤:

sh: line 93: syntax error near unexpected token `else' 
sh: line 93: `else' 
+0

嘗試從'bash'而不是'sh'執行它。 –

回答

0

你是不是遠程執行任何操作;您只需從遠程服務器複製腳本以在本地執行。一個問題是您的腳本使用bash擴展名,如read -p,但是您正在使用sh(即使它是到bash的鏈接,以POSIX模式執行)執行它。使用bash明確:

curl -s --insecure https:/192.168.63.23/mac.sh | bash 

至於語法錯誤,通過shellcheck.net運行代碼。您沒有足夠的實際代碼來查找問題。

相關問題