bash

Stop Bash on Windows from interpreting string as a path


just having a play around with Bash to automate some things (I'm by no means an expert!) but am having trouble with some syntax.

I'm using the AWS CLI to try and delete some log groups. I have the following code that loops through the array of log files and calls the delete function:

for log in $logList
do 
  echo deleting log $log
  aws logs delete-log-group --log-group-name $log
done

This works fine with some logs but it fails with logs where the name starts with a trailing slash. So if I'm trying to delete a log group called /aws/myLog it actually runs the command aws logs delete-log-group --log-group-name C:/Program Files/Git/aws/myLog

How do I go about escaping the starting slash if I don't actually know if it will have one? I assume that's what I need to do - escape the slash so it treats it as a literal rather than a path?

Edit:

For a simple recreation of it:

log='/aws/logs/myLog'
aws logs delete-log-group --log-group-name $log

Results in error 1 validation error detected: Value 'C:/Program Files/Git/aws/logs/myLog' at 'logGroupName' failed to satisfy constraint.

As you can see, it's appending an absolute path to the variable I'm passing in, but I want to treat is as is. I believe this is a Windows specific issue.


Solution

  • Git-bash is trying to convert the path to Windows path.

    Try this:

    export MSYS_NO_PATHCONV=1
    aws logs delete-log-group --log-group-name $log