Bash脚本在本地工作,但不在服务器上工作

时间:2016-03-03 12:41:25

标签: bash

我有一个在Mac上本地执行时运行良好的脚本。

# 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'

1 个答案:

答案 0 :(得分:0)

你没有远程执行任何事情;您只是从远程服务器复制脚本以在本地执行。一个问题是您的脚本使用bash扩展名read -p,但您正在使用sh执行它(即使它是bash的链接,也会在POSIX中执行模式)。明确使用bash

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

至于语法错误,请通过shellcheck.net运行代码。您还没有显示足够的实际代码来找到问题。