shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find


From: Leonardo Ayres
Subject: Re: Find
Date: Wed, 22 Jun 2005 14:24:34 -0000
User-agent: eGroups-EW/0.82

Eu já tinha feito do jeito mais simples antes e não tinha funcionado. 
Por isto que eu fui modificando até ficar da forma que eu mostrei.
Eu tentei jogar os find para dentro de um novo shell e executá-lo e 
só assim funcionou.

--- Em address@hidden, "MrBiTs" <mrbits@t...> 
escreveu
> /*
> 
> Se eu tiro as aspas protegidas, ele interpreta diferente do que eu 
gostaria,
> trocando o *.log por um arquivo de log que eu tenho no diretório 
onde está o
> script.
> 
> Se eu tiro o \\\; do final, vejo no log do set -x que ele usa só 
um ;
> */
> 
> Existe uma regra em programação que NINGUÉM que está iniciando 
segue.
> Chama-se KISS: Keep It Simple, Stupid. Ou, em outras palavras, 
SIMPLIFIQUE.
> 
> Antes de enfeitar seu código com colchetes, variáveis e outros 
bichos,
> faça-o funcionar. Pegue a sua linha:
> 
>  find ${param1} -name \"${param2}\" -mtime +${param3} -exec 
${param4} \\\;
> 
> e escreva-a assim:
> 
>       find $param1 -name "$param2" -mtime +$param3 -exec $param4 {} 
\;
> 
> Simples de tudo. Você não precisa desses escapes, ja que não está
> interpretando essa linha em algo externo ao seu script. Também não 
há a
> necessidade de utilizar chaves, já que não trabalha com as 
variáveis como
> arrays. E falta o escopo de contexto {} no final do comando find. 
Veja o
> trecho do man find que fala sobre o parâmetro exec:
>        -exec command ;
>               Execute  command;  true if 0 status is returned.  All
> following arguments to find are taken to be argu­
>               ments to the command until an argument consisting of 
`;' is
> encountered.  The string `{}'  is  replaced
>               by the current file name being processed everywhere 
it occurs
> in the arguments to the command, not just
>               in arguments where it is alone, as in some versions 
of find.
> Both of these constructions might need to
>               be escaped (with a `\') or quoted to protect them from
> expansion by the shell.  The command is executed
>               in the starting directory.
> 
> Ele diz que a string {} é substituída pelo nome de arquivo corrente 
sendo
> processado. Por que essa string não existe no seu find ? Veja o que 
acontece
> quando executamos algo similar ao seu comando:
> 
> $ find . -name *.txt -exec ls -l \\\;
> find: missing argument to `-exec'
> 
> Em contrapartida:
> 
> $ find . -name *.txt -exec ls -l {} \;
> -rw-r--r--  1 user user 4 2005-05-17 10:01 ./hattrick/version.txt
> -rw-r--r--  1 user user 4485 2003-06-03 03:15 ./hattrick/lizenz.txt
> -rw-r--r--  1 user user 1602 2002-03-19 
00:34 ./hattrick/hsqldb_lic.txt
> -rw-------  1 user user 494 2005-05-11 17:59
> ./.thunderbird/hdy7x2i4.default/cookies.txt
> -rw-r--r--  1 user user 45 2005-02-10 14:31
> ./.thunderbird/hdy7x2i4.default/extensions/installed-extensions.txt
> 
> Corrija o seu find e SIMPLIFIQUE ! Cole a linha de find que eu 
mande e
> verifique seu funcionamento. Depois, se vc quiser, faça as suas 
firulas.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]