mercredi 3 mars 2021

How to generate a random string in bash?

My goal is to have something like this in bash:

str=random_string(n scharacters)

I have managed to do the following:

chars=abcdefghijklmnopqrstuvwxyz
for (( i=1; i<=n; i++ ))
do
   str="${chars:RANDOM%${#chars}:1}"
done

The problem is that str also contains new lines.

Do you have any ideas?




Aucun commentaire:

Enregistrer un commentaire