简体   繁体   中英

Sh alias equivalent of PowerShell Set-Alias

What would be the equivalent of this PowerShell code in Sh:

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 :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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