Afficher un message
Vieux 02/05/2006, 15h40   #4
Pascal Bourguignon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: manipuler des chaines de caracteres

lhabert@clipper.ens.fr (Luc Habert) writes:

> octane@alinto.com :
>
>> Ensuite est il possible pour un script shell de generer 8 caracteres
>> compris dans la tranche ASCII 0x20 .. 0x126 ?

> ^^^^^
> Tu veux dire «0x7E», j'imagine?
>
>> (l'idee est d'en faire un generateur de mot de passe aleatoire)

>
> A=`dd bs=N count=1 </dev/urandom | mimencode`
> echo "${A%%=*}"
>
> pour un certain N. Bon d'accord, les caractères ne sont choisis que parmi 64
> caractères sur 95.


Oui, mais là, tu utilises dd. C'est de la triche, on demandait un
script shell, pas un dd...

#!/bin/bash
chars=' !\"#$%&'\''()*+,-./0123456789:;<=>?'
chars="$chars"'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'
chars="$chars"'\`abcdefghijklmnopqrstuvwxyz\{\|\}\ ~'
echo -n 'Generated: '
i=0 ; while [ $i -lt 8 ] ; do
echo -n "${chars:$(( $RANDOM % ( 1 + ${#chars} ) )):1}"
# I know about print, but it's an external program.
i=$(( $i + 1 ))
done
echo ''






--
__Pascal Bourguignon__ http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
  Réponse avec citation
 
Page generated in 0,05665 seconds with 9 queries