Dado um caminho, teste se sua aplicação

0

Estou fazendo uma pequena coisa de criador do .desktop, em que os usuários fornecem um caminho. Caminho pode ser um aplicativo ou diretório de link. Existe alguma maneira direta de testar se é app? Eu posso testar se é um diretório.

Obrigado

    
por Noitidart 06.09.2015 / 04:35

1 resposta

5

Veja man bash e você pode fazer coisas como:

   -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.

e muitos, muitos mais.

Você também pode procurar "dentro" do arquivo com o comando file (consulte man file ) para obter mais informações.

Em vez de analisar a saída de ls (que sempre causa confusão), deve-se usar /usr/bin/stat -c "%a %n" filename :

$ stat -c "%a %n" .bashrc
700 .bashrc
    
por waltinator 06.09.2015 / 05:38