Created
October 15, 2018 17:35
-
-
Save guimaluf/611fd0db998b023abf31565aecce579d to your computer and use it in GitHub Desktop.
Bash script to roll dices for D&D character sheet creation
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
#!/bin/bash | |
ATRIBUTOS=() | |
function remove_min { | |
local total=0 | |
local dices=() | |
IFS=$'\n' | |
DICES=($(sort <<<"${ROLL[*]}")) | |
unset IFS | |
dices=${DICES[@]:1} | |
total=$(IFS='+';bc<<<"${DICES[*]:1}") | |
echo Dados: ${dices} = ${total} | |
ATRIBUTOS+=($total) | |
} | |
function dice_roll { | |
for i in $(seq 4); | |
do | |
ROLL[i]=$((${RANDOM}%6 +1)) | |
done | |
echo '' | |
echo Rolagem: ${ROLL[@]} | |
} | |
echo '' | |
echo '### ROLAGENS ###' | |
for i in $(seq 6); do | |
dice_roll | |
remove_min | |
done | |
echo '#################' | |
echo '' | |
echo '### ATRIBUTOS ###' | |
echo $(IFS=$'\n'; sort <<<"${ATRIBUTOS[*]}") | |
echo '#################' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment