cogiz
November 13, 2016, 8:20pm
1
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 suggestions and advice would be Greatly appreciated.
Thank you,
Cogiz
Aia
November 13, 2016, 8:50pm
2
cogiz:
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 suggestions and advice would be Greatly appreciated.
Thank you,
Cogiz
for e in ${computerhand[@]}; do
if [[ $e =~ 6|D ]]; then
echo "$e" >> test.output
fi
done
#!/bin/bash
computerhand=(6H 2C JC QS 9D 3H 8H 4D)
topcard=6D
search="${topcard:0:1}|${topcard:1:1}"
for e in ${computerhand[@]}; do
if [[ $e =~ $search ]]; then
echo "$e" >> test.output
fi
done
1 Like
cogiz
November 15, 2016, 5:44pm
3
thank you very much. It worked like a charm
Cogiz