Microsoft
Software
Hardware
Network
Question : Unix update variable by position
Hi
Im new to Unix, as part of my learning im creating a hangman game using bash. I am having a problem showing what letters a user has guessed correctly.
So far I have 4 variables $word - that is the word a user is trying to guess, $hidden - that is the same as $word but replaces each letter with a -, $input_letter that is the current letter guess, and $position which is where the letter occurs in word.
eg $word = join
$hidden = ----
$input_letter = i
$position = 3
I want to replace 1 character in $hidden with $input_letter at $position. I also have to do this without the use of sed or awk.
Any help much appreciated
(unsure of which zone this would come under)
Answer : Unix update variable by position
#!/bin/bash
word=join
input_letter=i
hidden=${word//[^$input_le
tter]/-}
echo $hidden
Random Solutions
Excel Table Synchronization- Why does this code not work?
Clear Search History in IE 7
Internet Connection is OK; Internet Explorer Does Not Work
Using XP Home "you might not have permission to use this network resource"
application to identify what programs are using disk i/o in WinXP
Debian/Sarge Grub MBR bootage fubared
URGENT - - Need to Copy files from AIX server to Windows XP workstation
difficulty with transparent GIF outputs
Reinstalled XP Pro - boot up gives "client mac addr" and dhcp with rotating line
Highlight Command Button to Show Active