Why weird assignment from variable inside Powershell switch statement?
up vote
2
down vote
favorite
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 |
up vote
2
down vote
favorite
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 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
2 days ago
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 at 22:55
jacobsee
65131230
65131230
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 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
2 days ago
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 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
2 days ago
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 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 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
2 days ago
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
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
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 |
up vote
1
down vote
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 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 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 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 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 at 20:57
|
show 4 more comments
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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 |
up vote
0
down vote
accepted
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 |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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 2 days ago
answered Nov 27 at 22:35
Bacon Bits
20.4k42939
20.4k42939
add a comment |
add a comment |
up vote
1
down vote
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 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 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 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 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 at 20:57
|
show 4 more comments
up vote
1
down vote
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 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 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 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 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 at 20:57
|
show 4 more comments
up vote
1
down vote
up vote
1
down vote
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 at 19:23
answered Nov 21 at 23:10
TheIncorrigible1
9,29631334
9,29631334
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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 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
2 days ago