Linux Bash Who Am I Game Example

Go down

Linux Bash Who Am I Game Example

Post by jamied_uk on 12th June 2018, 16:58





Code:
#!/bin/bash
# (c) J~Net 2018
# Example ./whoami.sh
#
ans1="a dog"
ans2="dog"
# check if 1st attempt
if [ $# -eq 0 ]
then
    wrong="0"
else
    wrong="$1"   
fi
# keep current attempts
echo "Guess what \ Who I am"
read q
# Check
if [ "$ans1" = "$q" ] || [ "$ans2" = "$q" ]
then
    echo "Correct!"
    wrongtotal=$(($wrong + 1))
    echo "You got it in $wrongtotal Attempts"
   
else
    echo "Wrong"
    wrong=$(($wrong + 1))
    echo "Current Attempts $wrong "
    bash whoami.sh $wrong
fi
#
#
#
# stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script
# stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-script
avatar
jamied_uk
Admin

Posts : 2427
Join date : 2010-05-09
Age : 35
Location : UK

http://address-shortner.co.uk

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum