Why weird assignment from variable inside Powershell switch statement?
I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes
and = $No
in this code snippet:
Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}
I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?
powershell
add a comment |
I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes
and = $No
in this code snippet:
Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}
I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?
powershell
3
=
is being overloaded as a function or alias. There is code missing from your example. Observe:${function:=} = { $args }; = 'test'
orfunction = { $args }
is another syntax
– TheIncorrigible1
Nov 21 '18 at 22:58
1
The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
Dec 3 '18 at 17:11
add a comment |
I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes
and = $No
in this code snippet:
Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}
I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?
powershell
I'm a beginner at Powershell and am struggling to understand some syntax from some code I found on Github. I've read the docs on Powershell assignment, and on switch statements, and can't understand what is going on with the = $Yes
and = $No
in this code snippet:
Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}
I haven't been able to find any references to this kind of syntax, and it doesn't seem to do anything in the script. So why is it there?
powershell
powershell
asked Nov 21 '18 at 22:55
jacobseejacobsee
66631230
66631230
3
=
is being overloaded as a function or alias. There is code missing from your example. Observe:${function:=} = { $args }; = 'test'
orfunction = { $args }
is another syntax
– TheIncorrigible1
Nov 21 '18 at 22:58
1
The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
Dec 3 '18 at 17:11
add a comment |
3
=
is being overloaded as a function or alias. There is code missing from your example. Observe:${function:=} = { $args }; = 'test'
orfunction = { $args }
is another syntax
– TheIncorrigible1
Nov 21 '18 at 22:58
1
The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
Dec 3 '18 at 17:11
3
3
=
is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test'
or function = { $args }
is another syntax– TheIncorrigible1
Nov 21 '18 at 22:58
=
is being overloaded as a function or alias. There is code missing from your example. Observe: ${function:=} = { $args }; = 'test'
or function = { $args }
is another syntax– TheIncorrigible1
Nov 21 '18 at 22:58
1
1
The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
Dec 3 '18 at 17:11
The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
Dec 3 '18 at 17:11
add a comment |
2 Answers
2
active
oldest
votes
UPDATE: This issue has been resolved.
Looks to me like the variable name that was getting the assignment was deleted in a change back in August.
$PublishSettings = $Yes
Was changed to:
= $Yes
And:
$PublishSettings = $No
Was changed to:
= $No
Looks like poor search and replace.
I've created an issue for the problem at GitHub.
add a comment |
There are many characters that are valid in a function (or variable) name; this includes the =
symbol. What you're observing is a function or alias.
Examples:
# standard function
function =
{
return $args
}
# accessing the function: drive
${Function:=} = {
return $args
}
# defining a new alias
New-Alias -Name = -Value Get-Variable
# using the Alias attribute
function Test-Thing
{
[Alias('=')]
param()
return $args
}
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
@jacobsee I'm assuming there's something that looks like$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns$null
– TheIncorrigible1
Nov 27 '18 at 19:09
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
@jacobsee That's where your misunderstanding is coming -=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named=
.{ }
is an emptyscriptblock
being passed to the=
function. You can assign expression outputs to variables, such as:$myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
1
@jacobsee Yeah, I reviewed the project and there's no definition for a=
function or alias so that line of code would throw an exception.
– TheIncorrigible1
Nov 27 '18 at 20:57
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421586%2fwhy-weird-assignment-from-variable-inside-powershell-switch-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
UPDATE: This issue has been resolved.
Looks to me like the variable name that was getting the assignment was deleted in a change back in August.
$PublishSettings = $Yes
Was changed to:
= $Yes
And:
$PublishSettings = $No
Was changed to:
= $No
Looks like poor search and replace.
I've created an issue for the problem at GitHub.
add a comment |
UPDATE: This issue has been resolved.
Looks to me like the variable name that was getting the assignment was deleted in a change back in August.
$PublishSettings = $Yes
Was changed to:
= $Yes
And:
$PublishSettings = $No
Was changed to:
= $No
Looks like poor search and replace.
I've created an issue for the problem at GitHub.
add a comment |
UPDATE: This issue has been resolved.
Looks to me like the variable name that was getting the assignment was deleted in a change back in August.
$PublishSettings = $Yes
Was changed to:
= $Yes
And:
$PublishSettings = $No
Was changed to:
= $No
Looks like poor search and replace.
I've created an issue for the problem at GitHub.
UPDATE: This issue has been resolved.
Looks to me like the variable name that was getting the assignment was deleted in a change back in August.
$PublishSettings = $Yes
Was changed to:
= $Yes
And:
$PublishSettings = $No
Was changed to:
= $No
Looks like poor search and replace.
I've created an issue for the problem at GitHub.
edited Dec 3 '18 at 17:07
answered Nov 27 '18 at 22:35
Bacon BitsBacon Bits
21k43041
21k43041
add a comment |
add a comment |
There are many characters that are valid in a function (or variable) name; this includes the =
symbol. What you're observing is a function or alias.
Examples:
# standard function
function =
{
return $args
}
# accessing the function: drive
${Function:=} = {
return $args
}
# defining a new alias
New-Alias -Name = -Value Get-Variable
# using the Alias attribute
function Test-Thing
{
[Alias('=')]
param()
return $args
}
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
@jacobsee I'm assuming there's something that looks like$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns$null
– TheIncorrigible1
Nov 27 '18 at 19:09
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
@jacobsee That's where your misunderstanding is coming -=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named=
.{ }
is an emptyscriptblock
being passed to the=
function. You can assign expression outputs to variables, such as:$myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
1
@jacobsee Yeah, I reviewed the project and there's no definition for a=
function or alias so that line of code would throw an exception.
– TheIncorrigible1
Nov 27 '18 at 20:57
|
show 4 more comments
There are many characters that are valid in a function (or variable) name; this includes the =
symbol. What you're observing is a function or alias.
Examples:
# standard function
function =
{
return $args
}
# accessing the function: drive
${Function:=} = {
return $args
}
# defining a new alias
New-Alias -Name = -Value Get-Variable
# using the Alias attribute
function Test-Thing
{
[Alias('=')]
param()
return $args
}
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
@jacobsee I'm assuming there's something that looks like$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns$null
– TheIncorrigible1
Nov 27 '18 at 19:09
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
@jacobsee That's where your misunderstanding is coming -=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named=
.{ }
is an emptyscriptblock
being passed to the=
function. You can assign expression outputs to variables, such as:$myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
1
@jacobsee Yeah, I reviewed the project and there's no definition for a=
function or alias so that line of code would throw an exception.
– TheIncorrigible1
Nov 27 '18 at 20:57
|
show 4 more comments
There are many characters that are valid in a function (or variable) name; this includes the =
symbol. What you're observing is a function or alias.
Examples:
# standard function
function =
{
return $args
}
# accessing the function: drive
${Function:=} = {
return $args
}
# defining a new alias
New-Alias -Name = -Value Get-Variable
# using the Alias attribute
function Test-Thing
{
[Alias('=')]
param()
return $args
}
There are many characters that are valid in a function (or variable) name; this includes the =
symbol. What you're observing is a function or alias.
Examples:
# standard function
function =
{
return $args
}
# accessing the function: drive
${Function:=} = {
return $args
}
# defining a new alias
New-Alias -Name = -Value Get-Variable
# using the Alias attribute
function Test-Thing
{
[Alias('=')]
param()
return $args
}
edited Nov 27 '18 at 19:23
answered Nov 21 '18 at 23:10
TheIncorrigible1TheIncorrigible1
10.4k31436
10.4k31436
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
@jacobsee I'm assuming there's something that looks like$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns$null
– TheIncorrigible1
Nov 27 '18 at 19:09
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
@jacobsee That's where your misunderstanding is coming -=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named=
.{ }
is an emptyscriptblock
being passed to the=
function. You can assign expression outputs to variables, such as:$myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
1
@jacobsee Yeah, I reviewed the project and there's no definition for a=
function or alias so that line of code would throw an exception.
– TheIncorrigible1
Nov 27 '18 at 20:57
|
show 4 more comments
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
@jacobsee I'm assuming there's something that looks like$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns$null
– TheIncorrigible1
Nov 27 '18 at 19:09
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
@jacobsee That's where your misunderstanding is coming -=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named=
.{ }
is an emptyscriptblock
being passed to the=
function. You can assign expression outputs to variables, such as:$myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
1
@jacobsee Yeah, I reviewed the project and there's no definition for a=
function or alias so that line of code would throw an exception.
– TheIncorrigible1
Nov 27 '18 at 20:57
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
Thank you for your answer. I've read it several times but still having a hard time wrapping my head around it. You're right that I didn't include all the code, but one other detail to mention is that the variables (aliases?) $Yes and $No are not used any where else in the PS script, which includes several Functions followed by several Switches based on user prompts like the one shown.
– jacobsee
Nov 27 '18 at 19:05
@jacobsee I'm assuming there's something that looks like
$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns $null
– TheIncorrigible1
Nov 27 '18 at 19:09
@jacobsee I'm assuming there's something that looks like
$Yes = switch(condition) {
somewhere in the codebase. If the variable is undefined, it returns $null
– TheIncorrigible1
Nov 27 '18 at 19:09
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
There is not. But if there were, what would that do? In my example, what is being assigned to the $No variable? It's an empty pair of brackets!? Thanks for your patience.
– jacobsee
Nov 27 '18 at 19:37
@jacobsee That's where your misunderstanding is coming -
=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =
. { }
is an empty scriptblock
being passed to the =
function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
@jacobsee That's where your misunderstanding is coming -
=
is not an assignment operator in your code, it's a function call. Someone has literally defined a function named =
. { }
is an empty scriptblock
being passed to the =
function. You can assign expression outputs to variables, such as: $myvar = if ($true) { 'thisval' } else { 'thatval' }
– TheIncorrigible1
Nov 27 '18 at 19:44
1
1
@jacobsee Yeah, I reviewed the project and there's no definition for a
=
function or alias so that line of code would throw an exception.– TheIncorrigible1
Nov 27 '18 at 20:57
@jacobsee Yeah, I reviewed the project and there's no definition for a
=
function or alias so that line of code would throw an exception.– TheIncorrigible1
Nov 27 '18 at 20:57
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421586%2fwhy-weird-assignment-from-variable-inside-powershell-switch-statement%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
=
is being overloaded as a function or alias. There is code missing from your example. Observe:${function:=} = { $args }; = 'test'
orfunction = { $args }
is another syntax– TheIncorrigible1
Nov 21 '18 at 22:58
1
The issue has been resolved in the latest version of the script. See github.com/Sycnex/Windows10Debloater/issues/66 Voting to close because this was a typographical error.
– Bacon Bits
Dec 3 '18 at 17:11