From ff0632fc0f067ab3c247fa3d4ee21d2bc8ef3181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Thu, 12 Nov 2020 14:07:16 +0100 Subject: [PATCH] Functional code. --- d6.sh | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/d6.sh b/d6.sh index f49bc05..1280b72 100755 --- a/d6.sh +++ b/d6.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # This is free and unencumbered software released into the public domain. # # Anyone is free to copy, modify, publish, use, compile, sell, or @@ -86,7 +86,33 @@ do esac done -echo "NUM_WORDS=$NUM_WORDS" -echo "WORDLIST=$WORDLIST" -echo "DELIMITER=$DELIMITER" -echo "CASE=$CASE" +WORDS="" + +for i in $(seq 1 $NUM_WORDS) +do + ROLLS="" + for j in {1..5} + do + ROLLS="$((1 + $RANDOM % 6))$ROLLS" + done + + if [ $CASE == "upper" ] + then + WORD="$(awk "/$ROLLS/{ print toupper(\$2) }" $WORDLIST)" + elif [ $CASE == "lower" ] + then + WORD="$(awk "/$ROLLS/{ print tolower(\$2) }" $WORDLIST)" + else + WORD="$(awk "/$ROLLS/{ print \$2 }" $WORDLIST)" + WORD="${WORD^}" + fi + + if [ $i -eq $NUM_WORDS ] + then + WORDS="${WORDS}${WORD}" + else + WORDS="${WORDS}${WORD}${DELIMITER}" + fi +done + +echo "$WORDS"