diff options
author | Dennis Eriksen <d@ennis.no> | 2022-12-19 21:48:49 +0100 |
---|---|---|
committer | Dennis Eriksen <d@ennis.no> | 2022-12-19 21:48:49 +0100 |
commit | 5c849d5144bb760cce3dab69422fdf794717afd8 (patch) | |
tree | ee968180832b15821b5602afa5f881fa8a6263ca | |
parent | adding a zsh and a posix sh implementation of makepass. (diff) | |
download | makepass-5c849d5144bb760cce3dab69422fdf794717afd8.tar.gz |
head -c is not portable.. tail -c is. and head -n
-rwxr-xr-x | bin/bin/makepass.sh | 12 | ||||
-rwxr-xr-x | bin/bin/makepass.zsh | 12 |
2 files changed, 12 insertions, 12 deletions
diff --git a/bin/bin/makepass.sh b/bin/bin/makepass.sh index 0877cc9..6b80420 100755 --- a/bin/bin/makepass.sh +++ b/bin/bin/makepass.sh @@ -26,7 +26,7 @@ if [ ! -z "$1" ] && [ ! ${1:-0} -gt 0 ]; then printf '%s\n' 'not a number above _RANDOM() { RANDOM=0 while [ ! "$RANDOM" = "${RANDOM#0}" ]; do - RANDOM=$(< /dev/urandom tr -cd "[:digit:]" | head -c 8) + RANDOM=$(head -n100 /dev/urandom | tr -cd "[:digit:]" | tail -c 8) done printf '%s\n' "$RANDOM" return 0 @@ -47,14 +47,14 @@ _random() ( if [ "$fla" = "true" ]; then if [ $len -le 2 ]; then - string="$(< /dev/urandom tr -cd '[:alpha:]' | head -c $len)" + string="$(head -n10 /dev/urandom | tr -cd '[:alpha:]' | tail -c $len)" else - string="$(< /dev/urandom tr -cd '[:alpha:]' | head -c 1)" - string="${string}$(< /dev/urandom tr -cd "$chars" | head -c $((len-2)))" - string="${string}$(< /dev/urandom tr -cd '[:alpha:]' | head -c 1)" + string="$(head -n10 /dev/urandom | tr -cd '[:alpha:]' | tail -c 1)" + string="${string}$(head -n100 /dev/urandom | tr -cd "$chars" | tail -c $((len-2)))" + string="${string}$(head -n10 /dev/urandom | tr -cd '[:alpha:]' | tail -c 1)" fi else - string="$(< /dev/urandom tr -cd "$chars" | head -c $len)" + string="$(head -n100 /dev/urandom | tr -cd "$chars" | tail -c $len)" fi printf '%s\n' "$string" diff --git a/bin/bin/makepass.zsh b/bin/bin/makepass.zsh index 0579503..bba6097 100755 --- a/bin/bin/makepass.zsh +++ b/bin/bin/makepass.zsh @@ -25,7 +25,7 @@ emulate -L zsh # Function to create random stuff function _random() { setopt local_options - RANDOM=$(< /dev/urandom tr -cd "[:digit:]" | head -c 8) # seed RANDOM + RANDOM=$(head -n 100 /dev/urandom | tr -cd "[:digit:]" | tail -c 8) # seed RANDOM # Default is a number between 8 and 44 local -i len=$1 @@ -41,14 +41,14 @@ function _random() { if [[ $fla == true ]]; then if (( len <= 2 )); then - string="$(< /dev/urandom tr -cd '[:alpha:]' | head -c $len)" + string="$(head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c $len)" else - string="$(< /dev/urandom tr -cd '[:alpha:]' | head -c 1)" - string+="$(</dev/urandom tr -cd "$chars" | head -c $((len-2)))" - string+="$(</dev/urandom tr -cd '[:alpha:]' | head -c 1)" + string="$( head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c 1)" + string+="$(head -n 100 /dev/urandom | tr -cd "$chars" | tail -c $((len-2)))" + string+="$(head -n 10 /dev/urandom | tr -cd '[:alpha:]' | tail -c 1)" fi else - string="$(< /dev/urandom tr -cd "$chars" | head -c $len)" + string="$(head -n 100 /dev/urandom | tr -cd "$chars" | tail -c $len)" fi printf '%s\n' "$string"; return |