#!/bin/bash # # filename is genpass.sh # # example usage for an eight character password # . genpass.sh 8 # genpasswd() { local l=$1 [ "$l" == "" ] && l=16 tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs } # you could use a number instead of $1 to set the length genpasswd $1