πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Elegir un fichero al azar

#12377
From: Antonio Villalon
Date: Wed, 25 Jul 2001 20:23
42 lines
2495 bytes
rvm <rvm@linuxfan.com> wrote:
[...]
: Quisiera saber si es posible en bash leer el nombre de todos los ficheros de 
: un directorio (o todos los *.jpg, por ejemplo) y luego seleccionar 
: aleatoriamente uno de ellos. Luego ese fichero se lo pasarΓ­a al xloadimage 
: para que pusiera la imagen en la pantalla.

Holas,
Puedes hacer algo parecido a esto (ojo con los valores +/-1, lo mismo se me
ha pasado alguno):

NFILES=`find . -name "*.jpg"|wc -l`
file=`echo $[$RANDOM%$[NFILES+1]]`
xv -root -quit `find . -name "*.jpg"|head -$file|tail -1`

Pegale un vistazo a la variable $RANDOM de algunos shells, bash entre ellos.

Saludos,
			Toni
-- 
#############################################################################
#                      Toni Villalon <toni@aiind.upv.es>                    #
#           TELNET andercheran.aiind.upv.es 2895  for PGP Public Key        #
############################################################################# 
#  "The bad reputation Unix has gotten is totally undeserved, laid on by    #
#   people who don't understand, who have not gotten in there and tried     #
#   anything."                                                              #
#                                              Jim Joyce                    #
############# This .signature is written in 100% recycled bytes #############
Technical Details
Message-ID: <9jn9rl$igf$1@polaris.cc.upv.es>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!news.comunitel.net!news.rediris.es!news.uv.es!news.upv.es!not-for-mail
References: <2522487.MNUckLgytD@rvmsoft.localdomain>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,a6a4e55da032ea5d
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2001-07-25 13:38:02 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!news.comunitel.net!news.rediris.es!news.uv.es!news.upv.es!not-for-mail
From: Antonio Villalon <toni@andercheran.aiind.upv.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Elegir un fichero al azar
Date: 25 Jul 2001 20:23:17 GMT
Organization: U.P.V.
Lines: 42
Message-ID: <9jn9rl$igf$1@polaris.cc.upv.es>
References: <2522487.MNUckLgytD@rvmsoft.localdomain>
NNTP-Posting-Host: andercheran.aiind.upv.es
Mime-Version: 1.0
Content-Type: text/plain; charset=ES-ASCII
Content-Transfer-Encoding: quoted-printable
X-Trace: polaris.cc.upv.es 996092597 18959 158.42.22.41 (25 Jul 2001 20:23:17 GMT)
X-Complaints-To: newsmaster@upv.es
NNTP-Posting-Date: 25 Jul 2001 20:23:17 GMT
User-Agent: tin/1.4.3-20000502 ("Marian") (UNIX) (Linux/2.2.19 (i586))