检查文件是否可以在Ubuntu上使用PowerShell进行执行

问题描述 投票:1回答:1

我不想使用bash。

我在FileInfo对象中寻找了任何参数,但是没有什么可以告诉您该文件是否可执行。

我该怎么做?

linux powershell filesystems executable
1个回答
0
投票

使用标准test utility(在Ubuntu上为test

/usr/bin/test

注意:有人希望将$isExecutable = $(test -x '/path/to/some/file'; 0 -eq $LASTEXITCODE) 与文件路径一起使用将指示目标文件是否可执行,但是从PowerShell 7.0开始,此文件[[not可靠:any现有文件-可执行文件还是可执行文件?不是-当前报告为命令(类型为Get-Command)-请参见Application

this GitHub issue
注意:如果要解决此问题,请注意,即使对于当前位置的文件,也将始终需要指定

path

而不是单纯的文件名。 R例如# !! SHOULD work, but does NOT as of PowerShell 7.0: # !! any existing file is reported as executable. $isExecutable = [bool] (Get-Command -ErrorAction Ignore '/path/to/some/file') 而不是Get-Command ./foo,因为后者只会在Get-Command foo中列出的目录中查找foo可执行文件。
© www.soinside.com 2019 - 2024. All rights reserved.