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

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

redirecionamento para iniciantes


From: Ivan lopes
Subject: redirecionamento para iniciantes
Date: Mon, 1 Oct 2007 20:17:41 -0300

pretendo responder a pergunta que o grande Julio fez em um post
anterior ... mas
preferi responder em tres e-mails, onde todo o topico serah abordado,  partindo
do iniciante  ateh o cascudo .. HAHAHHAHAHA


- Iniciante -

a) gerando erro no comando 'fmt'.

$ fmt -y
fmt: invalid option -- y
Try `fmt --help' for more information.

=====================Atencao======================
Lembre-se da correspondencia entre os numeros e os
FD (file descriptores).
0 - stdin
1 - stdout
2 - stderr
==================================================

b) Ligando a saida padrao 'stdout' com o arquivo
   'a.txt'

$ fmt -y > a.txt
fmt: invalid option -- y
Try `fmt --help' for more information.

$ test -e a.txt && echo 'Arquivo existe'
$ echo $?
0

ou

$ test -e a.txt && echo 'Arquivo existe' || echo 'Arquivo nao existe'
Arquivo existe

Legal o arquivo existe ... mas oque tem dentro dele????

$ cat a.txt

Putz!!! ... tah vazio.
...
Sim faz sentido, pois vc ligou 'stdout' com um
arquivo, todavia, seu comando soh cuspiu 'stderr'

facil ...

=================!!!*Atencao*!!!==================
$ fmt -y > a.txt
$ fmt -y 1> a.txt
sao equivalentes, pois o 1 estah subentendido.
==================================================

c) Ligando o FD 2 com um arquivo.

direciono FD 2 do comando para o arquivo 'b.txt'.
$ fmt -y 2> b.txt

Podemos verificar que realmente conseguimos
escrever no arquivo com a saida do FD 2.

$ cat b.txt
fmt: invalid option -- y
Try `fmt --help' for more information.

OK??
tranquilo ...

d) Utilizando a opcao '--version' que eh valida, e
conduzida por stdout, temos:

$ fmt --version
fmt (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Ross Paterson.

e) Ligando o FD 1 com um arquivo.

$ fmt --version  > a.txt

$ cat a.txt
fmt (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Ross Paterson.

e) Ligando o FD 2 com um arquivo.

$ fmt --version 2> b.txt
fmt (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Ross Paterson.

$ cat b.txt
esse arquivo estah vazio ...

perfeito, muito facil ...


-- 
[ ]'s
Ivan Carlos Da Silva Lopes

Engenheiro Eletronico e Computacao
UFRJ


reply via email to

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