Re: Elegir un archivo aleatorio en un script
Ipsissima verba Hue-Bond:
> Cesar Rincon, Sat20030809@01:33:08(-0500):
> >
> >A=($DIR/*)
>
> Esto me ha despistado. Lo único que veo en el man acerca de los
> paréntesis es que su contenido se ejecuta en una subshell. Sin
> embargo, parece que tú estás creando un array.
Bash es confuso a veces. Los paréntesis denotan ejecución en
subshell, sí, salvo cuando van precedidos por una asignación (nombre
de variable y signo 'igual qué'). De la sección "Arrays" del manual
bash(1):
"Arrays are assigned to using compound assignments of the form
name=(value1 ... valuen), where each value is of the form [sub-
script]=string. Only string is required. If the optional brackets
and subscript are supplied, that index is assigned to; otherwise the
index of the element assigned is the last index assigned to by the
statement plus one. Indexing starts at zero. This syntax is also
accepted by the declare builtin. Individual array elements may be
assigned to using the name[subscript]=value syntax introduced
above."
De forma que también es válido
A=([2]=dos [4]=cuatro [6]=seis)
para asignar los índices 2, 4 y 6 específicamente.
Saluditos.
-CR
Reply to: