6

How can I run bash script on git bash with slash '/' on Windows.

Here is my script file. I can run well on 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}

As soon as I run the script on Git Bash on Windows, The console tell that Paths should start with /, which means it confuse with / in the path. although / is already correct.

Here is the git bash Windows console output:

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}

How can I execute script with command have '/' on Git Bash Windows ?

I am looking forward to hearing from you all ! Thanks a lot !

1 Answer 1

14

Add the following before your curl command:

export MSYS_NO_PATHCONV=1

Caveat emptor: The solution is based off a similar issue that occurs for docker commands on Windows (ref: The DevOps 2.1 Toolkit: Docker Swarm)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.