Created
March 5, 2023 00:06
-
-
Save samm81/783d24d55745d029c09fb5920154ffde to your computer and use it in GitHub Desktop.
takes a list of people on stdin and generates files with assassin targets
This file contains 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 | |
# unnoficial strict mode, note Bash<=4.3 chokes on empty arrays with set -u | |
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | |
# https://sharats.me/posts/shell-script-best-practices/ | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
IFS=$'\n\t' | |
shopt -s nullglob globstar | |
[[ "TRACE" == "1" ]] && set -o xtrace | |
usage() { | |
echo 'usage: ./assassins.sh | |
takes a list of people on stdin and generates files with assassin targets' | |
exit | |
} | |
[[ "${1:-}" =~ ^-*h(elp)?$ ]] && usage | |
cd "$(dirname "$0")" | |
main() { | |
mapfile -t people | |
people_shuf=( $(shuf -e "${people[@]}") ) | |
num_people="${#people_shuf[@]}" | |
people_looped=( "${people_shuf[@]}" "${people_shuf[0]}" ) | |
for (( i = 0; i < "$num_people"; i++ )); do | |
person=$"${people_looped[$i]}" | |
target=$"${people_looped[$((i + 1))]}" | |
echo "$target" > "${person}.txt" | |
done | |
} | |
main "$@" | |
# never end a file with a short-curcuit! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment