Results 1 to 4 of 4
My code runs fine until I get to the end where I try to compare a user input letter with a substring. I get all kinds of results depending on ...
- 06-16-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 2
Substrings
My code runs fine until I get to the end where I try to compare a user input letter with a substring. I get all kinds of results depending on the letter I guess. Have I made an error in my code?
Code:#!/bin/bash printf "Please type a word : " read word printf "guess a letter : " read guess for (( i=0; i<${#word}; i++ )) do if (( $guess == ${word:$i:1} )) then printf "yes" fi done
- 06-16-2008 #2
hi,
replace
withCode:if (( $guess == ${word:$i:1} ))
Code:if [ $guess == ${word:$i:1} ]Linux and me it's a love story
- 06-16-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 2
Worked. Cheers! Should I do the same with "for" and "if" ?
- 06-18-2008 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Yes, unless you prefer typing 4 shifted characters instead of two unshifted ones (programmers just don't seem to be as lazy as we used be!).


Reply With Quote