简体   繁体   English

Sh别名相当于PowerShell Set-Alias

[英]Sh alias equivalent of PowerShell Set-Alias

What would be the equivalent of this PowerShell code in Sh: Sh 中的这个 PowerShell 代码相当于什么:

Set-Alias -Name PS7 -Value "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
PS7 {
  $PSVersionTable
  1..5 | ForEach-Object -Parallel { Write-Host $_  } -ThrottleLimit 5
}

I tried the following:我尝试了以下内容:

alias ps="C:/Program Files/PowerShell/7/pwsh.exe"
ps {
  $PSVersionTable
  1..5 | ForEach-Object -Parallel { Write-Host $_  } -ThrottleLimit 5
}

But this doesn't seem to work.但这似乎不起作用。 Is it even possible?有可能吗? I would like it to be inline, not in a script.我希望它是内联的,而不是在脚本中。

Supposing you are in WSL :假设你在WSL中:

alias ps=\"$(wslpath -u 'D:\Program Files\PowerShell\7\pwsh.exe')\"
alias ps
 alias ps='"/mnt/d/Program Files/PowerShell/7/pwsh.exe"'
ps -nopro -c '& {
  $PSVersionTable
  1..5 | ForEach-Object -Parallel { Write-Host $_  } -ThrottleLimit 5
}'
 Name Value ---- ----- PSVersion 7.0.3 PSEdition Core GitCommitId 7.0.3 OS Microsoft Windows 10.0.19041 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0 1 2 3 4 5

FYI, I'm on the following (run from cmd ): ver & wsl --list仅供参考,我在下面(从cmd运行): ver & wsl --list

Microsoft Windows [Version 10.0.19041.508]
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
Ubuntu-18.04

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM