我如何问PowerShell的东西在哪里?
例如,"which notepad",它根据当前路径返回notepad.exe运行的目录。
我如何问PowerShell的东西在哪里?
例如,"which notepad",它根据当前路径返回notepad.exe运行的目录。
当前回答
There also always the option of using which. there are actually three ways to access which from Windows powershell, the first (not necessarily the best) wsl -e which command (this requires installation of windows subsystem for Linux and a running distro). B. gnuwin32 which is a port of several gnu binaries in .exe format as standle alone bundled lanunchers option three, install msys2 (cross compiler platform) if you go where it installed in /usr/bin you'll find many many gnu utils that are more up-to-date. most of them work as stand alone exe and can be copied from the bin folder to your home drive somewhere amd added to your PATH.
其他回答
可以从https://goprogram.co.uk/software/commands安装which命令,以及所有其他UNIX命令。
这是一个实际的*nix等效,即它给出*nix风格的输出。
Get-Command <your command> | Select-Object -ExpandProperty Definition
用你想要的替换就行了。
PS C:\> Get-Command notepad.exe | Select-Object -ExpandProperty Definition
C:\Windows\system32\notepad.exe
当你把它添加到你的配置文件时,你会想要使用一个函数而不是一个别名,因为你不能对管道使用别名:
function which($name)
{
Get-Command $name | Select-Object -ExpandProperty Definition
}
现在,当你重新加载你的个人资料,你可以这样做:
PS C:\> which notepad
C:\Windows\system32\notepad.exe
我对Which函数的命题是:
function which($cmd) { get-command $cmd | % { $_.Path } }
PS C:\> which devcon
C:\local\code\bin\devcon.exe
还有使用which的选项。实际上有三种方法可以从Windows powershell中访问
第一个(虽然不是最好的)是wsl(linux的windows子系统)
wsl -e which command
这需要安装Linux的windows子系统和一个正在运行的发行版。
下一个是gnuwin32,它是几个。exe格式的gnu二进制文件的移植,作为独立的捆绑启动程序 第三,安装msys2(跨编译器平台),如果你去/usr/bin中安装它,你会发现很多很多最新的gnu utils。他们中的大多数工作作为独立的exe,可以从bin文件夹复制到你的家庭驱动器的某个地方,并添加到你的路径。
与Unix的快速匹配
New-Alias which where.exe
但如果它们存在,它会返回多行,然后它就变成
function which {where.exe command | select -first 1}