Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 634
Rich Clingman Avatar asked Oct 28 '25 05:10

Rich Clingman


2 Answers

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.

like image 109
Philippe Avatar answered Oct 31 '25 07:10

Philippe


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

aws ssm put-parameter --name ' /bla/bla/bla' --type String --overwrite --value 1
like image 43
Kolya Terletskyi Avatar answered Oct 31 '25 06:10

Kolya Terletskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!