Skip to content

Instantly share code, notes, and snippets.

@baszoetekouw
Last active March 26, 2019 08:14
Show Gist options
  • Save baszoetekouw/69e9921a41791c3dde29554ec44401c6 to your computer and use it in GitHub Desktop.
Save baszoetekouw/69e9921a41791c3dde29554ec44401c6 to your computer and use it in GitHub Desktop.
Create a nicely formatted secret
#!/bin/bash
set -e
# defaults
num=24
grp=5
# ugly hack: arithmetric expansion $(()) will return 0 for non-integer arguments
if [ $(($1)) != 0 ]
then
num=$1
fi
if [ $(($2)) != 0 ]
then
grp=$2
fi
pwgen -s $num -1 | perl -pe 's/.{'$grp'}(?!$)/$&-/g'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment