gpt4 book ai didi

windows - 在 Windows 上运行 bash 脚本时,Git Bash 与 Slash '/' 混淆

转载 作者:行者123 更新时间:2023-12-03 08:44:52 25 4
gpt4 key购买 nike

如何在 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 上使用带有“/”的命令执行脚本?

我期待收到大家的来信!非常感谢!

最佳答案

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

export MSYS_NO_PATHCONV=1

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

关于windows - 在 Windows 上运行 bash 脚本时,Git Bash 与 Slash '/' 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61907994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com