Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-26-2009, 07:45 PM   #1
LQ Newbie
Registered: Mar 2009
Posts: 3

Rep: Reputation: 0
Unhappy [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 () {

while [ $i -ne $word_length ]
if [ "$letter"=$(echo ${random_word} | cut -c$(($i+1))) ]

if [ $oldsecret_word = $secret_word ]
$lives=$(( $lives-1 ))
echo "Bad Luck you lost a life"
echo "Good guess"
$guess_number=$(( $guess_number+1 ))
Old 03-27-2009, 01:41 AM   #2
Simon Bridge
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Hint: nobody programs in a vaccuum - see how others have done it.

This is my code soo far however it doesnt compile please help!
Well it wouldn't - it's a BASH script.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with BASH script and AWK and SED NickJH Linux - Newbie 11 03-07-2009 04:08 PM
Problem changing line with sed. Should i use AWK? RattleSn@ke Linux - General 7 11-12-2007 01:03 PM
Insert character by using sed/awk manish_meet_in Linux - General 3 04-05-2007 12:19 PM
Bash Awk Variable problem _hadi_ Programming 5 12-13-2006 12:25 AM
[Bash] New line character in variable michael_hk Linux - Newbie 4 06-15-2006 02:13 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration