【问题标题】:Git Bash confuse with Slash '/' when running bash script on Windows在 Windows 上运行 bash 脚本时,Git Bash 与 Slash '/' 混淆
【发布时间】:2020-09-06 12:26:17
【问题描述】:

如何在 Windows 上使用斜杠“/”在 git bash 上运行 bash 脚本。

这是我的脚本文件。我可以在 Ubuntu/Linux 上运行良好。

#!/bin/sh

KONG_ADMIN_HOST=localhost
KONG_ADMIN_PORT=8001

registerServiceRoute() {
  printf "\nRegister %s service route\n" $1
  curl -XPOST ${KONG_ADMIN_HOST}:${KONG_ADMIN_PORT}/services/$1/routes \
    --data protocols=grpc \
    --data name=$1-grpc \
    --data paths=$2          -----> This line '/'is understood wrong in Git Bash Windows
  printf "\n"
}

SERVICE_NAME=auth
SERVICE_PATH=/com.bht.saigonparking.api.grpc.auth.AuthService/     ----------> path with '/' here

registerServiceRoute ${SERVICE_NAME} ${SERVICE_PATH}

只要我在 Windows 上的 Git Bash 上运行脚本, 控制台告诉路径应该以 / 开头, 这意味着它与路径中的 / 混淆。虽然 / 已经是正确的了。

这是 git bash Windows 控制台输出:

Register auth service route
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   248  100   143  100   105    674    495 --:--:-- --:--:-- --:--:--  1169{"message":"schema violation (paths.1: should start with: \/)","name":"schema violation","fields":{"paths":["should start with: \/"]},"code":2}

如何在 Git Bash Windows 上执行带有“/”命令的脚本?

我期待着大家的回音!非常感谢!

【问题讨论】:

    标签: windows bash shell git-bash slash


    【解决方案1】:

    curl 命令之前添加以下内容:

    export MSYS_NO_PATHCONV=1
    

    警告购买者:该解决方案基于 Windows 上的 docker 命令发生的类似问题(参考:The DevOps 2.1 Toolkit: Docker Swarm

    【讨论】:

      猜你喜欢
      • 2017-05-02
      • 2019-08-19
      • 2015-12-10
      • 2020-10-03
      • 2023-03-03
      • 2016-07-23
      • 2015-04-09
      • 2014-03-01
      • 2020-09-15
      相关资源
      最近更新 更多