WSL
WSL copied to clipboard
How to pass over ampersand to powershell from WSL?
- Your Windows build number: (Type
verat a Windows Command Prompt) Microsoft Windows [Version 10.0.15063]
I tried to launch microsoft-edge with url having ampersand. I prepare a test url instead of my real url that's wanted to be launched.
- Test url is https://www.google.com/url?sa=t&url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQjCNHYJj1Y465rnV4VWzVcIVSF58cn9w
- This url will be redirected to https://github.com/Microsoft/BashOnWindows/issues
In PowerShell, it will occur errors because of ampersand;
PS C:\Windows\System32\WindowsPowerShell\v1.0> pwd
Path
----
C:\Windows\System32\WindowsPowerShell\v1.0
PS C:\Windows\System32\WindowsPowerShell\v1.0> ./powershell.exe start microsoft-edge:"https://www.google.com/url?sa=t&url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQjCNHYJj1Y465rnV4VWzVcIVSF58cn9w"
At line:1 char:55
+ { start microsoft-edge:https://www.google.com/url?sa=t&url=https%3A%2 ...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quot
ation marks ("&") to pass it as part of a string.
At line:1 char:121
+ ... ttps%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQj ...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quot
ation marks ("&") to pass it as part of a string.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : AmpersandNotAllowed
PS C:\Windows\System32\WindowsPowerShell\v1.0>
But, it can be solved by {} like this;
PS C:\Windows\System32\WindowsPowerShell\v1.0> ./powershell.exe { start microsoft-edge:"https://www.google.com/url?sa=t&url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQjCNHYJj1Y465rnV4VWzVcIVSF58cn9w" }
PS C:\Windows\System32\WindowsPowerShell\v1.0>
I tried to this in WSL but failed.
SUNJOONG-DESKTOP v1.0 # pwd
/mnt/c/Windows/System32/WindowsPowerShell/v1.0
SUNJOONG-DESKTOP v1.0 # ./powershell.exe { start microsoft-edge:"https://www.google.com/url?sa=t&url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQjCNHYJj1Y465rnV4VWzVcIVSF58cn9w" }
At line:1 char:55
+ { start microsoft-edge:https://www.google.com/url?sa=t&url=https%3A%2 ...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quot
ation marks ("&") to pass it as part of a string.
At line:1 char:121
+ ... ttps%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQj ...
+ ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quot
ation marks ("&") to pass it as part of a string.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : AmpersandNotAllowed
SUNJOONG-DESKTOP v1.0 #
Same command with {}, but failed only in WSL. How can fix it?
Hmm.... I found that;
sunjoong@SUNJOONG-DESKTOP /mnt/c/Windows/System32/WindowsPowerShell/v1.0 $ ./powershell.exe start microsoft-edge:'\"https://www.google.com/url?sa=t&url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FBashOnWindows%2Fissues&usg=AFQjCNHYJj1Y465rnV4VWzVcIVSF58cn9w\"'
sunjoong@SUNJOONG-DESKTOP /mnt/c/Windows/System32/WindowsPowerShell/v1.0 $
The anser was '\"url\"', i.e., single-quot-mark+slash+double-quot-mark+url+slash+double-quot-mark+single-quot-mark.