-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pager preference is not obeyed on Windows #8351
Comments
Hi @jimbo8098, thanks for reaching out. I'm still investigating this issue, but I wanted bring up that I think I've been able to reproduce the issue with |
My default Powershell profile
When I suspect the environment variable is being interpreted incorrectly. Perhaps some oversight in how scopes in Windows might be different and the aspect of comparitors in Powershell specifically being a bit more advanced than a usual You have The presence of |
In PowerShell, and in Windows in general, empty string environment variables are poorly supported (with an exception, see below). Setting an environment variable to an empty string is interpreted by client tools as unsetting the variable. That is, C:\Users\tom>set AWS_PAGER=test
C:\Users\tom>set AWS_PAGER
AWS_PAGER=test
C:\Users\tom>set AWS_PAGER=
C:\Users\tom>echo %AWS_PAGER%
%AWS_PAGER%
C:\Users\tom>set AWS_PAGER
Environment variable AWS_PAGER not defined Here we set the ~ ❯ ls env:/AWS_PAGER
Get-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.
~ ❯ $Env:AWS_PAGER="test"
~ ❯ ls env:/AWS_PAGER
Name Value
---- -----
AWS_PAGER test
~ ❯ $Env:AWS_PAGER=""
~ ❯ ls env:/AWS_PAGER
Get-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist. There is a big difference between these shells though: An exception is a recent change to .NET 9, which does support empty environment variables. As of this message, .NET 9 is only in the Preview version of PowerShell. PowerShell 7.5.0-preview.4
~ ❯ $Env:AWS_PAGER=$null
~ ❯ ls env:/AWS_PAGER
Get-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.
~ ❯ $Env:AWS_PAGER=""
~ ❯ ls env:/AWS_PAGER
Name Value
---- -----
AWS_PAGER Setting the environment variable this way, through a .NET 9 compatible client tool, does correctly disable the pager as documented. |
I think you're right Tom. I've done some more work in PS since and handling
of vars which are empty just isn't supported in the same way as Linux. I
think the problem is that in Linux, a bar can be empty but in Windows it is
always either undefined or a string. When I tried to set a var to $null the
var was just undefined and thus CLI_PAGER did not get obeyed.
I noted the same handling in the configure file too, but I think this is
just down to the file being read into vars anyway.
Frustrating it is unhandled since it makes reading the help pages a
tiresome experience in PS, which unfortunately is my main use of it. It's
quicker to read the help articles in a docker container than in the Windows
CLI command.
…On Wed, 4 Sept 2024, 23:20 Tom Keller, ***@***.***> wrote:
In PowerShell
<https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables>,
and in Windows in general, empty string environment variables are poorly
supported (with an exception, see below). Setting an environment variable
to an empty string is interpreted by client tools as unsetting the variable.
That is,
C:\Users\tom>set AWS_PAGER=test
C:\Users\tom>set AWS_PAGER
AWS_PAGER=test
C:\Users\tom>set AWS_PAGER=
C:\Users\tom>echo %AWS_PAGER%%AWS_PAGER%
C:\Users\tom>set %AWS_PAGER%
Environment variable %AWS_PAGER% not defined
Here we set the AWS_PAGER variable to test, read it back, then set it to
and can't read it back anymore. This is because set interprets empty
string as deleting the variable. PowerShell follows the same semantics:
~ ❯ ls env:/AWS_PAGERGet-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.
~ ❯ $Env:AWS_PAGER="test"
~ ❯ ls env:/AWS_PAGER
Name Value---- -----
AWS_PAGER test
~ ❯ $Env:AWS_PAGER=""
~ ❯ ls env:/AWS_PAGERGet-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.
There is a big difference between these shells though: cmd.exe will allow
you to call set VARIABLE="" which sets %VARIABLE% to the literal string "",
whereas PowerShell more intuitively interprets "" as null. That's also
why using $null in PowerShell also unsets the variable. There are other
API calls in Windows that you can use to set empty environment variables,
but they are mostly undocumented and mostly unsupported.
------------------------------
An exception is a recent change to .NET 9
<https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/9.0/empty-env-variable>,
which does support empty environment variables. As of this message, .NET 9
is only in the Preview version of PowerShell.
PowerShell 7.5.0-preview.4
~ ❯ $Env:AWS_PAGER=$null
~ ❯ ls env:/AWS_PAGERGet-ChildItem: Cannot find path 'AWS_PAGER' because it does not exist.
~ ❯ $Env:AWS_PAGER=""
~ ❯ ls env:/AWS_PAGER
Name Value---- -----
AWS_PAGER
Setting the environment variable this way, through a .NET 9 compatible
client tool, does correctly disable the pager as documented.
—
Reply to this email directly, view it on GitHub
<#8351 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC6XUFCYO6JO47BIYJVP7M3ZU6BSDAVCNFSM6AAAAAA7W2D7HKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZQGI2TEMRSGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
The config file does work properly for paging operation output, but |
You're right @RyanFitzSimmonsAK , I'll close this issue now since the other issue is tracking it. I've already weighed in on that issue so hopefully it helps people piece together the solution! |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the bug
The
AWS_PAGER
environment variable orcli_pager
config file parameter is not obeyed specifically if you wish to disable pagination. It is obeyed if you set it to a paginator of your choice.Expected Behavior
Per the AWS CLI documentation you can set the
AWS_PAGER
environment variable to be a blank string (i.e. not $null) or you can set the relevant option in config like so:Both of these would not result in paginated output.
Current Behavior
Note that if I instead run the AWS CLI command with
--no-cli-pager
, like below, the command works as expected:Reproduction Steps
~/.aws/config
'sdefault
profile to havecli_pager=
[System.Environment]::SetEnvironmentVariable("AWS_PAGER","")
$Env:AWS_PROFILE
to the relevant profile name.describe-instances
command above. The output is be paginated.Possible Solution
I use both Windows and Linux and haven't seen this same behaviour exhibited by Linux. I therefore suspect that this is just an oversight in how Windows handles variables.
Additional Information/Context
aws-cli/2.13.25 Python/3.11.5 Windows/10 exe/AMD64 prompt/off
CLI version used
aws-cli/2.13.25 Python/3.11.5 Windows/10 exe/AMD64 prompt/off
Environment details (OS name and version, etc.)
Windows 10 Business 10.0.19045
The text was updated successfully, but these errors were encountered: