aboutsummaryrefslogtreecommitdiffstats
path: root/examples/scripts/randomcard.bash
diff options
context:
space:
mode:
authorJari Aalto <jari.aalto@cante.net>1998-04-17 19:52:44 +0000
committerJari Aalto <jari.aalto@cante.net>2009-09-12 16:46:51 +0000
commitcce855bc5b117cb7ae70064131120687bc69fac0 (patch)
tree39c7a4ec8f6d22ef03df74f2684e6a04fef10399 /examples/scripts/randomcard.bash
parente8ce775db824de329b81293b4e5d8fbd65624528 (diff)
downloadandroid_external_bash-cce855bc5b117cb7ae70064131120687bc69fac0.tar.gz
android_external_bash-cce855bc5b117cb7ae70064131120687bc69fac0.tar.bz2
android_external_bash-cce855bc5b117cb7ae70064131120687bc69fac0.zip
Imported from ../bash-2.02.tar.gz.
Diffstat (limited to 'examples/scripts/randomcard.bash')
-rw-r--r--examples/scripts/randomcard.bash18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/scripts/randomcard.bash b/examples/scripts/randomcard.bash
new file mode 100644
index 0000000..9cb6b50
--- /dev/null
+++ b/examples/scripts/randomcard.bash
@@ -0,0 +1,18 @@
+# The following prints a random card from a card deck.
+#
+# cribbed from the ksh93 book, example from page 70
+#
+# chet@po.cwru.edu
+#
+declare -i i=0
+
+# load the deck
+for suit in clubs diamonds hearts spades; do
+ for n in ace 2 3 4 5 6 7 8 9 10 jack queen king; do
+ card[i]="$n of $suit"
+ i=i+1 # let is not required with integer variables
+ done
+done
+
+# and print a random card
+echo ${card[RANDOM%52]}