The above script is a rewrite of a terminal game of crazy 8's in Bash that I have been working on. The problem I am having is that the output file (choices.txt) is not showing me all of the results that it should. when the above script was run, the output in the choices.txt file was ( 0 0 0 9H 0 0 0 9S ).
It should have been ( 0 0 0 9H KC 0 7C 9S ).
Each time I run this script ( ./crazy.sh ) it gives me a different answer but always an incomplete one.
Can anyone explain to me why this is happening? I have been racking my brain for days trying to figure this out. Why does it show some valid card choices but not all? What am I missing?
Thank you in advance for any and all suggestions and advice.
Running your final for loop with the variables (not arrays!) set to the values indicated, I get 0 0 0 9H KC 0 7C 9S, so the logics seem to be OK. The inconsistent behaviour might be caused by some creative use of variables, arrays, separators, and assignments.
The way you assign them, A and B will be arrays with one single element only. Scrutinizer already proposed an alternative use. mapfile will (man bash) "Read lines from the standard input into the indexed array variable array", so again array PH has just one element as the input file has all cards in one line separated by spaces.
While the logics should work nevertheless, I can't assess the ramifications of using arrays vs. variables. Wouldn't it be worthwhile to try simple variables?
BTW, would your system allow for this construct:
Last edited by RudiC; 01-19-2017 at 02:19 PM..
Reason: typo, small enhancement.
Well, talking of complexity: your entire script looks somewhat overcomplicated to me. Although I like subroutines and functions for repeating tasks, jumping to and fro between them just for the sake of it might overdo it. Consider the following - it should do exactly what you need (if I read the script correctly):
trying a little bit of array scanning for open ports.
my code looks like below:
/bin/netstat -lntp|\
awk 'BEGIN { split("25 80 2020 6033 6010",q); }
$1 == "tcp" { split($4,a,":"); p]++; }
$1 == "tcp6" { split($4,a,":");p]++ }
END {
for ( i in q ) {
if (! q in p ) {... (8 Replies)
example of problem:
#!/bin/bash
P=(2 4 7)
How would you randomly choose one of these 3 numbers in this array?
either 2 or 4 or 7 is needed...but only one of them.
Thanks in advance
Cogiz
Please use CODE tags as required by forum rules! (3 Replies)
Example of problem:
computerhand=(6H 2C JC QS 9D 3H 8H 4D)
topcard=6D
How do you search ${computerhand} for all elements containing either a "6" or a "D" then
save the output to a file?
This is a part of a Terminal game of Crazy 8's that I'm attempting to write in Bash.
Any... (2 Replies)
Hi All,
need help with reading the array and sum of the array elements.
given an array of integers of size N . You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large.
Input Format
The first line of the input consists of an... (1 Reply)
I have a script which takes backup of some configuration files on my server. It does that by using an array which contains the complete path to the files to backup.
It copys the files to a pre defined dir. Each "program" has it's own folder, ex. apache.conf is being copied to /predefined... (7 Replies)
Hi I have two arrays :
@arcb= (450,625,720,645);
@arca=(625,645);
I need to remove the elements of @arca from elements of @arcb so that the content of @arcb will be (450,720).
Can anyone sugget me how to perform this operation?
The code I have used is this :
my @arcb=... (3 Replies)
Hi Guys,
I have an array which has numbers including blanks as follows:
1
26
66
4.77
-0.58
88
99
11
12
333
I want to print a group of three elements as a different column in a file as follows:(including blanks where there is missing elements) for.e.g. array element #7... (4 Replies)