[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Saida de pipe precedido por !
From: |
Mauricio Vieira |
Subject: |
Saida de pipe precedido por ! |
Date: |
Wed, 13 Jun 2001 16:22:35 -0300 (BRT) |
Salve Mestres,
tenho o seguinte script:
#!/bin/bash
while [ -z "$MATRICULA" ]; do
echo -n "Digite o numero de matricula do usuario (9 digitos, sem o
hífen) : "
read MATRICULA
if ! echo $MATRICULA | grep "[0-9]\{9\}" &2>/dev/null ; then
echo "Matricula aceita";
else
MATRICULA="";
fi
done
~
nao importa se coloco um "!" antes ou depois do echo $MATRICULA, qndo testo o
script
tanto com uma entrada certa (111222333) qnto com uma errada (asdf) ele imprime
"Matricula aceita".
araketu:~/scripts$ matricula.sh
Digite o numero de matricula do usuario (9 digitos, sem o hífen) : 111222333
Matricula aceita
araketu:~/scripts$ 111222333
araketu:~/scripts$ matricula.sh
Digite o numero de matricula do usuario (9 digitos, sem o hífen) : asdf
Matricula aceita
Fiz os testes diretamente no shell, e nao entendi porque nao fez diferenca:
araketu:~/scripts$ if echo 111222333 | grep "[0-9]\{9\}" &2>/dev/null ; then \
echo "Matricula aceita"; else echo "MATRICULA INCORRETA"; fi
[1] 26393
111222333
Matricula aceita
araketu:~/scripts$
#agora com o ! antes do echo.
araketu:~/scripts$ if ! echo 111222333 | grep "[0-9]\{9\}" &2>/dev/null ; then
\
echo "Matricula aceita"; else echo "MATRICULA INCORRETA"; fi
[1] 26602
111222333
Matricula aceita
araketu:~/scripts$ if echo asdf | grep "[0-9]\{9\}" &2>/dev/null ; then \
echo "Matricula aceita"; else echo "MATRICULA INCORRETA"; fi
[1] 26410
Matricula aceita
[1]+ Exit 1 echo asdf | grep "[0-9]\{9\}"
araketu:~/scripts$
#Pq ele só responde o exit status depois de ter imprimido a saida errada?
#agora com o ! antes do echo.
araketu:~/scripts$ if ! echo asdf | grep "[0-9]\{9\}" &2>/dev/null ; then \
echo "Matricula aceita"; else echo "MATRICULA INCORRETA"; fi
[1] 26582
Matricula aceita
[1]+ Exit 1 echo asdf | grep "[0-9]\{9\}"
Estranho.
do man bash
/ Pipelines
"If the reserved word ! precedes a pipeline, the exit status of that
pipeline is the logical NOT of the exit status of the last command.
Otherwise, the status of the pipeline is the exit status of the last
command. The shell waits for all commands in the pipeline to terminate
before returning a value."
O grep nao deveria aceitar apenas o numero de 9 digitos? Pq o ! nao faz
diferenca nesses testes?
O exit status do pipe não é igual ao do grep? O segundo teste deveria mostrar
apenas "MATRICULA INCORRETA", certo? O que estou fazendo errado?
Ah:
araketu:~/scripts$ bash --version
GNU bash, version 2.03.0(1)-release (i386-slackware-linux-gnu)
Copyright 1998 Free Software Foundation, Inc.
Agradeço desde já qualquer esclarecimento
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Mauricio B. C. Vieira - address@hidden
Computer Science Student - Federal University of Bahia, Brazil
Estudante de Ciencia da Computacao - UFBA, Salvador - Brasil
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- Identificar comando não executado em script, Cid R Andrade, 2001/06/13
- Re: [shell-script] Identificar comando não executado em script, Paulo Roberto de Paiva, 2001/06/13
- Saida de pipe precedido por !,
Mauricio Vieira <=
- => site com shell scripts <=, Eder Jordam, 2001/06/14
- Re: [shell-script] => site com shell scripts <=, Diogo Florenzano Avelino, 2001/06/14
- Motd, Marlon C. Garcia, 2001/06/14
- Re: [shell-script] Motd, Daniel Duclos, 2001/06/15
- Re: [shell-script] Motd -- Complementando, Daniel Duclos, 2001/06/15