Created
May 19, 2020 17:42
-
-
Save Snarp/da259a0cc2a2c43998365351e2556237 to your computer and use it in GitHub Desktop.
Generate random string in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# How-to: | |
# bash rand_str.bash {{optional length}} | |
# Source: https://www.tldp.org/LDP/abs/html/string-manipulation.html | |
LEN=$1 | |
if [ -z $LEN ]; then LEN=8; fi | |
str0="$$" | |
str1=$( echo "$str0" | md5sum | md5sum ) | |
randstring="${str1:2:LEN}" | |
echo "random string: $randstring" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment