You can use a C-style for
loop:
foo=string
for (( i=0; i<${#foo}; i++ )); do
echo "${foo:$i:1}"
done
${#foo}
expands to the length of foo
. ${foo:$i:1}
expands to the substring starting at position $i
of length 1.
More Related Contents:
- How do I iterate over a range of numbers defined by variables in Bash?
- Looping over pairs of values in bash [duplicate]
- How to loop over files in directory and change path and add suffix to filename
- How to skip the for loop when there are no matching files?
- Looping through alphabets in Bash
- How to parallelize for-loop in bash limiting number of processes
- How do I write a ‘for’ loop in Bash?
- How to add leading zeros for for-loop in shell? [duplicate]
- Using a variable in brace expansion range fed to a for loop
- Loop over tuples in bash?
- Make Bash handle variables like Batch
- Some troubles with using sed and awk [closed]
- Add a new element to an array without specifying the index in Bash
- Lookup shell variables by name, indirectly [duplicate]
- Removing colors from output
- How to loop through a directory recursively to delete files with certain extensions
- Associative arrays in Shell scripts
- How to get the part of a file after the first line that matches a regular expression
- Why do bash parameter expansions cause an rsync command to operate differently?
- How can I reference a file for variables using Bash?
- How to include an ‘&’ character in a bash curl statement
- How do I echo stars (*) when reading password with `read`?
- Bash: Copy named files recursively, preserving folder structure
- Using dot or “source” while calling another script – what is the difference?
- osascript using bash variable with a space
- What does “export” do in shell programming? [duplicate]
- What is the most elegant way to remove a path from the $PATH variable in Bash?
- How to use > in an xargs command?
- How to match a single quote in sed
- How to insert a new line character after a fixed number of characters in a file