[BASH] Hangman Game: changing a character within a variable without use of sed or awk
Hi i am new to bash scripting but i am learning loads and picking it up quickly however i cant get use to syntax..
What i need to do is access a variable wich contains a word wich has been converted to dashes eg. "------". I need to compare the varaible $letter wich contains the letter the user has inputted against the variable $random_word wich contains the text format of the secret_word eg. "travel". If $letter is in $random_word then it gets the location of the letter and changes it from a "-" to $letter in the var $secret_word.
This is my code soo far however it doesnt compile please help!
(p.s I cannot use sed and awk cus tht would make it too eassy :-P)
function compare_letter () {
oldsecret_word=$secret_word
word_length=${#random_word}
i=0
while [ $i -ne $word_length ]
do
if [ "$letter"=$(echo ${random_word} | cut -c$(($i+1))) ]
then
$secret_word+=$letter
else
$secret_word+="-"
fi
done
if [ $oldsecret_word = $secret_word ]
then
$lives=$(( $lives-1 ))
echo "Bad Luck you lost a life"
else
echo "Good guess"
fi
$guess_number=$(( $guess_number+1 ))
}
|