2016-03-03 127 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运行代码。您没有足够的实际代码来查找问题。

相关问题