Rich Clingman
Rich Clingman

Reputation: 156

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?

Upvotes: 3

Views: 1799

Answers (2)

Kolya Terletskyi
Kolya Terletskyi

Reputation: 181

What helped me was when I added whitespace before the slash.

aws ssm put-parameter --name ' /bla/bla/bla' --type String --overwrite --value 1

Upvotes: 2

Philippe
Philippe

Reputation: 26592

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.

Upvotes: 13

Related Questions