🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #7973

Re: Tratar variables numericas en bash

#7973
From: zd
Date: Thu, 02 Jan 2003 02:35
56 lines
2654 bytes
Respuesta al mensaje de: aru <aru_no_spam@no_spam.com>.
Con identificador: <slrnb16vd6.70.aru_no_spam@paleo.chiti.org>.

>>>  NUMERIC=0
>>>  for i in ls *.mp3
>>>  do
>>           let NUMERIC=$NUMERIC+1
>>>  done
>>>  
>>>  echo $NUMERIC
>> 
>> pero cuenta de m�s, ser�a mejor:
>> 
>> #!/bin/sh
>> NUMERIC=0
>> for i in `ls -c1 *.mp3`
>>     do
>>         let NUMERIC=$NUMERIC+1
>>     done
>> echo $NUMERIC
>
> Naturalmente que cuenta de m�s, porque cuenta 'ls' + '*.mp3', 
> lo correcto ser�a:
>   for i in $(ls *.mp3) ...

    No ex�ctamente. La forma segura de realizar la sustituci�n de co-
mandos es usando "`comando`". La construcci�n "$(comando)" s�lo es v�-
lida en bash y ksh.

> Y much�simo mejor, al no llamar a ning�n comando externo:
>   for i in *.mp3 ...

    S�, eso est� mejor; el int�rprete de ordenes expande los metacarac-
teres el s�lito.

>> Ahora bien, si lo quieres es contar archivos:
>> 
>> ls -l *.mp3|wc -l

    El par�metro "-l" introduce informaci�n de m�s; al menos el "ls" de
GNU a�ade una linea con la cantidad de disco usado por los archivos con-
tenidos en el directorio mostrado.

> Es la forma m�s r�pida, pero �porqu� el flag -l en ls? 
>   ls | wc -l
> es m�s que suficiente

    As� es.

    Saludos.


-- 
Zeles Deree (zeldere) / [.zd]
 * Correo: zeldere_nntp@yahoo.es
 * GNU/Linux - LFS 3.1
Technical Details
Message-ID: <av08i2$a42$1@titan.bt.es>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.astraweb.com!news-small.astraweb.com!news-out.spamkiller.net!propagator2-maxim!news-in.spamkiller.net!news.telia-iberia.com!news.rediris.es!newsfeed.bt.es!news.bt.es!not-for-mail
References: <ata5pc$mh9$1@julieta.escomposlinux.org> <slrnavhgk0.c15.marmolejo@porta.til> <slrnb16vd6.70.aru_no_spam@paleo.chiti.org>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,b6beb247a4710747
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-01-01 18:57:24 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.astraweb.com!news-small.astraweb.com!news-out.spamkiller.net!propagator2-maxim!news-in.spamkiller.net!news.telia-iberia.com!news.rediris.es!newsfeed.bt.es!news.bt.es!not-for-mail
From: zd <zeldere_nntp@yahoo.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Tratar variables numericas en bash
Date: 2 Jan 2003 02:35:46 GMT
Organization: BT Tel. Netnews service (readers)
Lines: 56
Message-ID: <av08i2$a42$1@titan.bt.es>
References: <ata5pc$mh9$1@julieta.escomposlinux.org> <slrnavhgk0.c15.marmolejo@porta.til> <slrnb16vd6.70.aru_no_spam@paleo.chiti.org>
NNTP-Posting-Host: cable223a208.usuarios.retecal.es
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 8bit
X-Trace: titan.bt.es 1041474946 10370 212.183.223.208 (2 Jan 2003 02:35:46 GMT)
X-Complaints-To: abuse@bt.es
NNTP-Posting-Date: 2 Jan 2003 02:35:46 GMT
User-Agent: slrn/0.9.7.3 (Linux)