01-30-06 02:31 AM
usr.bin.python@gmail.com wrote:
>
> cool... mind explaining to me how it works?
The building blocks are...
set - * The shell expands all files and assigns their names to
$1, $2, ..., $<N>
$# The number of arguments <N>
$(( $RANDOM % $# + 1 ))
Make your arithmetic, a random number between 1 and <N>
eval ... \${ $expression }
Since the arithmetic needs to be expanded first to get
some index, you need to escape the first $ to not be
considered by the shell, and in a second "indirection"
step, which is done by eval, to get the actual argument.
Somewhat simplified the expansion steps are...
"Step 0": eval echo \${$(( $RANDOM % $# + 1 ))}
"Step 1": eval echo \${$(( 789 % 22 + 1 ))}
"Step 2": eval echo \${20}
"Step 3": echo ${20}
"Step 4": echo fileNr20
Janis
[ Post a follow-up to this message ]
|