Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Created May 23, 2024 22:42
Show Gist options
  • Save mike-neck/cd113604e4ce86eed7d4e2ccb0dbb3dd to your computer and use it in GitHub Desktop.
Save mike-neck/cd113604e4ce86eed7d4e2ccb0dbb3dd to your computer and use it in GitHub Desktop.
ランダム文字列を生成するシェルスクリプト
#!/usr/bin/env bash
function generateRandomAlNumString() {
local chars=($(echo {a..z} {A..Z} {0..9}));
local string=()
local index
local loopIndex
for loopIndex in {1..16}; do
index="$(( RANDOM % 62 ))"
index="$(( index + 1 ))"
string+=("${chars[index]}")
done
local oldfs="${IFS}"
IFS=""
echo -n "${string[*]}"
IFS="${oldfs}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment