Sample Header Ad - 728x90

Issue regarding flames game in shell script

0 votes
0 answers
87 views
I am trying to make a flames game in shell script. I take 2 names and sort names. My code like this:
-bash
var=$(j=1;for((i=0;i]/{printf $2}') #checking for differernt characters using diff and folding using fold to newline after every 1 character (fold -w1)
Now the actual problem I am facing is in the flames part. I am running a loop to check for the length of the different sting and at that position or iteration whatever character is there to remove it from this:
-bash
flames()
{
    echo "$word ${#word}"
    size=echo ${#var2}
    
    for((i=0;i<${#word};i++))
    do
        echo  " ${word:$i:1}"

        if [[ $i == $size ]]
        then
            cha=echo ${word:$i:1}
            word1=echo ${word//$cha/}
        fi
    done
    
    word=echo $word1
    echo "$word ${#word}"
}
What its doing is its working till the value of size is equal to the i value . After that I am unable to understand how to check for and remove till there is just one character left?
-bash
while [ ${#word} -ne 1 ]
do
    flames
done
The above portion is running infinitely . Also is there any other way to doing it better than actually doing the parameter expansion?
Asked by utkarsh dubey (11 rep)
Aug 21, 2023, 04:37 PM
Last activity: Aug 23, 2023, 09:28 AM