🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Tratar variables numericas en bash

#7972
From: aru
Date: Wed, 01 Jan 2003 23:41
34 lines
1889 bytes
In article <slrnavhgk0.c15.marmolejo@porta.til>, marmolejo wrote:
... 
>>  Resulta que estaba haciendo un escript en bash con un bucle. Algo as�
>>  
>>  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) ...
Y much�simo mejor, al no llamar a ning�n comando externo:
  for i in *.mp3 ...
 
> Ahora bien, si lo quieres es contar archivos:
> 
> ls -l *.mp3|wc -l

Es la forma m�s r�pida, pero �porqu� el flag -l en ls? 
  ls | wc -l
es m�s que suficiente
Technical Details
Message-ID: <slrnb16vd6.70.aru_no_spam@paleo.chiti.org>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!news.rediris.es!news.uv.es!not-for-mail
References: <ata5pc$mh9$1@julieta.escomposlinux.org> <slrnavhgk0.c15.marmolejo@porta.til>

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 16:38:05 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!news.rediris.es!news.uv.es!not-for-mail
From: aru <aru_no_spam@no_spam.com>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Tratar variables numericas en bash
Date: Wed, 1 Jan 2003 23:41:19 +0000 (UTC)
Organization: Universitat de Valencia
Lines: 34
Distribution: es
Message-ID: <slrnb16vd6.70.aru_no_spam@paleo.chiti.org>
References: <ata5pc$mh9$1@julieta.escomposlinux.org> <slrnavhgk0.c15.marmolejo@porta.til>
NNTP-Posting-Host: 193-153-148-247.uc.nombres.ttd.es
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: peque.uv.es 1041464479 27230 193.153.148.247 (1 Jan 2003 23:41:19 GMT)
X-Complaints-To: newsmanager@uv.es
NNTP-Posting-Date: Wed, 1 Jan 2003 23:41:19 +0000 (UTC)
User-Agent: slrn/0.9.7.4 (Linux)