SumoLogic / sumologic-collector-puppet-module

Puppet module for installing Sumo Logic's collector.
Other
11 stars 22 forks source link

Why are there double-backslashes in powershell script? #30

Closed ghost closed 6 years ago

ghost commented 6 years ago

Why does this Powershell script have double-backslashes in it?

https://github.com/SumoLogic/sumo-collector-puppet-module/blob/master/files/download_sumo.ps1

Doing this inside the script seems to serve no purpose. Is there some puppety reason to do this that I'm not aware of?

TerribleDev commented 6 years ago

escaping the backslash?

twolsten commented 6 years ago

It does look like it is escaping the backslash.

ghost commented 6 years ago

Right, but why? For example, I have Powershell scripts in production, deployed via puppet, that do not do this.

twolsten commented 6 years ago

with Linux systems, scripts etc will use the \ to denote different things. For example a \n will be a new line character or a \t is a tab. You can stop the \ from being interpolated that way by adding another . This "escapes" it and tells the script to treat it as just a \

Hope that makes it clear

ghost commented 6 years ago

Howdy. I understand what backslashes are for and how they work.

This usage of backslashes strikes me as not necessary. Backslashes on Windows are literals, especially when used in paths. Inside a Powershell script, there should be no reason to use a double-backslash.

That's why I'm wondering what the double backslashes are doing inside a powershell script. Since this script is being deployed by Puppet, and puppet does different things with backslashes, maybe there's something I wasn't aware of in cases like this. But I have .ps1 scripts in my own Puppet manifests that do not use double-backslashes like this.

If the answer is "I don't know" or "looks like a mistake" or whatever, I'm fine with that. This is really a very minor question.

Thanks

twolsten commented 6 years ago

I am assuming that since the puppet master is Linux, which would be doing the compile of the commands etc, it would be what requires the \ and not the client.

I thought you were asking since you didn't understand the \ part, so sorry to explain something you already knew.

TerribleDev commented 6 years ago

Honestly, when I wrote the file I just figured. Hey I didn't want to have to deal with the problem of the slash being escaped, and windows doesn't care if your paths have an additional slash. So I stuck with the safe side of adding the extra backslashes.

I'm also not really a windows person.