If then statement confusion

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers If then statement confusion
# 1  
Old 12-08-2016
If then statement confusion

Code:
#!/bin/bash
PH=(KD 6S TC 3D)                 #playerhand
TCIP=(AH)                               #topcard in play
A=( "${TCIP[@]::1}" )               # A
B=( "${TCIP[@]:1}" )                # H
C=8

for e in ${PH[@]}; do
  if [[ $e =~ $A|$B|$C ]]; then
     echo "$e " >> /home/cogiz/validcards.txt 
  else
     echo "0" >> /home/cogiz/validcards.txt
  fi           
done

In the above code, if ${PH[@]} is scanned for an A,H, or 8 but none of those are found and results are all 0's. How could I then issue a separate command for that situation?

Thank you in advance for any suggestions.
Cogiz

Last edited by rbatte1; 12-08-2016 at 09:16 AM.. Reason: syntax
# 2  
Old 12-08-2016
If I understand you correctly, whilst you are in your for loop, you could set a flag within the then section to mark that you have found at least one of them, then after the loop test its value.

Would that help?



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed confusion

#!/bin/bash X=(0 2 4 6 7 0 0 0 0) Let me just say from the start that sed confuses the hell out of me! In the above line of code how can I use sed to remove all of the 0's except the first one? I have tried sed -e 's/*$//g' but it removes all of the 0's. Thank you in advance for any and... (3 Replies)
Discussion started by: cogiz
3 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. IP Networking

iptables Confusion

Hi all, I am looking to get a few questions answered but I am having trouble finding an answer to these specific questions online. 1. Order of operations: THere are plenty of fancy diagrams online that illustrate the order of operations for IPTables (Raw before Mangle for example) but what I... (1 Reply)
Discussion started by: knightfirefx
1 Replies

4. Shell Programming and Scripting

Confusion with PS

Hello All, I have a problem in counting number of process getting run with my current script name.. Here it is ps -ef | grep $0 | grep -v grep This display just one line with the PID, PPID and other details when i print it in the script. But when I want to count the numbers in my... (11 Replies)
Discussion started by: sathyaonnuix
11 Replies

5. Programming

const_cast confusion

See code below. It appears that i and j inhabit the same address yet hold different values. Can anyone shed light on this? int main() { const int i= 3; int* j = const_cast<int*>(&i); *j = 5; cout << j << endl << &i << endl; cout << *j << endl << i; } (4 Replies)
Discussion started by: StuartH
4 Replies

6. Cybersecurity

LDAP; confusion

Hello, I hope all is well. Two issues that I am grappling with. One: Is this a true statement: (AIX, LDAP configured), even if authentication is configured with LDAP, the system would still need to be authenticated against local (/etc/passwd); incase of network failure? Two: I can log... (0 Replies)
Discussion started by: rsheikh
0 Replies

7. UNIX for Dummies Questions & Answers

crontab confusion

I come across an entry in cron which is in such: 0 * * * * What is the first 0 indicating? 0 minute? meaning a script cron as such will run every minute? :confused: (2 Replies)
Discussion started by: user50210
2 Replies

8. UNIX for Dummies Questions & Answers

'tr' confusion

Good day, everyone! Could anybody explain me the following situation. If I'm running similar script: Var="anna.kurnikova" Var2="Anna Kurn" echo $Var | tr -t "$Var" "$Var2" Why the output is : anna KurniKova instead of Anna Kurnikova? :confused: Thank you in advance for any... (2 Replies)
Discussion started by: Nafanja
2 Replies

9. Shell Programming and Scripting

Sed confusion

Hello all, I am trying to delete all the lines in a particular file having a pattern. The problem is that it has special characters and for some reason is not doing the job. For eg. src_file /home/test/filelist.txt :xxxx:ogog /home/test/RCH/ogogogg /home/test/RYHUJ/HHHH... (3 Replies)
Discussion started by: alfredo123
3 Replies

10. UNIX for Dummies Questions & Answers

Clear confusion

Hi, In some machines when i type "clear" it completely clears all the contents on that window but on some it simply scrolls up all the content. How can i change this? (4 Replies)
Discussion started by: vibhor_agarwali
4 Replies
Login or Register to Ask a Question