You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
#!/usr/local/bin/powershell bang should not load profile #992
We just need to figure out who called us, you know.
Also, if you run the same way
#!powershellWrite-Host'foo'
bash-3.2$ /Users/vors/dev/foo.ps1
Failed to load , error: dlopen(, 1): no suitable image found. Did find:
/usr/local/lib/: not a file
/usr/lib/: not a file
I don't see how we would reliably determine who called us, and how to interpret it (I as a user might call PowerShell via env, and wouldn't want its behavior to change because it detected that env launched it instead of Bash, that's just a bad idea).
I think really we just want to run with -noprofile whenever an in-place script is run (and -noexit was not used). Said another way, a profile should only be loaded when PowerShell is launched into an interactive shell.
This would be much better behavior (but we'd need a way to specify -profile to reverse it).
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
So I would say we should run the profile with #!powershell, but we should also find a clean way of detecting the process is interactive, e.g. if ($host.IsInteractive)
It would really be nice to have something for 6.1 that works on Windows as well. I've been trying to use git pre-commit hooks on my Windows dev box to ensure I have the right email configured. This works but it slows down all my commits because it processes my profile scripts when it does not need to:
#!/usr/bin/env pwsh
# Verify user's Git config has appropriate email address
if ($env:GIT_AUTHOR_EMAIL -notmatch '@(non\.)?acme\.com$') {
Write-Warning "Your Git email address '$env:GIT_AUTHOR_EMAIL' is not configured correctly."
Write-Warning "It should end with '@acme.com' or '@non.acme.com'."
Write-Warning "Use the command: 'git config --global user.email <[email protected]>' to set it correctly."
exit 1
}
exit 0
The only work around I've found is to put the PS script in a separate pre-commit.ps1 file and modify pre-commit to:
It's obviously just a stopgap, but you can roll your own pwsh-np by creating a script by that name with the content below and by placing it in a folder in your PATH (works on both Windows and Unix-like platforms, but on the latter you must also mark the script as executable (chmod a+x pwsh-np)):
#!/bin/sh
pwsh -noprofile "$@"
Your hooks should then be able to use the shebang you mentioned (#!/usr/bin/env pwsh-np).
Reacted by Keith Hill, Ilya and Rain Sallow (/u/ta11ow)
Able to Run .ps1 script on zsh manually, however if call same ps1 from ansible playbook gets error that Connect-AzAccount is not recognized. #!/usr/bin/env pwsh is what i use in .ps1
Please help me to setup my environment variable.
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
So I would say we should run the profile with #!powershell, but we should also find a clean way of detecting the process is interactive, e.g. if ($host.IsInteractive)
Is $Host.IsInteractive planned? FWIW, [Environment]::UserInteractive always seems to return True, even in pwsh -c <command>.
I just realized that setting PowerShell as default shell on Linux (using chsh) is a very bad idea. All my programs display a lag of 3-4 seconds when starting up. Many applications use "$SHELL" -c <command> to run external commands, and in each of them PowerShell seems to load the profile, causing the delay (since $SHELL is now /usr/bin/pwsh). This is particularly noticeable in Neovim and Fzf, as examples.
Presence of $Host.IsInteractive would really help in aborting the sourcing of profile, as in the case of bash.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 23, 2023
Activity
andyleejordan commentedon May 18, 2016
Ha! I don't see anyway this is going to work without a shim that executes with
-noprofile.vors commentedon May 19, 2016
We just need to figure out who called us, you know.
Also, if you run the same way
andyleejordan commentedon May 19, 2016
I don't see how we would reliably determine who called us, and how to interpret it (I as a user might call PowerShell via
env, and wouldn't want its behavior to change because it detected thatenvlaunched it instead of Bash, that's just a bad idea).I think really we just want to run with
-noprofilewhenever an in-place script is run (and-noexitwas not used). Said another way, a profile should only be loaded when PowerShell is launched into an interactive shell.This would be much better behavior (but we'd need a way to specify
-profileto reverse it).vors commentedon May 19, 2016
Jason Shirk (@lzybkr) can you comment on the profile/noprofile, please ?
Should this work at all
#!powershell?lzybkr commentedon Jul 21, 2016
I just noticed this in my .bashrc:
So I would say we should run the profile with
#!powershell, but we should also find a clean way of detecting the process is interactive, e.g.if ($host.IsInteractive)vors commentedon Jul 21, 2016
👍
I was asking for
$host.IsInteractivefor ages.36 remaining items
rkeithhill commentedon Jun 5, 2018
It would really be nice to have something for 6.1 that works on Windows as well. I've been trying to use git pre-commit hooks on my Windows dev box to ensure I have the right email configured. This works but it slows down all my commits because it processes my profile scripts when it does not need to:
The only work around I've found is to put the PS script in a separate pre-commit.ps1 file and modify pre-commit to:
But I'd rather there be just a single file. At this point, I'd be satisfied if I could do this:
mklement0 commentedon Jun 5, 2018
Keith Hill (@rkeithhill):
It's obviously just a stopgap, but you can roll your own
pwsh-npby creating a script by that name with the content below and by placing it in a folder in your PATH (works on both Windows and Unix-like platforms, but on the latter you must also mark the script as executable (chmod a+x pwsh-np)):Your hooks should then be able to use the shebang you mentioned (
#!/usr/bin/env pwsh-np).nippyin commentedon May 20, 2019
Able to Run .ps1 script on zsh manually, however if call same ps1 from ansible playbook gets error that Connect-AzAccount is not recognized. #!/usr/bin/env pwsh is what i use in .ps1
Please help me to setup my environment variable.
iSazonov commentedon May 20, 2019
Sandeep Sharma (@nippyin) Please open new issue with step-by-step repo.
rashil2000 commentedon Sep 4, 2021
Is
$Host.IsInteractiveplanned? FWIW,[Environment]::UserInteractivealways seems to return True, even inpwsh -c <command>.I just realized that setting PowerShell as default shell on Linux (using
chsh) is a very bad idea. All my programs display a lag of 3-4 seconds when starting up. Many applications use"$SHELL" -c <command>to run external commands, and in each of them PowerShell seems to load the profile, causing the delay (since$SHELLis now/usr/bin/pwsh). This is particularly noticeable in Neovim and Fzf, as examples.Presence of
$Host.IsInteractivewould really help in aborting the sourcing of profile, as in the case of bash.microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.