#!/bin/bash

ECHOARGS=
LENGTH=12

while getopts nl: ARG; do
    case ${ARG} in
        n) ECHOARGS="-n"
           ;;

        l) LENGTH=${OPTARG}
           ;;

        ?) printf "Usage: %s [-n] [-l X]\n" ${0}
           exit 1
           ;;
    esac
done

PW=$(openssl rand -base64 ${LENGTH} | cut -c1-${LENGTH})

echo ${ECHOARGS} ${PW}

exit 0