给定一个路径,测试它的应用程序

Noi*_*art 0 .desktop

我正在制作一个小 .desktop 创建者的东西,用户提供一个路径。路径可以是链接应用程序或目录。有没有直接的方法来测试是否是应用程序?我可以测试它是否是目录。

谢谢

wal*_*tor 5

查看man bash,您可以执行以下操作:

   -a file
          True if file exists.
   -d file
          True if file exists and is a directory.
   -e file
          True if file exists.
   -f file
          True if file exists and is a regular file.
   -u file
          True if file exists and its set-user-id bit is set.
   -x file
          True if file exists and is executable.
    -L file
          True if file exists and is a symbolic link.
Run Code Online (Sandbox Code Playgroud)

还有很多很多。

您还可以使用file命令(请参阅 参考资料man file)查看文件“内部”以获取更多信息。

与其解析输出ls(这总是导致最终的混淆),不如使用/usr/bin/stat -c "%a %n" filename

$ stat -c "%a %n" .bashrc
700 .bashrc
Run Code Online (Sandbox Code Playgroud)