如何在Mac High Sierra上运行VPN automator

时间:2018-08-13 04:45:36

标签: macos vpn macos-sierra automator

以下是我连接到VPN的代码

VPN="MY VPN NAME"
IS_CONNECTED=$(test -z `scutil --nc status "$VPN" | head -n 1 | grep Connected` && echo 0 || echo 1);
if [ $IS_CONNECTED = 1 ]; then
  scutil --nc stop "$VPN"
else
  scutil --nc start "$VPN"
fi

但是不断出错

  

“期望的表达式,但是发现了未知的标记”

enter image description here

请帮助我解决这个问题!

1 个答案:

答案 0 :(得分:0)

如果IS_CONNECTED是整数,则需要使用整数比较:

if [ $IS_CONNECTED -eq 1 ]; then
   ...

要进行字符串比较,请使用=

if [ "$someString" = "string" ]; then
  ...