I am trying to iterate through a string taken as an input through the read command. I'm trying to output the number of each letter and each letter It should then use a loop to output each letter in turn. For example, if the user enters "picasso", the output should be:
Letter 1: p Letter 2: i Letter 3: c Letter 4: a Letter 5: s Letter 6: s Letter 7: o
Here is my current code:
#!/bin/bash
# Prompt a user to enter a word and output each letter in turn.
read -p "Please enter a word: " word
for i in $word
do
echo "Letter $i: $word"
done
Should I be placing the input to an array? I'm still new to programming loops but I'm finding it impossible to figure out the logic.
Any advice? Thanks.