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

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

Re: [shell-script] Verificar entrada igual ou maior que W051**


From: Leslie Watter
Subject: Re: [shell-script] Verificar entrada igual ou maior que W051**
Date: Thu, 11 Apr 2013 14:03:57 -0300

Por partes, com exemplos:


-- pra pegar parte da tua variável

$ echo $X
w01234_11042013

$ echo ${X:2:4}
1234

----

da onde isso foi tirado ?? (man bash )

----
      ${parameter:offset:length}
              Substring Expansion.  Expands to up to length characters of
parameter starting at the character specified by offset.  If length is
omitted, expands  to  the
              substring  of  parameter starting at the character specified
by offset.  length and offset are arithmetic expressions (see ARITHMETIC
EVALUATION below).  If
              offset evaluates to a number less than zero, the value is
used as an offset from the end of the value of parameter.  Arithmetic
expressions starting with  a
              - must be separated by whitespace from the preceding : to be
distinguished from the Use Default Values expansion.  If length evaluates
to a number less than
              zero, and parameter is not @ and not an indexed or
associative array, it is interpreted as an offset from the end of the value
of parameter  rather  than  a
              number  of characters, and the expansion is the characters
between the two offsets.  If parameter is @, the result is length
positional parameters beginning
              at offset.  If parameter is an indexed array name subscripted
by @ or *, the result is the length members of the array beginning with
 ${parameter[offset]}.
              A  negative offset is taken relative to one greater than the
maximum index of the specified array.  Substring expansion applied to an
associative array pro‐
              duces undefined results.  Note that a negative offset must be
separated from the colon by at least one space to avoid being confused with
the :-  expansion.
              Substring  indexing  is  zero-based  unless  the positional
parameters are used, in which case the indexing starts at 1 by default.  If
offset is 0, and the
              positional parameters are used, $0 is prefixed to the list.
----

... continua :D

[]s

LEslie



2013/4/10 Petterson Faria <address@hidden>

> vc pode usar expansao de variaveis.
> se sempre comeca com w0 + num faz um..
>
> if [ ${var:2} -gt 999 ]; then
>  echo maior que w0999
> fi
>
>
> --
> Atenciosamente,
> *Petterson Faria*
>
> "Há momentos em que a maior sabedoria, é parecer não saber nada" (Sun Tzu)
>
>
>
> 2013/4/10 Roberto Alves <address@hidden>
>
> > **
> >
> >
> > Boa tarde a todos.
> >
> > Estou fazendo um script que vai pegar um diretório e fazer um rsync de
> uma
> > máquina pra outra.
> > Eu verifico o nome da pasta que o cara digita para evitar que seja
> > diferente de um monte de coisas e não causar algum problema.
> >
> > Está quase pronto mas como não sou bom em sed não sei verificar o
> seguinte.
> > As pastas têm o seguinte formato de nome:
> >
> > w01234_11042013
> >
> > Começa com um w e tem 5 digitos mais um sublinhado e uma data.
> > Estamos na numeração w05048 e quando entrarmos no w05100 eu passarei a
> usar
> > este script pra fazer tudo sozinho.
> > Como ainda haverá algumas pastas com numeração abaixo da w05100 eu vou
> ter
> > que verificar se a numeração é igual ou maior que w05100 pra copiar
> apenas
> > estas, mas não sei como.
> >
> > Teria que ser algo do tipo:
> > Começar com w (minuscula) e ser igual ou maior que 05100 (5100 em cinco
> > dígitos. Com um zero à esquerda).
> >
> > ^[w]051?? ...vou jogar isso numa variável e testar se é maior ou igual
> mas
> > não sei mesmo como pegar a numeração pra saber se é maior ou igual a
> 5100.
> > O pouco que aprendi já esqueci porque saí dessa área há quase 5 anos.
> >
> > Já sei que serão muitas sugestões e por isso agradeço antecipadamente.
> >
> > abraços,
> > Roberto
> >
> > [As partes desta mensagem que não continham texto foram removidas]
> >
> >
> >
>
>
> [As partes desta mensagem que não continham texto foram removidas]
>
>
>
> ------------------------------------
>
> ---------------------------------------------------------------------
> Esta lista não admite a abordagem de outras liguagens de programação, como
> perl, C etc. Quem insistir em não seguir esta regra será moderado sem
> prévio aviso.
> ---------------------------------------------------------------------
> Sair da lista: address@hidden
> ---------------------------------------------------------------------
> Esta lista é moderada de acordo com o previsto em
> http://www.listas-discussao.cjb.net
> ---------------------------------------------------------------------
> Servidor Newsgroup da lista: news.gmane.org
> Grupo: gmane.org.user-groups.programming.shell.brazil
>
> Links do Yahoo! Grupos
>
>
>


-- 
Leslie H. Watter


[As partes desta mensagem que não continham texto foram removidas]



reply via email to

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