检查命令是否可执行

Žan*_*nik 2 linux bash executable command

如何检查命令在 Linux 中是否可执行。

例子:

xeyes
Run Code Online (Sandbox Code Playgroud)

oli*_*liv 8

man bash条件表达式段落中:

-x 文件

如果文件存在且可执行,则为真。

因此,您可以使用:

[ -x /usr/bin/xeyes ] && echo "File is executable" || echo "File is not an executable or does not exist"
Run Code Online (Sandbox Code Playgroud)