Pick a card from an array in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pick a card from an array in bash
# 1  
Old 06-30-2011
Pick a card from an array in bash

Hello,

I am trying to use $RANDOM to pick cards from an array in bash. I created the script below to give me a selection everytime I run it, but the output is always like this:
2 3 4 5 6 7 8 9 10 Jack Queen King Ace of Clubs Diamonds Hearts Spades.

Can you please help me? I expected it to give me something like : 2 of Jack or 5 of Hearts, everytime I run it. the codes are below

Code:
 
#!/bin/bash
suite="Clubs Diamonds Hearts Spades"
denomination="2 3 4 5 6 7 8 9 10 Jack Queen King Ace"
num_suites=${#suite[*]}
num_denominations=${#denomination[*]}
echo -n "${denomination[$((RANDOM%num_denominations))]} of "
echo "${suite[$((RANDOM%num_suites))]}"
exit 0

# 2  
Old 06-30-2011
Code:
suite="Clubs Diamonds Hearts Spades"

That's not an array:

Code:
suite=( Clubs Diamonds Hearts Spades )

That's an array.

Fix both of those and it works great.
# 3  
Old 07-02-2011
That's wonderful! It works fine. Thanks so much for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Array connectin to another Array

Hello, i have a script that i need account_number to match a name. for exsample : ACCOUNT_ID=(IatHG8DC7mZbdymSoOr11w KbnlG2j-KRQ0-1_Xk356s8) and i run a loop curl requst with this the issue is that i want to know on which account were talking about so bash will know this : ... (4 Replies)
Discussion started by: batchenr
4 Replies

2. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

3. UNIX for Dummies Questions & Answers

Help with bash array

Hi, I would like to remove audio tracks from several video clips contained in a single directory using the command files=(*.mpg); ffmpeg -i "${files}" -vcodec copy -an na/output.mpg I want each processed file outputted to the sub-directory na retaining the original file name, how do I do that?... (4 Replies)
Discussion started by: jeppe83
4 Replies

4. Shell Programming and Scripting

Pick a line in file 2 basing on array in file1

Dear friends, I have two files. One with all IDs(in a single field) . And another with data(of which say field 5 is ID). I want to create an array of IDs using first file and while reading second file if the ID appears in the array I need to print $0 else skip. After a long gap I am... (6 Replies)
Discussion started by: paresh n doshi
6 Replies

5. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

6. OS X (Apple)

Associated Array in bash

I am using code as below to save data in associated array on Mac OS 10.8. #!/bin/sh storyboardExt=".storyboard" stringsExt=".strings" newStringsExt=".strings.new" oldStringsExt=".strings.old" localeDirExt=".lproj" baseLprojDir="Base${localeDirExt}" echo "${baseLprojDir}" # Find... (2 Replies)
Discussion started by: mikezang
2 Replies

7. Shell Programming and Scripting

Array in Bash!

sorry I am new to the bash scripting since I was used to c shell programming. I am writting a script in bash for which I have to create an array in bash. I was able to do parse one variable through command line by doing": Lets say the below code is part of temp.bash and is called like: temp.bash... (5 Replies)
Discussion started by: dixits
5 Replies

8. UNIX Desktop Questions & Answers

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card?

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card? Does any Linux OS support Nvidia card? (1 Reply)
Discussion started by: sito
1 Replies

9. Shell Programming and Scripting

bash array

I'm trying to move files based on a certain day..my question is on array's, what's wrong with the way I'm stepping through the array? what i have gives me syntax errors..any ideas...so far I have #! /bin/bash sun_d=`cal |grep -v |awk '{printf " " $1}' ` echo "$sun_d" ls -l... (1 Reply)
Discussion started by: gubten
1 Replies

10. Linux

Wireless card won't pick up network

I'm trying to get my wireless card up. I've been at it for a while now and something just isn't quite working right. I'm not getting any wireless signal. I'm using FC4 with a stack 16 kernel and ndiswrappr to load my drivers. here are the outputs that i get. Alittle bit about my... (3 Replies)
Discussion started by: byblyk
3 Replies
Login or Register to Ask a Question