0

我有一个脚本,它有 2 种方法。一种方法在远程机器上执行命令,第二种方法相应地采取行动。

run_remote(){
sshpass -p $password ssh $user@$ipaddr /bin/bash << EOF
   if [ -e \$file ]; then
      echo "file exist"
      exit 1
   else
      echo "file doesnt exist"
   fi
EOF
   if [ check ]; then
      echo "failed"
      exit 1
   fi
}

run_local(){
   echo "run locally"
}

#main
run_remote
if [ $? == 0 ]; then
   run_local
fi

但即使文件存在与否,它总是执行 run_local 方法。如果有人可以告诉我如何捕获方法的退出状态(如果它在远程机器上执行),那将会很有帮助。

4

1 回答 1

0

尝试在 echo "file doesn't exist" 行之后放置 exit 0

于 2018-06-18T06:33:05.117 回答