bashaws-cligit-bashmsys

GitBash: How can I pass an argument that starts with a slash / without it seen as a directory?


On Windows10 using Git Bash...

I'm using aws cli to get a parameter from ssm. The names argument begins with "/". This is processed by bash as a directory name and results in an error. (Command works in CentOS. It works in PowerShell. I'd like to stay inside Git Bash.)

aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2

Response:

{
    "Parameters": [],
    "InvalidParameters": [
        "C:/Program Files/Git/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
    ]
}

I've tried quoting and escaping...

... "/aws/..."
... '/aws/...'
... \/aws/...
... \/aws\/...
... \\/aws/...
... \\/aws\\...

I've tried putting into a variable, but the result is the same.

I tried turning off globbing. (I verified "*" is no longer expanded, but I still have the same problem.)

set -f

I can't find a way to make the command work in GitBash.

Do you happen to know a solution?


Solution

  • Try this :

    MSYS_NO_PATHCONV=1 aws ssm ...
    

    If this does not work, or causes other problems, try

    aws ssm ... //aws\\service...
    

    which is replacing the first forward slash by doubling it and replacing all the remaining forward slashes by two backslashes.