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

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

Re: echo


From: César A . K . Grossmann
Subject: Re: echo
Date: Tue, 05 Aug 2003 18:13:10 -0000
User-agent: eGroups-EW/0.82

--- Em address@hidden, "NetStaRt" <news.ckendy@b...>
escreveu
> Quando eu executo 
> echo AlgumaCoisa > arq.txt
> 
> no arquivo arq.txt vai ficar a string AlgumaCoisa, caso 
> eu execute novamente, porem com uma string diferente, o 
> conteudo vai ser sobrescrito. Como eu faço para o shell 
> pedir uma confirmacao?

Buenas, eu não sei se dá para fazer com que ele peça confirmação, o
que dá é:

1. Usar o >>, que vai colocar a nova string no fim do arquivo, em vez
de sobrescrever o arquivo original com um novo arquivo só com aquele
conteúdo.

2. Da página man do bash (um interpretador de shell popular):

   Redirecting Output
       Redirection  of  output causes the file whose name results
       from the expansion of word to be  opened  for  writing  on
       file descriptor n, or the standard output (file descriptor
       1) if n is not specified.  If the file does not  exist  it
       is created; if it does exist it is truncated to zero size.

       The general format for redirecting output is:

              [n]>word

       If the redirection operator is >, and the noclobber option
       to  the set builtin has been enabled, the redirection will
       fail if the file whose name results from the expansion  of
       word  exists  and  is  a regular file.  If the redirection
       operator is >|, or the redirection operator is >  and  the
       noclobber  option  to  the  set  builtin  command  is  not
       enabled, the redirection is attempted  even  if  the  file
       named by word exists.

Ou seja, dá para fazer com que a redireção simples falhe, usando "set
-o noclobber". Veja o exemplo abaixo:

$ cat teste.txt
teste
$ set -o noclobber
$ echo teste > teste.txt
bash: teste.txt: cannot overwrite existing file

[]s
--
Cesar A. K. Grossmann ICQ UIN: 35659423
O Maravilhoso Mundo do Linux 2.6 - Confira a tradução!
http://www.LinuxByGrossmann.cjb.net/wwol26-ptBR.html


reply via email to

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