[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] Ler da entrada padr�o sem ecoar na tela
From: |
Fábio Berbert de Paula |
Subject: |
Re: [shell-script] Ler da entrada padrão sem ecoar na tela |
Date: |
Tue, 3 Jul 2001 11:07:57 -0300 |
Fala Cid,
> Usei o read em um script, mas estou perguntando uma senha
> q está aparecendo na tela. Como perguntar, em bash, algo
> através do read ou algo semelhante sem ecoar na tela?
> Vejam o que fiz:
>
> echo -n "Conectar como: "
> read USERNAME
> echo -n "Senha: "
> read SENHA
Use:
echo -n "Conectar como: "
read USERNAME
echo -n "Senha: "
stty -echo
read SENHA
stty echo
echo ""
echo Sua senha é $SENHA
O segredo está no stty ;o)
Atenciosamente,
--
------------------------------------------------------
Fábio Berbert de Paula address@hidden
------------------------------------------------------
SysAdmin & *UNIX* Developer Linux Solutions
(021) 526-7262 ramal 21
---------------- Yes, I have a Palm ----------------
From (no email address) Tue Jul 03 09:20:18 2001
Return-Path: <address@hidden>
X-Sender: address@hidden
X-Apparently-To: address@hidden
Received: (EGP: mail-7_2_0); 3 Jul 2001 16:20:17 -0000
Received: (qmail 70645 invoked from network); 3 Jul 2001 16:20:16 -0000
Received: from unknown (10.1.10.27) by l9.egroups.com with QMQP; 3 Jul 2001
16:20:16 -0000
Received: from unknown (HELO perninha.conectiva.com.br) (200.250.58.156) by
mta2 with SMTP; 3 Jul 2001 16:20:15 -0000
Received: from burns.conectiva (burns.conectiva [10.0.0.4]) by
perninha.conectiva.com.br (Postfix) with SMTP id 3A6F438C9D for
<address@hidden>; Tue, 3 Jul 2001 13:20:12 -0300 (EST)
Received: (qmail 3802 invoked by uid 0); 3 Jul 2001 16:18:59 -0000
Received: from verde.distro.conectiva (10.0.17.77) by burns.conectiva with
SMTP; 3 Jul 2001 16:18:59 -0000
Date: Tue, 3 Jul 2001 13:28:35 -0300 (BRT)
X-X-Sender: <verde@verde.distro.conectiva>
To: <address@hidden>
Subject: =?iso-8859-1?Q?Re=3A_=5Bshell-script=5D_Ler_da_entrada_padr=E3o?=
=?iso-8859-1?Q?_sem_ecoar_na_tela?=
In-Reply-To: <address@hidden>
Message-ID: <Pine.LNX.4.33L.0107031324500.844-100000@verde.distro.conectiva>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=iso-8859-1
Content-Transfer-Encoding: 8BIT
X-eGroups-From: # aurelio marinho jargas <address@hidden>
From: # aurelio marinho jargas <address@hidden>
olás,
@ 3/7, Fábio Berbert de Paula:
> > Usei o read em um script, mas estou perguntando uma senha
> > q está aparecendo na tela. Como perguntar, em bash, algo
> > através do read ou algo semelhante sem ecoar na tela?
> > Vejam o que fiz:
> >
> > echo -n "Conectar como: "
> > read USERNAME
> > echo -n "Senha: "
> > read SENHA
>
> echo -n "Conectar como: "
> read USERNAME
> echo -n "Senha: "
> stty -echo
> read SENHA
> stty echo
> echo ""
> echo Sua senha é $SENHA
o read pode fazer tudo, imprimir o prompt e esconder a senha:
read -p 'Conectar como: ' USERNAME
read -p 'Senha: ' -s SENHA
ele tem um monte de opções massa:
------------------------------------------------------------
man read
------------------------------------------------------------
-a aname
The words are assigned to sequential indices of the array variable
aname, starting at 0. aname is unset before any new values are
assigned. Other name arguments are ignored.
-d delim
The first character of delim is used to terminate the input line,
rather than newline.
-e If the standard input is coming from a terminal, readline (see READÂ
LINE above) is used to obtain the line.
-n nchars
read returns after reading nchars characters rather than waiting for
a complete line of input.
-p prompt
Display prompt, without a trailing newline, before attempting to read
any input. The prompt is displayed only if input is coming from a
terminal.
-r Backslash does not act as an escape character. The backslash is conÂ
sidered to be part of the line. In particular, a backslash-newline
pair may not be used as a line continuation.
-s Silent mode. If input is coming from a terminal, characters are not
echoed.
-t timeout
Cause read to time out and return failure if a complete line of input
is not read within timeout seconds. This option has no effect if
read is not reading input from the terminal or a pipe.
------------------------------------------------------------
--
s·:(·>(·×^a]×http://www.verde666.org×^[:wq