scripts

My personal collection of scripts
git clone git://src.gearsix.net/scriptsscripts.zip
Log | Files | Refs | Atom | README | LICENSE

randstr.sh (raw) (369B)


   1 #!/bin/sh
   2 # randstr
   3 # description: generate a random string of size $1 (default: 10)
   4 # e.g.$ randstr 10
   5 
   6 if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
   7 	echo "Usage: randstr [SIZE]"
   8 	echo ""
   9 	echo "print a random string of SIZE length (default: 10)"
  10 	exit
  11 fi
  12 
  13 len=10
  14 if [ $1 ]; then len=$1; fi
  15 
  16 echo $(cat /dev/urandom | tr -dc "a-zA-Z0-9" | fold -w $len | head -n 1)