My mate asked this before on the unix SE, but he asked it wrong. He didn't get a working answer either.
Anyway, I'm trying to make my bash script process each character in a variable and echo a certain string per letter until it reaches the last. Here's what I have so far:
#!/bin/bash
echo Word?
read -r -p '' foo
# $foo is set to 'Mammals and Bricks' by user.
wordlength=${#foo}
$wordlength says 18, so start on character 1.
'M' is first letter received in $foo, so echo '{m,M}'
'a' is second letter received in $foo, so echo '{a,A}'
'm' is third letter received in $foo, so echo '{m,M}'
'm' is fourth letter received in $foo, so echo '{m,M}'
'a' is the fifth letter received in $foo, so echo '{a,A}'
'l' is the sixth letter received in $foo, so echo '{l,L}'
's' is the seventh letter received in foo, so echo '{s,S}'
' ' is the eighth, so echo '\ '
........
'c' is sixteenth letter received in $foo, so echo '{c,C}'
'k' is seventeenth letter received in $foo, so echo '{k,K}'
's' is eighteenth letter received in $foo, so echo '{s,S}'
And here's what it would look like on the user's end:
Word?
Mammals and Bricks
{m,M}{a,A}{m,M}{m,M}{a,A}{l,L}{s,S} {a,A}{n,N}{d,D} {b,B}{r,R}{i,I}{c,C}{k,K}{s,S}
Which is what it would output exactly. You would see all of the above in raw characters.
Anyone know how to do this?