在 Windows 上运行 bash 脚本时,Git Bash 与斜杠“/”混淆

Tha*_*ỳnh 2 windows bash shell slash git-bash

如何在 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}
Run Code Online (Sandbox Code Playgroud)

当我在 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}
Run Code Online (Sandbox Code Playgroud)

如何在 Git Bash Windows 上使用命令“/”执行脚本?

我期待收到大家的来信!多谢 !

Tha*_*ded 5

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

export MSYS_NO_PATHCONV=1
Run Code Online (Sandbox Code Playgroud)

买者自负:该解决方案基于 Windows 上 docker 命令出现的类似问题(参考:DevOps 2.1 Toolkit:Docker Swarm